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;
}
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;
}
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());
}
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());
}
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));
}
Aggregations