furqaankhan commented on code in PR #1686:
URL: https://github.com/apache/sedona/pull/1686#discussion_r1848941814


##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -1094,6 +1094,48 @@ public static Geometry lineInterpolatePoint(Geometry 
geom, double fraction) {
     return geom.getFactory().createPoint(interPoint);
   }
 
+  public static double perimeter(Geometry geometry, boolean use_spheroid, 
boolean lenient) {
+    if (use_spheroid && geometry.getSRID() != 4326) {
+      if (lenient) {
+        return 0;
+      } else {
+        throw new IllegalArgumentException(
+            "For spheroidal perimeter calculations, the input geometry must be 
in the WGS84 CRS (SRID 4326).");
+      }
+    }
+
+    String geomType = geometry.getGeometryType();
+    if (geomType.equalsIgnoreCase(Geometry.TYPENAME_POLYGON)) {
+      return calculateLength(geometry, use_spheroid);
+    } else if (geomType.equalsIgnoreCase(Geometry.TYPENAME_MULTIPOLYGON)) {
+      return calculateLength(geometry, use_spheroid);
+    } else if 
(geomType.equalsIgnoreCase(Geometry.TYPENAME_GEOMETRYCOLLECTION)) {

Review Comment:
   Yes, PostGIS recently changed their behavior. Perimeter is just for 
Polygonal geometries and Length is for Linear geometries.
   
   [ST_Perimeter not supporting linear 
geom](https://postgis.net/docs/ST_Perimeter.html#:~:text=ST_Surface%2C%20ST_MultiSurface%20(Polygon%2C%20MultiPolygon).%200%20is%20returned%20for%20non%2Dareal%20geometries.%20For%20linear%20geometries%20use%20ST_Length.)
   [ST_Length not supporting polygonal 
geom](https://postgis.net/docs/ST_Length.html#:~:text=if%20it%20is%20a%20LineString%2C%20MultiLineString%2C%20ST_Curve%2C%20ST_MultiCurve.%20For%20areal%20geometries%200%20is%20returned%3B%20use%20ST_Perimeter%20instead.)



-- 
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