Search in sources :

Example 11 with Geometry

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

the class MappingRule method hasCompatibleGeometryType.

private boolean hasCompatibleGeometryType(Feature feature) {
    getFeatureType();
    GeomRestriction restriction = getGeomRestriction();
    GeometryAttribute property = feature.getDefaultGeometryProperty();
    Geometry geom = (Geometry) property.getValue();
    if (geom.getClass().equals(Point.class)) {
        return geometryType == Point.class;
    } else {
        if (geometryType.equals(Point.class)) {
            return false;
        }
        Coordinate[] coords = geom.getCoordinates();
        if (geometryType.equals(Polygon.class) && coords.length < 3) {
            return false;
        }
        boolean isClosed = coords[0].equals(coords[coords.length - 1]);
        if (isClosed && restriction.equals(GeomRestriction.ONLY_OPEN_LINES)) {
            return false;
        }
        if (!isClosed && restriction.equals(GeomRestriction.ONLY_CLOSED_LINES)) {
            return false;
        }
        return true;
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) GeometryAttribute(org.opengis.feature.GeometryAttribute) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 12 with Geometry

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

the class GeometrySerializer method write.

@Override
public void write(Object obj, final DataOutput out) throws IOException {
    final Geometry geom = (Geometry) obj;
    final int geometryType = getGeometryType(geom);
    final int typeAndMasks = geometryType;
    writeUnsignedVarInt(typeAndMasks, out);
    geom.apply(new EncodingSequenceFilter(out, true));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 13 with Geometry

use of com.vividsolutions.jts.geom.Geometry 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 14 with Geometry

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

the class GeometryDiffTest method testNoNewGeometry.

@Test
public void testNoNewGeometry() 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))");
    LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(Optional.of(oldGeom), Optional.fromNullable((Geometry) null));
    LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText());
    assertEquals(diff, deserializedDiff);
    assertEquals("9 point(s) deleted, 0 new point(s) added, 0 point(s) moved", diff.toString());
    Optional<Geometry> resultingGeom = diff.applyOn(Optional.of(oldGeom));
    assertFalse(resultingGeom.isPresent());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 15 with Geometry

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

the class GeometryDiffTest method testNoConflictAddingPoints.

@Test
public void testNoConflictAddingPoints() 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, 10 10, 20 45, 45 30, 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, 10 10, 20 45, 45 30, 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)

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