james-willis commented on code in PR #1765:
URL: https://github.com/apache/sedona/pull/1765#discussion_r1926266271


##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -1156,6 +1156,39 @@ public static Geometry lineMerge(Geometry geometry) {
     return geometry.getFactory().createGeometryCollection();
   }
 
+  public static Geometry[] lineSegments(Geometry geometry, boolean lenient) {
+    LineString line;
+    try {
+      line = (LineString) geometry;
+    } catch (Exception e) {
+      if (lenient) {
+        return new Geometry[] {};
+      } else {
+        throw new IllegalArgumentException(
+            "Geometry is not a LineString. This function expects input 
geometry to be a LineString.");
+      }
+    }
+
+    Coordinate[] coords = line.getCoordinates();
+    GeometryFactory geometryFactory = geometry.getFactory();
+    if (coords.length == 2) {
+      return new Geometry[] {line};
+    } else if (coords.length == 0) {
+      return new Geometry[] {geometryFactory.createLineString()};

Review Comment:
   can you just return line here instead of allocating a new line?



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