szehon-ho commented on code in PR #54114:
URL: https://github.com/apache/spark/pull/54114#discussion_r2790635711
##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/geo/Ring.java:
##########
@@ -47,23 +47,28 @@ boolean isClosed() {
if (points.size() < 4) {
return false;
}
- Point first = points.get(0);
- Point last = points.get(points.size() - 1);
- return coordinatesEqual(first.getCoordinates(), last.getCoordinates());
+ return coordinatesEqual(points.get(0), points.get(points.size() - 1));
}
/**
- * Compares two coordinate arrays for equality.
+ * Compares two points for coordinate equality (X and Y only).
+ * Z and M coordinates are NOT considered, per OGC standards.
*/
- private static boolean coordinatesEqual(double[] coords1, double[] coords2) {
- if (coords1.length != coords2.length) {
- return false;
- }
- for (int i = 0; i < coords1.length; i++) {
- if (coords1[i] != coords2[i]) {
- return false;
+ private static boolean coordinatesEqual(Point p1, Point p2) {
+ return p1.getX() == p2.getX() && p1.getY() == p2.getY();
Review Comment:
i see, nice catch
##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/geo/MultiLineString.java:
##########
@@ -39,11 +39,26 @@ int getNumGeometries() {
@Override
boolean isEmpty() {
- return lineStrings.isEmpty() ||
lineStrings.stream().allMatch(LineString::isEmpty);
+ return lineStrings.isEmpty();
}
@Override
int getDimensionCount() {
return 2 + (hasZ ? 1 : 0) + (hasM ? 1 : 0);
}
+
+ @Override
+ protected void appendWktContent(StringBuilder sb) {
+ for (int i = 0; i < lineStrings.size(); i++) {
+ if (i > 0) {
+ sb.append(",");
Review Comment:
Would it better to have a space between coordinates for readability and
consistency with the other choices we made (which is to put a space) ?
POINT (1 2, 3 4)
##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/geo/GeometryModel.java:
##########
@@ -176,4 +176,50 @@ GeometryCollection asGeometryCollection() {
throw new ClassCastException(
"Cannot cast " + getClass().getSimpleName() + " to GeometryCollection");
}
+
+ /**
+ * Appends dimension suffix (Z, M, or ZM) to the WKT type name.
+ */
+ protected void appendDimensionSuffix(StringBuilder sb) {
+ if (hasZ && hasM) {
+ sb.append(" ZM");
+ } else if (hasZ) {
+ sb.append(" Z");
+ } else if (hasM) {
+ sb.append(" M");
+ }
+ }
+
+ /**
+ * Appends the WKT (Well-Known Text) representation of this geometry to the
given StringBuilder.
+ */
+ protected void toWkt(StringBuilder sb) {
+ sb.append(typeId.getWktName());
+ appendDimensionSuffix(sb);
+ if (isEmpty()) {
+ sb.append(" EMPTY");
+ } else {
+ if (hasZ || hasM) {
+ sb.append(" (");
+ } else {
+ sb.append("(");
+ }
+ appendWktContent(sb);
+ sb.append(")");
+ }
+ }
+
+ /**
+ * Appends the geometry-specific WKT content (i.e. coordinate values of all
child geometries).
Review Comment:
when reading, i dont see the value of (ie, coordinate values of all child
geometries) in the comment, as WKT will have more than just coordinates.
'geometry-specific WKT' content seems ok to me. Wdyt?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]