From 2341f8c1fb4abeabcca80788c59ddf8258ea2b3c Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Sat, 26 Oct 2024 07:26:20 -0400 Subject: [PATCH] change to coordinate sequence --- .../com/onthegomap/planetiler/geo/GeoUtils.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java index 7b07ff7178..7b71469277 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/geo/GeoUtils.java @@ -607,14 +607,13 @@ public static double lineLengthMeters(CoordinateSequence sequence) { * @see "Some Algorithms for Polygons on a Sphere", JPL * Publication 07-03, Jet Propulsion * Laboratory, Pasadena, CA, June 2007. */ - public static double ringAreaMeters(LinearRing ring) { + public static double ringAreaMeters(CoordinateSequence ring) { double total = 0; - var cs = ring.getCoordinateSequence(); - var numEdges = cs.size() - 1; + var numEdges = ring.size() - 1; for (int i = 0; i < numEdges; i++) { - double lowerX = cs.getX(i) * RADIANS_PER_DEGREE; - double midY = cs.getY(i + 1 == numEdges ? 0 : i + 1) * RADIANS_PER_DEGREE; - double upperX = cs.getX(i + 2 >= numEdges ? (i + 2) % numEdges : i + 2) * RADIANS_PER_DEGREE; + double lowerX = ring.getX(i) * RADIANS_PER_DEGREE; + double midY = ring.getY(i + 1 == numEdges ? 0 : i + 1) * RADIANS_PER_DEGREE; + double upperX = ring.getX(i + 2 >= numEdges ? (i + 2) % numEdges : i + 2) * RADIANS_PER_DEGREE; total += (upperX - lowerX) * Math.sin(midY); } return Math.abs(total) * AREA_FACTOR; @@ -622,14 +621,14 @@ public static double ringAreaMeters(LinearRing ring) { /** * Returns the approximate area in meters of a polygon, or all polygons contained within a multigeometry using - * {@link #ringAreaMeters(LinearRing)}. + * {@link #ringAreaMeters(CoordinateSequence)}. */ public static double areaInMeters(Geometry latLonGeom) { return switch (latLonGeom) { case Polygon poly -> { - double result = ringAreaMeters(poly.getExteriorRing()); + double result = ringAreaMeters(poly.getExteriorRing().getCoordinateSequence()); for (int i = 0; i < poly.getNumInteriorRing(); i++) { - result -= ringAreaMeters(poly.getInteriorRingN(i)); + result -= ringAreaMeters(poly.getInteriorRingN(i).getCoordinateSequence()); } yield result; }