Search in sources :

Example 6 with WKTReader

use of com.vividsolutions.jts.io.WKTReader 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)

Example 7 with WKTReader

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

the class GeometryDiffTest method testModifiedMultiPolygon.

@Test
public void testModifiedMultiPolygon() throws Exception {
    int NUM_COORDS = 10;
    Random rand = new Random();
    List<Coordinate> list = Lists.newArrayList();
    for (int i = 0; i < NUM_COORDS; i++) {
        list.add(new Coordinate(rand.nextInt(), rand.nextInt()));
    }
    Geometry oldGeom = new WKTReader().read("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 10, 30 5, 10 30, 20 35),(30 20, 20 25, 20 15, 30 20)))");
    Geometry newGeom = new WKTReader().read("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 45 20, 30 5, 10 10, 10 30, 20 35)))");
    LCSGeometryDiffImpl diff = new LCSGeometryDiffImpl(Optional.of(oldGeom), Optional.of(newGeom));
    LCSGeometryDiffImpl deserializedDiff = new LCSGeometryDiffImpl(diff.asText());
    assertEquals(diff, deserializedDiff);
    assertEquals("4 point(s) deleted, 1 new point(s) added, 1 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) Random(java.util.Random) Coordinate(com.vividsolutions.jts.geom.Coordinate) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 8 with WKTReader

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

the class GeometryDiffTest method testNoConflictIfSameDiff.

@Test
public void testNoConflictIfSameDiff() 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));
    GeometryAttributeDiff diff2 = new GeometryAttributeDiff(Optional.of(oldGeom), Optional.of(newGeom));
    assertFalse(diff.conflicts(diff2));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 9 with WKTReader

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

the class GeometryDiffTest method testCanApply.

@Test
public void testCanApply() 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));
    Geometry oldGeomModified = new WKTReader().read("MULTILINESTRING ((40 40, 20 45, 45 30, 40 41),(20 35, 45 10, 30 5, 10 30, 20 35))");
    assertTrue(diff.canBeAppliedOn(Optional.of(oldGeomModified)));
    Geometry oldGeomModified2 = new WKTReader().read("MULTILINESTRING ((40 40, 10 10))");
    assertFalse(diff.canBeAppliedOn(Optional.of(oldGeomModified2)));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 10 with WKTReader

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

the class GeometryDiffTest method testDoubleReverseEquality.

@Test
public void testDoubleReverseEquality() 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 diff2 = diff.reversed().reversed();
    assertEquals(diff, diff2);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

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