Search in sources :

Example 81 with Geometry

use of com.vividsolutions.jts.geom.Geometry in project GeoGig by boundlessgeo.

the class GeometrySerializer method read.

@Override
public Geometry read(DataInput in) throws IOException {
    final int typeAndMasks = readUnsignedVarInt(in);
    Geometry geom;
    if ((typeAndMasks & POINT) == POINT) {
        geom = GEOMFAC.createPoint(EncodingSequenceFilter.readCoordinate(in));
    } else if ((typeAndMasks & LINESTRING) == LINESTRING) {
        CoordinateSequence cs = EncodingSequenceFilter.read(in);
        geom = GEOMFAC.createLineString(cs);
    } else {
        throw new UnsupportedOperationException();
    }
    return geom;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 82 with Geometry

use of com.vividsolutions.jts.geom.Geometry in project GeoGig by boundlessgeo.

the class GeogigSimpleFeature method getBounds.

@Override
public BoundingBox getBounds() {
    CoordinateReferenceSystem crs = featureType.getCoordinateReferenceSystem();
    Envelope bounds = ReferencedEnvelope.create(crs);
    if (node == null) {
        Optional<Object> o;
        List<Optional<Object>> values = getValues();
        for (int i = 0; i < values.size(); i++) {
            o = values.get(i);
            if (o.isPresent() && o.get() instanceof Geometry) {
                Geometry g = (Geometry) o.get();
                // crs as the feature type
                if (bounds.isNull()) {
                    bounds.init(JTS.bounds(g, crs));
                } else {
                    bounds.expandToInclude(JTS.bounds(g, crs));
                }
            }
        }
    } else {
        node.expand(bounds);
    }
    return (BoundingBox) bounds;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Optional(com.google.common.base.Optional) BoundingBox(org.opengis.geometry.BoundingBox) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(com.vividsolutions.jts.geom.Envelope) Point(com.vividsolutions.jts.geom.Point)

Example 83 with Geometry

use of com.vividsolutions.jts.geom.Geometry in project GeoGig by boundlessgeo.

the class GeometryDiffTest method testNoConflict.

@Test
public void testNoConflict() 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, 45 35, 30 30),(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, 45 30, 40 40),(20 35, 45 10, 31 6, 10 30, 20 35))");
    GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom2));
    assertFalse(diff.conflicts(diff2));
    Optional<?> merged = diff2.applyOn(Optional.of(newGeom));
    assertTrue(merged.isPresent());
    Geometry mergedGeom = (Geometry) merged.get();
    assertEquals("MULTILINESTRING ((40 40, 20 45, 45 35, 30 30), (20 35, 45 10, 31 6, 10 30, 20 35))", mergedGeom.toText());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 84 with Geometry

use of com.vividsolutions.jts.geom.Geometry in project GeoGig by boundlessgeo.

the class GeometryDiffTest method testNoOldGeometry.

@Test
public void testNoOldGeometry() throws Exception {
    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.fromNullable((Geometry) null), Optional.of(newGeom));
    LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText());
    assertEquals(diff, deserializedDiff);
    assertEquals("0 point(s) deleted, 13 new point(s) added, 0 point(s) moved", diff.toString());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 85 with Geometry

use of com.vividsolutions.jts.geom.Geometry in project GeoGig by boundlessgeo.

the class GeometryDiffTest method testConflict.

@Test
public void testConflict() 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),(20 35, 45 10, 20 35))");
    GeometryAttributeDiff diff = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom));
    Geometry newGeom2 = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 41 33, 25 25),(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)

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