/** * Tests that the {@link PolyLine}'s geometry is valid * * @param polyline * the {@link PolyLine} to test * @return {@code true} if the {@link PolyLine} has valid geometry, otherwise {@code false} */ public static boolean isValidPolyLine(final PolyLine polyline) { final LineString lineString = POLYLINE_CONVERTER.convert(polyline); return lineString.isSimple(); }
@Override public String convert(final PolyLine polyLine) { final Geometry geometry = new JtsPolyLineConverter().convert(polyLine); return new WKTWriter().write(geometry); } }
public static Geometry getJts(final PolyLine polyLine) { if (polyLine instanceof Polygon) { return new JtsPolygonConverter().convert((Polygon) polyLine); } return new JtsPolyLineConverter().convert(polyLine); }
/** * Query country boundaries which cover/partially cover given {@link PolyLine} * * @param polyLine * Any {@link PolyLine} or {@link Polygon} * @return a list of {@link CountryBoundary} */ public List<CountryBoundary> boundaries(final PolyLine polyLine) { return this.boundariesHelper(() -> this.query(polyLine.bounds().asEnvelope()), boundary -> boundary.intersects(JTS_POLYLINE_CONVERTER.convert(polyLine))); }
/** * Query country boundaries which cover/partially cover given {@link PolyLine}, with an * extension square box * * @param polyLine * Any {@link PolyLine} or {@link Polygon} * @param extension * Extension {@link Distance} * @return a list of {@link CountryBoundary} */ public List<CountryBoundary> boundaries(final PolyLine polyLine, final Distance extension) { return this.boundariesHelper( () -> this.query(polyLine.bounds().expand(extension).asEnvelope()), boundary -> boundary.intersects(JTS_POLYLINE_CONVERTER.convert(polyLine))); }
@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); }