Search in sources :

Example 21 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem 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 22 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem 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 23 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project GeoGig by boundlessgeo.

the class Show method printRaw.

private void printRaw(GeogigCLI cli) throws IOException {
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    for (String ref : refs) {
        Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
        if (!obj.isPresent()) {
            ref = getFullRef(ref);
            obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
        }
        checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
        RevObject revObject = obj.get();
        if (revObject instanceof RevFeature) {
            Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class).setRefSpec(ref).call();
            if (opt.isPresent()) {
                RevFeatureType ft = opt.get();
                ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
                RevFeature feature = (RevFeature) revObject;
                Ansi ansi = super.newAnsi(console.getTerminal());
                ansi.a(ref).newline();
                ansi.a(feature.getId().toString()).newline();
                ImmutableList<Optional<Object>> values = feature.getValues();
                int i = 0;
                for (Optional<Object> value : values) {
                    PropertyDescriptor attrib = attribs.get(i);
                    ansi.a(attrib.getName()).newline();
                    PropertyType attrType = attrib.getType();
                    String typeName = FieldType.forBinding(attrType.getBinding()).name();
                    if (attrType instanceof GeometryType) {
                        GeometryType gt = (GeometryType) attrType;
                        CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
                        String crsText = CrsTextSerializer.serialize(crs);
                        ansi.a(typeName).a(" ").a(crsText).newline();
                    } else {
                        ansi.a(typeName).newline();
                    }
                    ansi.a(value.or("[NULL]").toString()).newline();
                    i++;
                }
                console.println(ansi.toString());
            } else {
                CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
                console.println(s);
            }
        } else {
            CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
            console.println(s);
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) RevObject(org.locationtech.geogig.api.RevObject) PropertyType(org.opengis.feature.type.PropertyType) GeometryType(org.opengis.feature.type.GeometryType) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) CatObject(org.locationtech.geogig.api.plumbing.CatObject) RevObject(org.locationtech.geogig.api.RevObject) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Ansi(org.fusesource.jansi.Ansi) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 24 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project GeoGig by boundlessgeo.

the class OSMHistoryImportTest method test.

@Test
public void test() throws Exception {
    cli.execute("config", "user.name", "Gabriel Roldan");
    cli.execute("config", "user.email", "groldan@boundlessgeo.com");
    cli.execute("osm", "import-history", fakeOsmApiUrl, "--to", "10");
    GeoGIG geogig = cli.getGeogig();
    List<DiffEntry> changes = ImmutableList.copyOf(geogig.command(DiffOp.class).setOldVersion("HEAD~2").setNewVersion("HEAD~1").call());
    assertEquals(1, changes.size());
    DiffEntry entry = changes.get(0);
    assertEquals(ChangeType.MODIFIED, entry.changeType());
    assertEquals("node/20", entry.getOldObject().path());
    assertEquals("node/20", entry.getNewObject().path());
    Optional<RevFeature> oldRevFeature = geogig.command(RevObjectParse.class).setObjectId(entry.getOldObject().objectId()).call(RevFeature.class);
    Optional<RevFeature> newRevFeature = geogig.command(RevObjectParse.class).setObjectId(entry.getNewObject().objectId()).call(RevFeature.class);
    assertTrue(oldRevFeature.isPresent());
    assertTrue(newRevFeature.isPresent());
    Optional<RevFeatureType> type = geogig.command(RevObjectParse.class).setObjectId(entry.getOldObject().getMetadataId()).call(RevFeatureType.class);
    assertTrue(type.isPresent());
    FeatureType featureType = type.get().type();
    CoordinateReferenceSystem expected = CRS.decode("EPSG:4326", true);
    CoordinateReferenceSystem actual = featureType.getCoordinateReferenceSystem();
    assertTrue(actual.toString(), CRS.equalsIgnoreMetadata(expected, actual));
}
Also used : FeatureType(org.opengis.feature.type.FeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevFeature(org.locationtech.geogig.api.RevFeature) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 25 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem 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)

Aggregations

CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)210 Test (org.junit.Test)80 MathTransform (org.opengis.referencing.operation.MathTransform)32 FactoryException (org.opengis.referencing.FactoryException)25 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)24 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)23 Geometry (com.vividsolutions.jts.geom.Geometry)21 TransformException (org.opengis.referencing.operation.TransformException)21 DependsOnMethod (org.apache.sis.test.DependsOnMethod)19 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)13 Geometry (org.locationtech.jts.geom.Geometry)11 FactoryException (org.opengis.util.FactoryException)11 SimpleFeature (org.opengis.feature.simple.SimpleFeature)9 DirectPosition (org.opengis.geometry.DirectPosition)9 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)9 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)9 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)9 ArrayList (java.util.ArrayList)8 GeometryType (org.opengis.feature.type.GeometryType)8 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)7