Search in sources :

Example 16 with ReferencedEnvelope

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;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) ScreenMap(org.geotools.renderer.ScreenMap) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SimplifyingFilterVisitor(org.geotools.filter.visitor.SimplifyingFilterVisitor) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 17 with ReferencedEnvelope

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);
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 18 with ReferencedEnvelope

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;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope)

Example 19 with ReferencedEnvelope

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;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope)

Example 20 with ReferencedEnvelope

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;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) MapContent(org.geotools.map.MapContent) Rectangle(java.awt.Rectangle) GTRenderer(org.geotools.renderer.GTRenderer) BufferedImage(java.awt.image.BufferedImage) StreamingRenderer(org.geotools.renderer.lite.StreamingRenderer) Graphics2D(java.awt.Graphics2D)

Aggregations

ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)20 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)12 Test (org.junit.Test)9 Filter (org.opengis.filter.Filter)4 BoundingBox (org.opengis.geometry.BoundingBox)4 Envelope (com.vividsolutions.jts.geom.Envelope)3 Polygon (com.vividsolutions.jts.geom.Polygon)3 Query (org.geotools.data.Query)3 RevTree (org.locationtech.geogig.api.RevTree)3 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)3 BufferedImage (java.awt.image.BufferedImage)2 List (java.util.List)2 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)2 MapContent (org.geotools.map.MapContent)2 GTRenderer (org.geotools.renderer.GTRenderer)2 StreamingRenderer (org.geotools.renderer.lite.StreamingRenderer)2 ObjectId (org.locationtech.geogig.api.ObjectId)2 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)2 Feature (org.opengis.feature.Feature)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2