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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations