use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.
the class GeogigFeatureSource method getBoundsInternal.
@Override
protected ReferencedEnvelope getBoundsInternal(Query query) throws IOException {
final Filter filter = (Filter) query.getFilter().accept(new SimplifyingFilterVisitor(), null);
final CoordinateReferenceSystem crs = getSchema().getCoordinateReferenceSystem();
if (Filter.INCLUDE.equals(filter) && oldRoot == null && ChangeType.ADDED.equals(changeType())) {
NodeRef typeRef = getTypeRef();
ReferencedEnvelope bounds = new ReferencedEnvelope(crs);
typeRef.getNode().expand(bounds);
return bounds;
}
if (Filter.EXCLUDE.equals(filter)) {
return ReferencedEnvelope.create(crs);
}
FeatureReader<SimpleFeatureType, SimpleFeature> features;
if (isNaturalOrder(query.getSortBy())) {
Integer offset = query.getStartIndex();
Integer maxFeatures = query.getMaxFeatures() == Integer.MAX_VALUE ? null : query.getMaxFeatures();
ScreenMap screenMap = (ScreenMap) query.getHints().get(Hints.SCREENMAP);
features = getNativeReader(Query.NO_NAMES, filter, offset, maxFeatures, screenMap);
} else {
features = getReader(query);
}
ReferencedEnvelope bounds = new ReferencedEnvelope(crs);
try {
while (features.hasNext()) {
bounds.expandToInclude((ReferencedEnvelope) features.next().getBounds());
}
} finally {
features.close();
}
return bounds;
}
use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.
the class DiffTreeTest method testMixedFilters.
/**
* Apply path, bounds, and changeType filtering all at once
*/
@Test
public void testMixedFilters() {
ObjectDatabase db = geogit.getContext().objectDatabase();
final RevTree tree1 = tree(1000, db);
final RevTree tree2 = tree(50, db);
final RevTree tree2Changed;
{
RevTreeBuilder builder = new RevTreeBuilder(db, tree2);
// add 10 changed features, and delete 10 more
for (int i = 0; i < 20; i++) {
if (i % 2 == 0) {
builder.remove(String.valueOf(i));
} else {
builder.put(feature(i, ObjectId.forString("changed" + i)));
}
}
tree2Changed = builder.build();
db.put(tree2Changed);
assertEquals(tree2.size() - 10, tree2Changed.size());
}
final RevTree root1 = createRoot(db, tree1, tree2);
final RevTree root2 = createRoot(db, tree1, tree2Changed);
final ObjectId rootId1 = root1.getId();
final ObjectId rootId2 = root2.getId();
CoordinateReferenceSystem crs = revtype.type().getCoordinateReferenceSystem();
// boundsFilter covers features 1-11
ReferencedEnvelope boundsFilter = new ReferencedEnvelope(1.9, 11.1, 1.9, 11.1, crs);
// first try with bounds only
diffTree.setBoundsFilter(boundsFilter);
assertEquals(10, Iterators.size(diffTree.setOldTree(rootId1).setNewTree(rootId2).call()));
assertChangeTypeFilter(rootId1, rootId2, 0, 5, 5);
assertChangeTypeFilter(rootId2, rootId1, 5, 0, 5);
// now add path filtering
diffTree.setPathFilter("tree1");
assertChangeTypeFilter(rootId1, rootId2, 0, 0, 0);
assertChangeTypeFilter(rootId2, rootId1, 0, 0, 0);
diffTree.setPathFilter("tree2");
assertChangeTypeFilter(rootId1, rootId2, 0, 5, 5);
assertChangeTypeFilter(rootId2, rootId1, 5, 0, 5);
// odd feature ids from 0 to 18 were removed from tree2
// tree2/0 and tree2/12 match path filter but don't match bounds filter
diffTree.setPathFilter(ImmutableList.of("tree2/0", "tree2/2", "tree2/4", "tree2/12"));
diffTree.setBoundsFilter(null);
assertChangeTypeFilter(rootId1, rootId2, 0, 4, 0);
assertChangeTypeFilter(rootId2, rootId1, 4, 0, 0);
diffTree.setBoundsFilter(boundsFilter);
assertChangeTypeFilter(rootId1, rootId2, 0, 2, 0);
assertChangeTypeFilter(rootId2, rootId1, 2, 0, 0);
}
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;
}
use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.
the class BoundsFilteringDiffConsumer method intersects.
private boolean intersects(@Nullable Bounded node, final Optional<ObjectId> metadataId) {
if (node == null) {
return false;
}
if (!metadataId.isPresent()) {
return true;
}
ReferencedEnvelope nativeCrsFilter = getProjectedFilter(metadataId.get());
boolean intersects = node.intersects(nativeCrsFilter);
return intersects;
}
use of org.geotools.geometry.jts.ReferencedEnvelope in project dhis2-core by dhis2.
the class MapUtils method render.
// -------------------------------------------------------------------------
// Map
// -------------------------------------------------------------------------
public static BufferedImage render(InternalMap map, Integer maxWidth, Integer maxHeight) {
MapContent mapContent = new MapContent();
for (InternalMapLayer mapLayer : map.getLayers()) {
for (InternalMapObject mapObject : mapLayer.getMapObjects()) {
mapContent.addLayer(createFeatureLayerFromMapObject(mapObject));
}
}
// Create a renderer for this map
GTRenderer renderer = new StreamingRenderer();
renderer.setMapContent(mapContent);
// Calculate image height
ReferencedEnvelope mapBounds = mapContent.getMaxBounds();
double widthToHeightFactor = mapBounds.getSpan(0) / mapBounds.getSpan(1);
int[] widthHeight = getWidthHeight(maxWidth, maxHeight, LegendSet.LEGEND_TOTAL_WIDTH, TITLE_HEIGHT, widthToHeightFactor);
//LegendSet.LEGEND_TOTAL_WIDTH;
Rectangle imageBounds = new Rectangle(0, 0, widthHeight[0], widthHeight[1]);
// Create an image and get the graphics context from it
BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = (Graphics2D) image.getGraphics();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
renderer.paint(graphics, imageBounds, mapBounds);
mapContent.dispose();
return image;
}
Aggregations