@Test public void testCreateMultiPolyLineFromWKT() { final String wkt = "MULTILINESTRING ((107.68471354246141 2.2346191319821231, 107.68471354246141 2.2345360028045156), " + "(107.68454724550249 2.2345601370821555, 107.68453115224835 2.2345601370821555, " + "107.68449419872607 2.2344243539043736))"; final MultiPolyLine multiPolyLine = MultiPolyLine.wkt(wkt); logger.info("Create MultiPolyLine from wkt {}", multiPolyLine.toString()); final String polyLineWkt1 = "LINESTRING (107.68471354246141 2.2346191319821231, 107.68471354246141 2.2345360028045156)"; final String polyLineWkt2 = "LINESTRING (107.68454724550249 2.2345601370821555, " + "107.68453115224835 2.2345601370821555, 107.68449419872607 2.2344243539043736))"; final PolyLine polyLine1 = PolyLine.wkt(polyLineWkt1); final PolyLine polyLine2 = PolyLine.wkt(polyLineWkt2); final Set<PolyLine> polyLines = Sets.newHashSet(); multiPolyLine.iterator().forEachRemaining(polyLines::add); Assert.assertTrue(polyLines.contains(polyLine1)); Assert.assertTrue(polyLines.contains(polyLine2)); } }
@Test public void testAsGeoJsonGeometry() { final PolyLine polyLine = PolyLine.wkt( "LINESTRING (-75.616330 40.194570, -75.616330 40.194570, -75.616330 40.194570, -75.616340 40.194580, -75.616340 40.194590)"); final String geoJson = "{\"type\":\"LineString\",\"coordinates\":[[-75.61633,40.19457],[-75.61633,40.19457],[-75.61633,40.19457],[-75.61634,40.19458],[-75.61634,40.19459]]}"; final JsonObject geometry = polyLine.asGeoJsonGeometry(); Assert.assertEquals(geoJson, geometry.toString()); }
@Test public void testCreateMultiPolyLineFromPolyLine() { final PolyLine polyLine1 = PolyLine .wkt("LINESTRING (10.5553105 48.3419094, 10.5552096 48.3417501, 10.5551312 48.3416583, " + "10.5551027 48.341611, 10.5550183 48.3415143, 10.5549357 48.3414668, " + "10.5548325 48.3414164, 10.5548105 48.3415201, 10.5548015 48.3415686, " + "10.5548925 48.3416166, 10.5550334 48.3416375, 10.5551312 48.3416583)"); final PolyLine polyLine2 = PolyLine .wkt("LINESTRING (10.5551312 48.3416583, 10.5551027 48.341611, 10.5550183 48.3415143, " + "10.5549357 48.3414668, 10.5548325 48.3414164, 10.5548105 48.3415201, " + "10.5548015 48.3415686, 10.5548925 48.3416166, 10.5550334 48.3416375)"); final MultiPolyLine multiPolyLine = new MultiPolyLine(Arrays.asList(polyLine1, polyLine2)); logger.info("Create MultiPolyLine from a list of PolyLine {}", multiPolyLine.toString()); final Set<PolyLine> polyLines = Sets.newHashSet(); multiPolyLine.iterator().forEachRemaining(polyLines::add); Assert.assertEquals(2, polyLines.size()); Assert.assertTrue(polyLines.contains(polyLine1)); Assert.assertTrue(polyLines.contains(polyLine2)); }
@Test public void testEqualsShape() { final PolyLine polyLine1 = PolyLine .wkt("LINESTRING (10.5553105 48.3419094, 10.5552096 48.3417501, 10.5551312 48.3416583, " + "10.5551027 48.341611, 10.5550183 48.3415143, 10.5549357 48.3414668, " + "10.5548325 48.3414164, 10.5548105 48.3415201, 10.5548015 48.3415686, " + "10.5548925 48.3416166, 10.5550334 48.3416375, 10.5551312 48.3416583)"); final PolyLine polyLine2 = PolyLine .wkt("LINESTRING (10.5551312 48.3416583, 10.5551027 48.341611, 10.5550183 48.3415143, " + "10.5549357 48.3414668, 10.5548325 48.3414164, 10.5548105 48.3415201, " + "10.5548015 48.3415686, 10.5548925 48.3416166, 10.5550334 48.3416375, " + "10.5551312 48.3416583, 10.5552096 48.3417501, 10.5553105 48.3419094)"); Assert.assertFalse(polyLine1.equals(polyLine2)); Assert.assertTrue(polyLine1.equalsShape(polyLine2)); }
@Test public void testWithoutDuplicateConsecutiveShapePoints() { final PolyLine polyLine1 = PolyLine.wkt( "LINESTRING (-75.616326 40.194564, -75.616330 40.194570, -75.616330 40.194570, -75.616340 40.194580)"); final PolyLine polyLine2 = PolyLine.wkt( "LINESTRING (-75.616326 40.194564, -75.616330 40.194570, -75.616340 40.194580)"); final PolyLine polyLine3 = PolyLine.wkt( "LINESTRING (-75.616326 40.194564, -75.616330 40.194570, -75.616340 40.194580, -75.616330 40.194570)"); final PolyLine polyLine4 = PolyLine.wkt( "LINESTRING (-75.616330 40.194570, -75.616330 40.194570, -75.616330 40.194570, -75.616340 40.194580, -75.616340 40.194590)"); final PolyLine polyLine5 = PolyLine.wkt( "LINESTRING (-75.616330 40.194570, -75.616340 40.194580, -75.616340 40.194590)"); Assert.assertEquals(polyLine2.toWkt(), polyLine1.withoutDuplicateConsecutiveShapePoints().toWkt()); Assert.assertEquals(polyLine3.toWkt(), polyLine3.withoutDuplicateConsecutiveShapePoints().toWkt()); Assert.assertEquals(polyLine5.toWkt(), polyLine4.withoutDuplicateConsecutiveShapePoints().toWkt()); }
@Test public void testSelfIntersectsNoIntersections() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 2 2, 3 3, 3 1)"); Assert.assertFalse(polyLine.selfIntersects()); Assert.assertEquals(0, polyLine.selfIntersections().size()); }
@Test public void testSelfIntersectsTouchLast() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 3 1, 3 2, 2 1)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,2"), intersections.toArray()[0]); }
@Test public void testSelfIntersectsClosedLoop() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 2 2, 3 3, 3 1, 1 1)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,1"), intersections.toArray()[0]); }
@Test public void testSelfIntersectsTouchFirst() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(2 1, 3 2, 3 1, 1 1)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,2"), intersections.toArray()[0]); }
@Test public void testSelfIntersectsTouchMiddle() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 3 1, 3 2, 2 1, 1 2)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,2"), intersections.toArray()[0]); }
@Test public void testCreateMultiLineStringFromMultiPolyLine() { final String wkt = "MULTILINESTRING ((107.68471354246141 2.2346191319821231, 107.68471354246141 2.2345360028045156), " + "(107.68454724550249 2.2345601370821555, 107.68453115224835 2.2345601370821555, " + "107.68449419872607 2.2344243539043736))"; final MultiPolyLine multiPolyLine = MultiPolyLine.wkt(wkt); final PolyLine polyLine1 = PolyLine.wkt( "LINESTRING (107.68471354246141 2.2346191319821231, 107.68471354246141 2.2345360028045156)"); final PolyLine polyLine2 = PolyLine .wkt("LINESTRING (107.68454724550249 2.2345601370821555, " + "107.68453115224835 2.2345601370821555, 107.68449419872607 2.2344243539043736)"); final LineString lineString1 = new JtsPolyLineConverter().convert(polyLine1); final LineString lineString2 = new JtsPolyLineConverter().convert(polyLine2); final MultiLineString multiLineString = new JtsMultiPolyLineConverter() .convert(multiPolyLine); Assert.assertTrue("First line is contained", multiLineString.contains(lineString1)); Assert.assertTrue("Second line is contained", multiLineString.contains(lineString2)); }
@Test public void testNearestNeighborCountryCodeOnMultiLineStringOutsideBoundary() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("DMA_boundary.txt"))); map.setShouldAlwaysSlicePredicate(taggable -> true); final PolyLine polyLine = PolyLine.wkt(new InputStreamResource( () -> CountryBoundaryMapTest.class.getResourceAsStream("DMA_snake_polyline.wkt")) .firstLine()); final List<Geometry> sliced = map.slice(123000000L, new JtsPolyLineConverter().convert(polyLine), Taggable.with("force-slice", "please")); int withNearestNeighborTag = 0; for (final Geometry slicedGeometry : sliced) { if (SyntheticNearestNeighborCountryCodeTag.YES.name() .equals(CountryBoundaryMap.getGeometryProperty(slicedGeometry, SyntheticNearestNeighborCountryCodeTag.KEY))) { withNearestNeighborTag++; } } Assert.assertEquals(3, withNearestNeighborTag); }
@Test(expected = AtlasIntegrityException.class) public void testNotSoCloseNode() { final PackedAtlasBuilder builder = new PackedAtlasBuilder(); builder.addNode(1, Location.forString("48.3406719,10.5563445"), Maps.hashMap()); builder.addNode(2, Location.forString("48.34204,10.55844"), Maps.hashMap()); // First node is too off. builder.addEdge(3, PolyLine.wkt("LINESTRING (10.5563430 48.3406710, 10.55844 48.34204)"), Maps.hashMap(HighwayTag.KEY, HighwayTag.RESIDENTIAL.getTagValue())); final Atlas result = builder.get(); logger.info("{}", result); Assert.assertNotNull(result); }
@Test public void testVeryCloseNode() { final PackedAtlasBuilder builder = new PackedAtlasBuilder(); builder.addNode(1, Location.forString("48.3406719,10.5563445"), Maps.hashMap()); builder.addNode(2, Location.forString("48.34204,10.55844"), Maps.hashMap()); // First node is slightly off. builder.addEdge(3, PolyLine.wkt("LINESTRING (10.5563444 48.3406717, 10.55844 48.34204)"), Maps.hashMap(HighwayTag.KEY, HighwayTag.RESIDENTIAL.getTagValue())); final Atlas result = builder.get(); logger.info("{}", result); Assert.assertNotNull(result); } }
@Test public void testManyVeryCloseNodes() { final PackedAtlasBuilder builder = new PackedAtlasBuilder(); builder.addNode(1, Location.forString("48.3406719,10.5563445"), Maps.hashMap()); builder.addNode(2, Location.forString("48.34204,10.55844"), Maps.hashMap()); builder.addNode(3, Location.forString("48.3406720,10.5563445"), Maps.hashMap()); builder.addNode(4, Location.forString("48.3406719,10.5563446"), Maps.hashMap()); // First node is slightly off. builder.addEdge(5, PolyLine.wkt("LINESTRING (10.5563444 48.3406717, 10.55844 48.34204)"), Maps.hashMap(HighwayTag.KEY, HighwayTag.RESIDENTIAL.getTagValue())); final Atlas result = builder.get(); logger.info("{}", result); Assert.assertNotNull(result); }
@Test public void testContains() { final PolyLine line = PolyLine .wkt("LINESTRING (10.5553105 48.3419094, 10.5552096 48.3417501, 10.5551312 48.3416583, " + "10.5551027 48.341611, 10.5550183 48.3415143, 10.5549357 48.3414668, " + "10.5548325 48.3414164, 10.5548105 48.3415201, 10.5548015 48.3415686, " + "10.5548925 48.3416166, 10.5550334 48.3416375, 10.5551312 48.3416583)"); Assert.assertTrue("Verifying PolyLine contains Location", line.contains(Location.forString("48.3419094, 10.5553105"))); Assert.assertFalse("Verifying PolyLine doesn't contain Location", line.contains(Location.COLOSSEUM)); Assert.assertTrue("Verifying PolyLine contains Segment", line.contains(new Segment(Location.forString("48.3419094, 10.5553105"), Location.forString("48.3417501, 10.5552096")))); Assert.assertFalse("Verifying PolyLine doesn't contain Segment", line.contains(new Segment(Location.TEST_2, Location.COLOSSEUM))); }
Assert.assertFalse(multiPolygon1.fullyGeometricallyEncloses(multiPolygon7)); final PolyLine polyLine1 = PolyLine.wkt("LINESTRING (6 6, -6 -6)"); final PolyLine polyLine2 = PolyLine.wkt("LINESTRING (6 6, -6 6, -6 -6, 6 -6)"); final Polygon polygon1 = Polygon.wkt("POLYGON ((6 6, -6 6, -6 -6, 6 -6, 6 6))");