Search in sources :

Example 1 with JtsPolyLineConverter

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;
}
Also used : GeometryCollection(org.locationtech.jts.geom.GeometryCollection) Geometry(org.locationtech.jts.geom.Geometry) JtsPolygonConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPolygonConverter) LineString(org.locationtech.jts.geom.LineString) ArrayList(java.util.ArrayList) PolyLine(org.openstreetmap.atlas.geography.PolyLine) JtsPolyLineConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter)

Example 2 with JtsPolyLineConverter

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;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Area(org.openstreetmap.atlas.geography.atlas.items.Area) LineString(org.locationtech.jts.geom.LineString) LocationItem(org.openstreetmap.atlas.geography.atlas.items.LocationItem) PolyLine(org.openstreetmap.atlas.geography.PolyLine) Point(org.locationtech.jts.geom.Point) Polygon(org.openstreetmap.atlas.geography.Polygon) JtsPointConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPointConverter) JtsPolyLineConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter) Location(org.openstreetmap.atlas.geography.Location)

Example 3 with JtsPolyLineConverter

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));
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) JtsMultiPolyLineConverter(org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolyLineConverter) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) JtsPolyLineConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter) Test(org.junit.Test)

Example 4 with JtsPolyLineConverter

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;
}
Also used : GeometryCollection(org.locationtech.jts.geom.GeometryCollection) Geometry(org.locationtech.jts.geom.Geometry) LineString(org.locationtech.jts.geom.LineString) ArrayList(java.util.ArrayList) PolyLine(org.openstreetmap.atlas.geography.PolyLine) JtsPolyLineConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter)

Example 5 with JtsPolyLineConverter

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);
}
Also used : CoreException(org.openstreetmap.atlas.exception.CoreException) LineString(org.locationtech.jts.geom.LineString) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader) JtsPolyLineConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter)

Aggregations

JtsPolyLineConverter (org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter)7 LineString (org.locationtech.jts.geom.LineString)6 PolyLine (org.openstreetmap.atlas.geography.PolyLine)5 Geometry (org.locationtech.jts.geom.Geometry)4 ArrayList (java.util.ArrayList)2 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)2 Point (org.locationtech.jts.geom.Point)2 Location (org.openstreetmap.atlas.geography.Location)2 Polygon (org.openstreetmap.atlas.geography.Polygon)2 Area (org.openstreetmap.atlas.geography.atlas.items.Area)2 LocationItem (org.openstreetmap.atlas.geography.atlas.items.LocationItem)2 JtsPointConverter (org.openstreetmap.atlas.geography.converters.jts.JtsPointConverter)2 JtsPolygonConverter (org.openstreetmap.atlas.geography.converters.jts.JtsPolygonConverter)2 Test (org.junit.Test)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 ParseException (org.locationtech.jts.io.ParseException)1 WKTReader (org.locationtech.jts.io.WKTReader)1 CoreException (org.openstreetmap.atlas.exception.CoreException)1 CountryBoundary (org.openstreetmap.atlas.geography.boundary.CountryBoundary)1 JtsMultiPolyLineConverter (org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolyLineConverter)1