Search in sources :

Example 41 with LatLon

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

the class SphericalEarthMath method enclosingBoundingBox.

/**
 * Calculate a bounding box that contains the given positions.
 */
public static BoundingBox enclosingBoundingBox(List<LatLon> positions) {
    Double minLat = null, minLon = null, maxLat = null, maxLon = null;
    for (LatLon pos : positions) {
        double lat = pos.getLatitude();
        double lon = pos.getLongitude();
        if (minLat == null || lat < minLat)
            minLat = lat;
        if (minLon == null || lon < minLon)
            minLon = lon;
        if (maxLat == null || lat > maxLat)
            maxLat = lat;
        if (maxLon == null || lon > maxLon)
            maxLon = lon;
    }
    return new BoundingBox(minLat, minLon, maxLat, maxLon);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

Example 42 with LatLon

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

the class SphericalEarthMath method enclosingBoundingBox.

/**
 * Calculate a bounding box that contains the given circle. In other words, it is a square
 * centered at the given position and with a side length of radius*2
 * @param center of the circle
 * @param radius in meters
 * @return The bounding box that contains the area
 */
public static BoundingBox enclosingBoundingBox(LatLon center, double radius) {
    double distance = sqrt(2) * radius;
    LatLon min = translate(center, distance, 225);
    LatLon max = translate(center, distance, 45);
    return new BoundingBox(min, max);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) BoundingBox(de.westnordost.osmapi.map.data.BoundingBox)

Example 43 with LatLon

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

the class SphericalEarthMath method distance.

/**
 * @return distance covered by the given polyline
 */
public static double distance(List<LatLon> positions) {
    double length = 0;
    for (int i = 0; i < positions.size() - 1; i++) {
        LatLon p0 = positions.get(i);
        LatLon p1 = positions.get(i + 1);
        length += distance(p0, p1);
    }
    return length;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon)

Example 44 with LatLon

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

the class SphericalEarthMath method centerLineOf.

/**
 * @return the center line of the given polyline
 */
public static List<LatLon> centerLineOf(List<LatLon> positions) {
    double halfDistance = distance(positions) / 2;
    for (int i = 0; i < positions.size() - 1; i++) {
        LatLon pos0 = positions.get(i);
        LatLon pos1 = positions.get(i + 1);
        halfDistance -= distance(pos0, pos1);
        if (halfDistance > 0)
            continue;
        List<LatLon> result = new ArrayList<>(2);
        result.add(pos0);
        result.add(pos1);
        return result;
    }
    return null;
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) ArrayList(java.util.ArrayList)

Example 45 with LatLon

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

the class ElementGeometryTest method testFindCenterOfPolygonWithNoArea.

public void testFindCenterOfPolygonWithNoArea() {
    List<List<LatLon>> polygons = new ArrayList<>();
    List<LatLon> square = new ArrayList<>();
    square.add(new OsmLatLon(10, 10));
    polygons.add(square);
    ElementGeometry geom = new ElementGeometry(null, polygons);
    assertEquals(null, geom.center);
}
Also used : LatLon(de.westnordost.osmapi.map.data.LatLon) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) 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