Search in sources :

Example 6 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class JTSConst method toLineStrings.

public static Geometry toLineStrings(List<List<LatLon>> polylines) {
    LineString[] lineStrings = new LineString[polylines.size()];
    int i = 0;
    for (List<LatLon> polyline : polylines) {
        lineStrings[i++] = factory.createLineString(toCoordinates(polyline));
    }
    if (lineStrings.length == 1)
        return lineStrings[0];
    else
        return factory.createMultiLineString(lineStrings);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) LineString(com.vividsolutions.jts.geom.LineString) Point(com.vividsolutions.jts.geom.Point)

Example 7 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class JTSConst method toShellsWithHoles.

private static Map<LinearRing, ArrayList<LinearRing>> toShellsWithHoles(List<List<LatLon>> outerPolygons, List<List<LatLon>> innerPolygons) {
    // outer -> List of inner
    Map<LinearRing, ArrayList<LinearRing>> shellsWithHoles = new HashMap<>();
    for (List<LatLon> outer : outerPolygons) {
        LinearRing shell = factory.createLinearRing(toCoordinates(outer));
        Geometry outerGeom = factory.createPolygon(shell);
        shellsWithHoles.put(shell, null);
        Iterator<List<LatLon>> it = innerPolygons.iterator();
        while (it.hasNext()) {
            List<LatLon> inner = it.next();
            LinearRing hole = factory.createLinearRing(toCoordinates(inner));
            Geometry holeGeom = factory.createPolygon(hole);
            if (outerGeom.contains(holeGeom)) {
                if (shellsWithHoles.get(shell) == null) {
                    shellsWithHoles.put(shell, new ArrayList<>());
                }
                shellsWithHoles.get(shell).add(hole);
                it.remove();
            }
        }
    }
    return shellsWithHoles;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ElementGeometry(de.westnordost.streetcomplete.data.osm.ElementGeometry) LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinearRing(com.vividsolutions.jts.geom.LinearRing)

Example 8 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class JTSConst method toCoordinates.

public static Coordinate[] toCoordinates(List<LatLon> latLons) {
    Coordinate[] result = new Coordinate[latLons.size()];
    int i = 0;
    for (LatLon latLon : latLons) {
        result[i++] = toCoordinate(latLon);
    }
    return result;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point)

Example 9 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class SphericalEarthMath method enclosedArea.

/**
 * area enclosed in the given bbox in m²
 */
public static double enclosedArea(BoundingBox bbox) {
    LatLon min = bbox.getMin();
    LatLon max = bbox.getMax();
    LatLon minLatMaxLon = new OsmLatLon(min.getLatitude(), max.getLongitude());
    LatLon maxLatMinLon = new OsmLatLon(max.getLatitude(), min.getLongitude());
    return distance(min, minLatMaxLon) * distance(min, maxLatMinLon);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 10 with LatLon

use of de.westnordost.osmapi.map.data.LatLon in project StreetComplete by westnordost.

the class ElementGeometryTest method testFindCenterOfPolyline.

public void testFindCenterOfPolyline() {
    List<List<LatLon>> polylines = new ArrayList<>();
    List<LatLon> polyline = new ArrayList<>();
    LatLon start = new OsmLatLon(-10, -20);
    LatLon finish = new OsmLatLon(10, 20);
    polyline.add(start);
    polyline.add(finish);
    polylines.add(polyline);
    ElementGeometry geom = new ElementGeometry(polylines, null);
    double dist = SphericalEarthMath.distance(start, finish);
    double bearing = SphericalEarthMath.bearing(start, finish);
    LatLon expect = SphericalEarthMath.translate(start, dist / 2, bearing);
    assertEquals(expect, geom.center);
    assertEquals(new BoundingBox(start, finish), geom.getBounds());
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Aggregations

LatLon (de.westnordost.osmapi.map.data.LatLon)63 OsmLatLon (de.westnordost.osmapi.map.data.OsmLatLon)45 ArrayList (java.util.ArrayList)29 BoundingBox (de.westnordost.osmapi.map.data.BoundingBox)13 List (java.util.List)12 ElementGeometry (de.westnordost.streetcomplete.data.osm.ElementGeometry)8 OsmNode (de.westnordost.osmapi.map.data.OsmNode)5 HashMap (java.util.HashMap)5 Point (android.graphics.Point)3 PointF (android.graphics.PointF)3 Node (de.westnordost.osmapi.map.data.Node)3 OsmElementQuestType (de.westnordost.streetcomplete.data.osm.OsmElementQuestType)3 LngLat (com.mapzen.tangram.LngLat)2 Point (com.vividsolutions.jts.geom.Point)2 Element (de.westnordost.osmapi.map.data.Element)2 QuestGroup (de.westnordost.streetcomplete.data.QuestGroup)2 VisibleQuestListener (de.westnordost.streetcomplete.data.VisibleQuestListener)2 OsmNoteQuestType (de.westnordost.streetcomplete.data.osmnotes.OsmNoteQuestType)2 Collection (java.util.Collection)2 Map (java.util.Map)2