szehon-ho commented on code in PR #53227:
URL: https://github.com/apache/spark/pull/53227#discussion_r2663020613


##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/geo/Ring.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.catalyst.util.geo;
+
+import java.util.List;
+
+/**
+ * Represents a ring (closed linestring) in a polygon.
+ */
+class Ring {
+  private final List<Point> points;
+  private final boolean hasZ;
+  private final boolean hasM;
+
+  Ring(List<Point> points, boolean hasZ, boolean hasM) {
+    this.points = points;
+    this.hasZ = hasZ;
+    this.hasM = hasM;
+  }
+
+  List<Point> getPoints() {
+    return points;
+  }
+
+  int getNumPoints() {
+    return points.size();
+  }
+
+  boolean isEmpty() {
+    return points.isEmpty();
+  }
+
+  int getDimensionCount() {
+    return 2 + (hasZ ? 1 : 0) + (hasM ? 1 : 0);
+  }
+
+  boolean hasZ() {
+    return hasZ;
+  }
+
+  boolean hasM() {
+    return hasM;
+  }
+
+  boolean isClosed() {

Review Comment:
   added to class javadoc



##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/geo/WkbWriter.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.catalyst.util.geo;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * Utility class for converting geometries to Well-Known Binary (WKB) format.
+ * This class implements the OGC Simple Features specification for WKB writing.
+ * <p>
+ * This class is designed to support reuse of a single instance to write 
multiple
+ * geometries efficiently. This class is NOT thread-safe; each thread should 
create
+ * its own instance.
+ */
+public class WkbWriter {
+
+  /**
+   * Gets the WKB type code for a geometry, including dimension offset.
+   * For example: Point 2D = 1, Point Z = 1001, Point M = 2001, Point ZM = 3001
+   */
+  private static int getWkbType(GeometryModel geometry) {
+    int baseType = (int) geometry.getTypeId().getValue();
+    boolean hasZ = geometry.hasZ();
+    boolean hasM = geometry.hasM();
+
+    // Determine dimension offset based on hasZ and hasM flags
+    if (hasZ && hasM) {
+      return baseType + WkbConstants.DIM_OFFSET_ZM;
+    } else if (hasZ) {
+      return baseType + WkbConstants.DIM_OFFSET_Z;
+    } else if (hasM) {
+      return baseType + WkbConstants.DIM_OFFSET_M;
+    } else {
+      return baseType + WkbConstants.DIM_OFFSET_2D;
+    }
+  }
+
+  // ========== Public Write Methods ==========
+
+  /**
+   * Writes a geometry to WKB format.
+   */
+  public byte[] write(GeometryModel geometry) {
+    return write(geometry, ByteOrder.LITTLE_ENDIAN);
+  }
+
+  /**
+   * Writes a geometry to WKB format with specified byte order.
+   * <p>

Review Comment:
   Same as above



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

Reply via email to