zhangfengcdt commented on code in PR #2831:
URL: https://github.com/apache/sedona/pull/2831#discussion_r3088490832


##########
common/src/main/java/org/apache/sedona/common/geography/Functions.java:
##########
@@ -75,14 +71,69 @@ private static S2Polygon rectToPolygon(double lngLo, double 
latLo, double lngHi,
     v.add(S2LatLng.fromDegrees(latHi, lngLo).toPoint());
 
     S2Loop loop = new S2Loop(v);
-    // Optional: normalize for canonical orientation (keeps the smaller-area 
side)
     loop.normalize();
 
     return new S2Polygon(loop);
   }
 
+  // ─── Level 1: JTS-only structural operations ─────────────────────────────
+
+  /** Return the number of points in a geography. */
+  public static int nPoints(Geography g) {
+    if (g == null) return 0;
+    return toJTS(g).getNumPoints();
+  }
+
+  // ─── Level 2: JTS + S2 geodesic metrics ──────────────────────────────────
+
+  /**
+   * Geometry-to-geometry geodesic distance in meters. Uses S2ClosestEdgeQuery 
for true minimum
+   * distance between any two points on the geometries (not 
centroid-to-centroid). Consistent with
+   * sedona-db's s2_distance implementation.
+   */
+  public static Double distance(Geography g1, Geography g2) {
+    if (g1 == null || g2 == null) return null;
+    Distance dist = new Distance();
+    double radians = dist.S2_distance(toShapeIndex(g1), toShapeIndex(g2));
+    return radiansToMeters(radians);
+  }

Review Comment:
   Now, it has the similar logic for the ShapeIndex is now built from 
WkbS2Shape instead of S2 Geography. For large polygons, it runs slightly faster.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to