use of org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter in project atlas by osmlab.
the class PolygonClipper method processResult.
private List<? extends PolyLine> processResult(final Geometry intersections) {
final List<PolyLine> result = new ArrayList<>();
if (intersections instanceof GeometryCollection) {
final GeometryCollection collection = (GeometryCollection) intersections;
final int numGeometries = collection.getNumGeometries();
for (int n = 0; n < numGeometries; n++) {
final Geometry geometry = collection.getGeometryN(n);
result.addAll(processResult(geometry));
}
} else if (intersections instanceof org.locationtech.jts.geom.Polygon) {
result.add(new JtsPolygonConverter().backwardConvert((org.locationtech.jts.geom.Polygon) intersections));
} else if (intersections instanceof LineString) {
result.add(new JtsPolyLineConverter().backwardConvert((LineString) intersections));
}
return result;
}
use of org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter in project atlas by osmlab.
the class AtlasSearchCommand method entityContainsWktGeometry.
private // NOSONAR
boolean entityContainsWktGeometry(// NOSONAR
final AtlasEntity entity, // NOSONAR
final String wkt) {
if (entity.getType() == ItemType.RELATION) {
return false;
}
final Geometry geometry = parseWkt(wkt);
if (geometry == null) {
return false;
}
Location inputLocation = null;
PolyLine inputPolyline = null;
if (geometry instanceof Point) {
inputLocation = new JtsPointConverter().backwardConvert((Point) geometry);
} else if (geometry instanceof LineString) {
inputPolyline = new JtsPolyLineConverter().backwardConvert((LineString) geometry);
} else {
this.outputDelegate.printlnErrorMessage("--" + SUB_GEOMETRY_OPTION_LONG + " only supports POINT and LINESTRING, found " + geometry.getClass().getName());
return false;
}
boolean matchedSomething;
if (entity.getType() == ItemType.POINT || entity.getType() == ItemType.NODE) {
final Location location = ((LocationItem) entity).getLocation();
if (inputLocation != null) {
matchedSomething = location.equals(inputLocation);
return matchedSomething;
}
} else if (entity.getType() == ItemType.LINE || entity.getType() == ItemType.EDGE) {
final PolyLine line = ((LineItem) entity).asPolyLine();
if (inputLocation != null) {
matchedSomething = line.contains(inputLocation);
if (matchedSomething) {
return true;
}
}
if (inputPolyline != null) {
matchedSomething = line.overlapsShapeOf(inputPolyline);
return matchedSomething;
}
} else if (entity.getType() == ItemType.AREA) {
final Polygon polygon = ((Area) entity).asPolygon();
if (inputLocation != null) {
matchedSomething = polygon.contains(inputLocation);
if (matchedSomething) {
return true;
}
}
if (inputPolyline != null) {
matchedSomething = polygon.overlapsShapeOf(inputPolyline);
return matchedSomething;
}
}
return false;
}
use of org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter in project atlas by osmlab.
the class MultiPolyLineTest method testCreateMultiLineStringFromMultiPolyLine.
@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));
}
use of org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter in project atlas by osmlab.
the class MultiPolygonClipper method processPolyLine.
private List<PolyLine> processPolyLine(final Geometry intersections) {
final List<PolyLine> result = new ArrayList<>();
if (intersections instanceof GeometryCollection) {
final GeometryCollection collection = (GeometryCollection) intersections;
final int numGeometries = collection.getNumGeometries();
for (int n = 0; n < numGeometries; n++) {
final Geometry geometry = collection.getGeometryN(n);
result.addAll(processPolyLine(geometry));
}
} else if (intersections instanceof LineString) {
result.add(new JtsPolyLineConverter().backwardConvert((LineString) intersections));
}
return result;
}
use of org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter in project atlas by osmlab.
the class WktPolyLineConverter method backwardConvert.
@Override
public PolyLine backwardConvert(final String wkt) {
LineString geometry = null;
final WKTReader myReader = new WKTReader();
try {
geometry = (LineString) myReader.read(wkt);
} catch (final ParseException | ClassCastException e) {
throw new CoreException("Cannot parse wkt : {}", wkt, e);
}
return new JtsPolyLineConverter().backwardConvert(geometry);
}
Aggregations