jiayuasu commented on code in PR #1686:
URL: https://github.com/apache/sedona/pull/1686#discussion_r1848922852
##########
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;
Review Comment:
I would prefer to assume SRID is 4326 if lenient is true. This is
particularly useful because most people forget to set SRID for their 4326
geometries.
##########
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)) {
Review Comment:
Can you re-use the logic from ST_LengthSpheroid?
##########
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:
So this does not work with lines? Is this the expected behavior? What about
ST_Length and LengthSpheroid?
--
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]