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