Search in sources :

Example 1 with ReferencedEnvelope

use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.

the class WorkingTree method putInDatabase.

/**
     * Adds a single feature to the staging database.
     * 
     * @param feature the feature to add
     * @param metadataId
     * @return the Node for the inserted feature
     */
private Node putInDatabase(final Feature feature, final ObjectId metadataId) {
    checkNotNull(feature);
    checkNotNull(metadataId);
    final RevFeature newFeature = RevFeatureBuilder.build(feature);
    final ObjectId objectId = newFeature.getId();
    final Envelope bounds = (ReferencedEnvelope) feature.getBounds();
    final String nodeName = feature.getIdentifier().getID();
    indexDatabase.put(newFeature);
    Node newObject = Node.create(nodeName, objectId, metadataId, TYPE.FEATURE, bounds);
    return newObject;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) RevFeature(org.locationtech.geogig.api.RevFeature) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 2 with ReferencedEnvelope

use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.

the class BoundsFilteringDiffConsumer method createProjectedFilter.

private ReferencedEnvelope createProjectedFilter(ObjectId metadataId) {
    final ReferencedEnvelope boundsFilter = this.boundsFilter;
    RevFeatureType featureType = ftypeSource.getFeatureType(metadataId);
    CoordinateReferenceSystem nativeCrs = featureType.type().getCoordinateReferenceSystem();
    if (null == nativeCrs || nativeCrs instanceof DefaultEngineeringCRS) {
        return boundsFilter;
    }
    ReferencedEnvelope transformedFilter;
    try {
        transformedFilter = boundsFilter.transform(nativeCrs, true);
    } catch (TransformException | FactoryException e) {
        throw Throwables.propagate(e);
    }
    return transformedFilter;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DefaultEngineeringCRS(org.geotools.referencing.crs.DefaultEngineeringCRS)

Example 3 with ReferencedEnvelope

use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.

the class GeoGigFeatureSourceTest method testGetBoundsQuery.

@Test
public void testGetBoundsQuery() throws Exception {
    ReferencedEnvelope bounds;
    Filter filter;
    filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
    bounds = pointsSource.getBounds(new Query(pointsName, filter));
    assertEquals(boundsOf(points2), bounds);
    ReferencedEnvelope queryBounds = boundsOf(points1, points2);
    Polygon geometry = JTS.toGeometry(queryBounds);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    bounds = pointsSource.getBounds(new Query(pointsName, filter));
    assertEquals(boundsOf(points1, points2), bounds);
    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));
    bounds = pointsSource.getBounds(new Query(pointsName, filter));
    assertEquals(boundsOf(points1, points2), bounds);
    filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
    bounds = linesSource.getBounds(new Query(linesName, filter));
    assertEquals(boundsOf(lines3, lines2), bounds);
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Query(org.geotools.data.Query) Filter(org.opengis.filter.Filter) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Example 4 with ReferencedEnvelope

use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.

the class GeoGigFeatureSourceTest method testGetCount.

@Test
public void testGetCount() throws Exception {
    assertEquals(3, pointsSource.getCount(Query.ALL));
    assertEquals(3, linesSource.getCount(Query.ALL));
    Filter filter;
    filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
    assertEquals(1, pointsSource.getCount(new Query(pointsName, filter)));
    ReferencedEnvelope queryBounds = boundsOf(points1, points2);
    Polygon geometry = JTS.toGeometry(queryBounds);
    filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
    assertEquals(2, pointsSource.getCount(new Query(pointsName, filter)));
    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));
    assertEquals(2, pointsSource.getCount(new Query(pointsName, filter)));
    filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
    assertEquals(2, linesSource.getCount(new Query(linesName, filter)));
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Query(org.geotools.data.Query) Filter(org.opengis.filter.Filter) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test)

Example 5 with ReferencedEnvelope

use of org.geotools.geometry.jts.ReferencedEnvelope in project GeoGig by boundlessgeo.

the class DiffTreeTest method testBoundsFilteringReprojecting.

@Test
public void testBoundsFilteringReprojecting() throws Exception {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    RevTree tree1 = tree(1000, db);
    RevTree tree2 = tree(50, db);
    RevTree root = createRoot(db, tree1, tree2);
    CoordinateReferenceSystem nativeCrs = revtype.type().getCoordinateReferenceSystem();
    CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:4326", true);
    ReferencedEnvelope nativeFilter = new ReferencedEnvelope(49.9, 51.1, 49.9, 51.1, nativeCrs);
    ReferencedEnvelope queryFilter = nativeFilter.transform(queryCrs, true);
    List<DiffEntry> diffs;
    diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId());
    diffTree.setBoundsFilter(queryFilter);
    diffs = ImmutableList.copyOf(diffTree.call());
    assertEquals(2, diffs.size());
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

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