use of org.geotools.geometry.jts.ReferencedEnvelope in project spatial-portal by AtlasOfLivingAustralia.
the class AreaUploadShapefileWizardController method executeShapeImageRenderer.
private void executeShapeImageRenderer(Filter filter) {
try {
LOGGER.debug("Generating image");
SimpleFeatureCollection features1;
if (filter == null) {
features1 = source.getFeatures();
} else {
features1 = source.getFeatures(filter);
}
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
org.geotools.styling.Style style = SLD.createSimpleStyle(source.getSchema());
Layer layer = new FeatureLayer(features1, style);
map.addLayer(layer);
GTRenderer renderer = new StreamingRenderer();
renderer.setMapContent(map);
int imageWidth = 800;
int imageHeight = 300;
Rectangle imageBounds;
ReferencedEnvelope mapBounds;
mapBounds = map.getMaxBounds();
double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0);
if (heightToWidth * imageWidth > imageHeight) {
imageBounds = new Rectangle(0, 0, (int) Math.round(imageHeight / heightToWidth), imageHeight);
} else {
imageBounds = new Rectangle(0, 0, imageWidth, (int) Math.round(imageWidth * heightToWidth));
}
BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_RGB);
Graphics2D gr = image.createGraphics();
gr.setPaint(Color.WHITE);
gr.fill(imageBounds);
renderer.paint(gr, imageBounds, mapBounds);
img.setContent(image);
} catch (Exception e) {
LOGGER.debug("Unable to generate image for selected shapefile", e);
}
}
use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.
the class GeoGigFeatureSourceTest method testGetFeaturesFilter.
@Test
public void testGetFeaturesFilter() throws Exception {
SimpleFeatureCollection collection;
Set<List<Object>> actual;
Set<List<Object>> expected;
Filter filter;
filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
collection = pointsSource.getFeatures(new Query(pointsName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = Collections.singleton(((SimpleFeature) points2).getAttributes());
assertEquals(expected, actual);
ReferencedEnvelope queryBounds = boundsOf(points1, points2);
Polygon geometry = JTS.toGeometry(queryBounds);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
collection = pointsSource.getFeatures(new Query(pointsName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = ImmutableSet.of(((SimpleFeature) points1).getAttributes(), ((SimpleFeature) points2).getAttributes());
assertEquals(expected, actual);
ReferencedEnvelope transformedQueryBounds;
CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
transformedQueryBounds = queryBounds.transform(queryCrs, true);
geometry = JTS.toGeometry(transformedQueryBounds);
geometry.setUserData(queryCrs);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
collection = pointsSource.getFeatures(new Query(pointsName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = ImmutableSet.of(((SimpleFeature) points1).getAttributes(), ((SimpleFeature) points2).getAttributes());
assertEquals(expected.size(), actual.size());
assertEquals(expected, actual);
filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
collection = linesSource.getFeatures(new Query(linesName, filter));
actual = Sets.newHashSet();
for (SimpleFeature f : toList(collection)) {
actual.add(f.getAttributes());
}
expected = ImmutableSet.of(((SimpleFeature) lines2).getAttributes(), ((SimpleFeature) lines3).getAttributes());
assertEquals(expected, actual);
}
use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.
the class GeoGigFeatureSourceTest method testGetBounds.
@Test
public void testGetBounds() throws IOException {
ReferencedEnvelope expected;
ReferencedEnvelope bounds;
bounds = pointsSource.getBounds();
assertNotNull(bounds);
expected = boundsOf(points1, points2, points3);
assertEquals(expected, bounds);
bounds = linesSource.getBounds();
assertNotNull(bounds);
expected = boundsOf(lines1, lines2, lines3);
assertEquals(expected, bounds);
}
use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.
the class RepositoryTestCase method boundsOf.
/**
* Computes the aggregated bounds of {@code features} in the {@code targetCrs}
*/
public ReferencedEnvelope boundsOf(CoordinateReferenceSystem targetCrs, Feature... features) throws Exception {
ReferencedEnvelope bounds = new ReferencedEnvelope(targetCrs);
for (int i = 0; i < features.length; i++) {
Feature f = features[i];
BoundingBox fbounds = f.getBounds();
if (!CRS.equalsIgnoreMetadata(targetCrs, fbounds)) {
fbounds = fbounds.toBounds(targetCrs);
}
bounds.include(fbounds);
}
return bounds;
}
use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.
the class BoundsFilteringDiffConsumer method getProjectedFilter.
private ReferencedEnvelope getProjectedFilter(final ObjectId metadataId) {
ReferencedEnvelope projectedFilter = filtersByMetadataId.get(metadataId);
if (projectedFilter == null) {
projectedFilter = createProjectedFilter(metadataId);
filtersByMetadataId.put(metadataId, projectedFilter);
}
return projectedFilter;
}
Aggregations