Search in sources :

Example 11 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project GeoGig by boundlessgeo.

the class GeometryDiffTest method testModifiedMultiLineString.

@Test
public void testModifiedMultiLineString() throws Exception {
    Geometry oldGeom = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
    Geometry newGeom = new WKTReader().read("MULTILINESTRING ((40 40, 20 35, 45 30, 40 40),(20 35, 45 20, 30 15, 10 10, 10 30, 20 35),(10 10, 20 20, 35 30))");
    LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(Optional.of(oldGeom), Optional.of(newGeom));
    LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText());
    assertEquals(diff, deserializedDiff);
    assertEquals("0 point(s) deleted, 4 new point(s) added, 3 point(s) moved", diff.toString());
    Optional<Geometry> resultingGeom = diff.applyOn(Optional.of(oldGeom));
    assertEquals(newGeom, resultingGeom.get());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 12 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project GeoGig by boundlessgeo.

the class GeometryDiffTest method testConflictEditedSamePoint.

@Test
public void testConflictEditedSamePoint() throws Exception {
    Geometry oldGeom = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
    Geometry newGeom = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 48 32, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
    GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom));
    Geometry newGeom2 = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 41 33, 40 40),(20 35, 45 10, 30 5, 10 30, 20 35))");
    GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom2));
    assertTrue(diff.conflicts(diff2));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 13 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project incubator-rya by apache.

the class GeoMongoDBStorageStrategy method serialize.

@Override
public DBObject serialize(final RyaStatement ryaStatement) {
    // write the statement data to the fields
    try {
        final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
        final Geometry geo = (new WKTReader()).read(GeoParseUtils.getWellKnownText(statement));
        if (geo == null) {
            LOG.error("Failed to parse geo statement: " + statement.toString());
            return null;
        }
        final BasicDBObject base = (BasicDBObject) super.serialize(ryaStatement);
        if (geo.getNumPoints() > 1) {
            base.append(GEO, getCorrespondingPoints(geo));
        } else {
            base.append(GEO, getDBPoint(geo));
        }
        return base;
    } catch (final ParseException e) {
        LOG.error("Could not create geometry for statement " + ryaStatement, e);
        return null;
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) BasicDBObject(com.mongodb.BasicDBObject) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader)

Example 14 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project incubator-rya by apache.

the class GeoTemporalMongoDBStorageStrategy method getGeoObjs.

private DBObject[] getGeoObjs(final Collection<IndexingExpr> geoFilters) {
    final List<DBObject> objs = new ArrayList<>();
    geoFilters.forEach(filter -> {
        final GeoPolicy policy = GeoPolicy.fromURI(filter.getFunction());
        final WKTReader reader = new WKTReader();
        final String geoStr = ((Value) filter.getArguments()[0]).stringValue();
        try {
            // This method is what is used in the GeoIndexer.
            final Geometry geo = reader.read(geoStr);
            objs.add(getGeoObject(geo, policy));
        } catch (final GeoTemporalIndexException | UnsupportedOperationException | ParseException e) {
            LOG.error("Unable to parse '" + geoStr + "'.", e);
        }
    });
    return objs.toArray(new DBObject[] {});
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeoPolicy(org.apache.rya.indexing.geotemporal.GeoTemporalIndexer.GeoPolicy) GeoTemporalIndexException(org.apache.rya.indexing.geotemporal.GeoTemporalIndexException) ArrayList(java.util.ArrayList) Value(org.openrdf.model.Value) ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 15 with WKTReader

use of com.vividsolutions.jts.io.WKTReader in project hibernate-orm by hibernate.

the class HANAExpectationsFactory method getTestPolygon.

@Override
public Polygon getTestPolygon() {
    WKTReader reader = new WKTReader();
    try {
        Polygon polygon = (Polygon) reader.read("POLYGON((0 0, 50 0, 90 90, 100 0, 0 0))");
        polygon.setSRID(getTestSrid());
        return polygon;
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
Also used : ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader) Polygon(com.vividsolutions.jts.geom.Polygon)

Aggregations

WKTReader (com.vividsolutions.jts.io.WKTReader)71 Geometry (com.vividsolutions.jts.geom.Geometry)51 Test (org.junit.Test)28 ParseException (com.vividsolutions.jts.io.ParseException)23 WKTWriter (com.vividsolutions.jts.io.WKTWriter)9 Metacard (ddf.catalog.data.Metacard)9 Coordinate (com.vividsolutions.jts.geom.Coordinate)6 IsValidOp (com.vividsolutions.jts.operation.valid.IsValidOp)6 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)6 GeometryOperator (org.codice.alliance.libs.klv.GeometryOperator)6 Context (org.codice.alliance.video.stream.mpegts.Context)6 MapLayer (au.org.emii.portal.menu.MapLayer)5 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)4 Polygon (com.vividsolutions.jts.geom.Polygon)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Optional (java.util.Optional)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Before (org.junit.Before)3 Facet (au.org.ala.legend.Facet)2