Search in sources :

Example 1 with Geometry

use of com.vividsolutions.jts.geom.Geometry in project hibernate-orm by hibernate.

the class GeometryEquality method test.

private boolean test(Geometry geom1, Geometry geom2, boolean ignoreSRID) {
    if (geom1 == null) {
        return geom2 == null;
    }
    if (geom1.isEmpty()) {
        return geom2.isEmpty();
    }
    if (!ignoreSRID && !equalSRID(geom1, geom2)) {
        return false;
    }
    if (geom1 instanceof GeometryCollection) {
        if (!(geom2 instanceof GeometryCollection)) {
            return false;
        }
        GeometryCollection expectedCollection = (GeometryCollection) geom1;
        GeometryCollection receivedCollection = (GeometryCollection) geom2;
        for (int partIndex = 0; partIndex < expectedCollection.getNumGeometries(); partIndex++) {
            Geometry partExpected = expectedCollection.getGeometryN(partIndex);
            Geometry partReceived = receivedCollection.getGeometryN(partIndex);
            if (!test(partExpected, partReceived, true)) {
                return false;
            }
        }
        return true;
    } else {
        return testSimpleGeometryEquality(geom1, geom2);
    }
}
Also used : GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Geometry(com.vividsolutions.jts.geom.Geometry)

Example 2 with Geometry

use of com.vividsolutions.jts.geom.Geometry in project hibernate-orm by hibernate.

the class TestStoreRetrieveUsingJTS method retrieveAndCompare.

private void retrieveAndCompare(Map<Integer, GeomEntity> stored) {
    int id = -1;
    Transaction tx = null;
    Session session = null;
    try {
        session = openSession();
        tx = session.beginTransaction();
        for (GeomEntity storedEntity : stored.values()) {
            id = storedEntity.getId();
            GeomEntity retrievedEntity = (GeomEntity) session.get(GeomEntity.class, id);
            Geometry retrievedGeometry = retrievedEntity.getGeom();
            Geometry storedGeometry = storedEntity.getGeom();
            String msg = createFailureMessage(storedEntity.getId(), storedGeometry, retrievedGeometry);
            assertTrue(msg, geometryEquality.test(storedGeometry, retrievedGeometry));
        }
        tx.commit();
    } catch (Exception e) {
        if (tx != null) {
            tx.rollback();
        }
        throw new RuntimeException(String.format("Failure on case: %d", id), e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Transaction(org.hibernate.Transaction) ParseException(com.vividsolutions.jts.io.ParseException) Session(org.hibernate.Session)

Example 3 with Geometry

use of com.vividsolutions.jts.geom.Geometry in project series-rest-api by 52North.

the class FeatureOutputSerializer method encodeGeometry.

private Object encodeGeometry(GeoJSONFeature value) {
    try {
        final GeoJSONEncoder enc = new GeoJSONEncoder();
        final Geometry geometry = value.getGeometry();
        return enc.encodeGeometry(geometry);
    } catch (GeoJSONException e) {
        LOGGER.error("could not properly encode geometry.", e);
        return null;
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry)

Example 4 with Geometry

use of com.vividsolutions.jts.geom.Geometry in project series-rest-api by 52North.

the class TransformingGeometryOutputService method transformInline.

private void transformInline(IoParameters query, GeometryInfo info) {
    Geometry geometry = info.getGeometry();
    info.setGeometry(transformationService.transform(geometry, query));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry)

Example 5 with Geometry

use of com.vividsolutions.jts.geom.Geometry in project series-rest-api by 52North.

the class TransformingPlatformOutputService method transformInline.

private void transformInline(IoParameters query, PlatformOutput platform) {
    Geometry geometry = platform.getGeometry();
    platform.setGeometry(transformationService.transform(geometry, query));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry)

Aggregations

Geometry (com.vividsolutions.jts.geom.Geometry)123 WKTReader (com.vividsolutions.jts.io.WKTReader)35 Test (org.junit.Test)31 Coordinate (com.vividsolutions.jts.geom.Coordinate)23 Point (com.vividsolutions.jts.geom.Point)21 ParseException (com.vividsolutions.jts.io.ParseException)19 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)14 Envelope (com.vividsolutions.jts.geom.Envelope)13 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)13 WKTWriter (com.vividsolutions.jts.io.WKTWriter)13 ArrayList (java.util.ArrayList)12 LineString (com.vividsolutions.jts.geom.LineString)10 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)9 Metacard (ddf.catalog.data.Metacard)9 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 Optional (com.google.common.base.Optional)6 IOException (java.io.IOException)6 RevFeature (org.locationtech.geogig.api.RevFeature)6 JtsGeometry (org.locationtech.spatial4j.shape.jts.JtsGeometry)6 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)5