Search in sources :

Example 6 with ReferencedEnvelope

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

the class DiffBoundsTest method testReprojectToTargetCRS.

@Test
public void testReprojectToTargetCRS() throws Exception {
    DiffBounds cmd = geogig.command(DiffBounds.class).setOldVersion("HEAD^").setNewVersion("HEAD");
    DiffSummary<BoundingBox, BoundingBox> defaultCrs = cmd.call();
    CoordinateReferenceSystem target = CRS.decode("EPSG:26986");
    cmd.setCRS(target);
    DiffSummary<BoundingBox, BoundingBox> reprojected = cmd.call();
    assertEquals(target, reprojected.getLeft().getCoordinateReferenceSystem());
    assertEquals(target, reprojected.getRight().getCoordinateReferenceSystem());
    assertEquals(target, reprojected.getMergedResult().get().getCoordinateReferenceSystem());
    assertFalse(defaultCrs.getLeft().isEmpty());
    assertFalse(defaultCrs.getRight().isEmpty());
    assertFalse(defaultCrs.getMergedResult().get().isEmpty());
    ReferencedEnvelope e = new ReferencedEnvelope(defaultCrs.getLeft());
    ReferencedEnvelope expected = e.transform(target, true);
    assertEquals(expected, reprojected.getLeft());
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) BoundingBox(org.opengis.geometry.BoundingBox) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

Example 7 with ReferencedEnvelope

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

the class DiffBoundsTest method testReprojectToTargetBucketTree.

@Test
public void testReprojectToTargetBucketTree() throws Exception {
    final int leftCount = RevTree.NORMALIZED_SIZE_LIMIT * 2;
    final int rightCount = RevTree.NORMALIZED_SIZE_LIMIT * 3;
    WorkingTree workingTree = geogig.getRepository().workingTree();
    final String typeName = "newpoints";
    final DefaultProgressListener listener = new DefaultProgressListener();
    workingTree.insert(typeName, new TestFeatureIterator(typeName, leftCount), listener, null, null);
    geogig.command(AddOp.class).call();
    workingTree.insert(typeName, new TestFeatureIterator(typeName, rightCount), listener, null, null);
    {
        // sanity check
        long diffFeatures = geogig.command(DiffCount.class).setOldVersion("STAGE_HEAD").setNewVersion("WORK_HEAD").call().featureCount();
        assertEquals(rightCount - leftCount, diffFeatures);
    }
    DiffBounds cmd = geogig.command(DiffBounds.class).setOldVersion("STAGE_HEAD").setNewVersion("WORK_HEAD");
    final CoordinateReferenceSystem nativeCrs = CRS.decode("EPSG:3857");
    final DiffSummary<BoundingBox, BoundingBox> diffInNativeCrs = cmd.setCRS(nativeCrs).call();
    CoordinateReferenceSystem targetcrs = CRS.decode("EPSG:4326", true);
    cmd.setCRS(targetcrs);
    DiffSummary<BoundingBox, BoundingBox> reprojected = cmd.call();
    assertEquals(targetcrs, reprojected.getLeft().getCoordinateReferenceSystem());
    assertEquals(targetcrs, reprojected.getRight().getCoordinateReferenceSystem());
    assertEquals(targetcrs, reprojected.getMergedResult().get().getCoordinateReferenceSystem());
    ReferencedEnvelope e = new ReferencedEnvelope(diffInNativeCrs.getRight());
    ReferencedEnvelope expected = e.transform(targetcrs, true);
    BoundingBox actual = reprojected.getRight();
    assertEquals(expected, actual);
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) BoundingBox(org.opengis.geometry.BoundingBox) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

Example 8 with ReferencedEnvelope

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

the class DiffTreeTest method testBoundsFiltering.

@Test
public void testBoundsFiltering() {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    RevTree tree1 = tree(1000, db);
    RevTree tree2 = tree(50, db);
    RevTree root = createRoot(db, tree1, tree2);
    CoordinateReferenceSystem crs = revtype.type().getCoordinateReferenceSystem();
    ReferencedEnvelope filter;
    List<DiffEntry> diffs;
    diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId());
    filter = new ReferencedEnvelope(50, 51, 50, 51, crs);
    diffTree.setBoundsFilter(filter);
    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)

Example 9 with ReferencedEnvelope

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

the class ExtractBounds method visit.

@Override
public List<ReferencedEnvelope> visit(Literal literal, @Nullable Object data) {
    Object value = literal.getValue();
    if (value instanceof Geometry) {
        Geometry geom = (Geometry) value;
        Envelope literalEnvelope = geom.getEnvelopeInternal();
        CoordinateReferenceSystem crs = nativeCrs;
        if (geom.getUserData() instanceof CoordinateReferenceSystem) {
            crs = (CoordinateReferenceSystem) geom.getUserData();
        }
        ReferencedEnvelope bbox = new ReferencedEnvelope(literalEnvelope, crs);
        bounds.add(bbox);
    }
    return bounds;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 10 with ReferencedEnvelope

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

the class RemoteRepositoryTestCase method boundsOf.

/**
     * Computes the aggregated bounds of {@code features} in the {@code targetCrs}
     */
protected 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;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) BoundingBox(org.opengis.geometry.BoundingBox) Feature(org.opengis.feature.Feature)

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