uros-db commented on code in PR #53227:
URL: https://github.com/apache/spark/pull/53227#discussion_r2731320784


##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/geo/GeometryModel.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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;
+
+/**
+ * Abstract base class for specific geometry types (Point, LineString, 
Polygon, etc.).
+ * This class provides common functionality needed by geometry subclasses.
+ */
+abstract class GeometryModel {
+
+  /** GeometryModel internal implementation. */
+
+  // Geometry type and SRID information
+  // The GeoTypeId enum represents the OGC WKB base code for the geometry type.
+  protected final GeoTypeId typeId;
+  protected int sridValue;
+
+  // Dimension flags
+  protected final boolean hasZ;
+  protected final boolean hasM;
+
+  /** GeometryModel constructors. */
+
+  /**
+   * Constructor for GeometryModel.
+   * @param typeId enum representing OGC WKB base code.
+   * @param srid spatial reference ID.
+   * @param hasZ whether this geometry has Z coordinate.
+   * @param hasM whether this geometry has M coordinate.
+   */
+  protected GeometryModel(GeoTypeId typeId, int srid, boolean hasZ, boolean 
hasM) {
+    this.typeId = typeId;
+    this.sridValue = srid;
+    this.hasZ = hasZ;
+    this.hasM = hasM;
+  }
+
+  /** GeometryModel getters and instance methods. */
+
+  // Returns the geometry type ID (OGC WKB base code)
+  GeoTypeId getTypeId() {
+    return typeId;
+  }
+
+  // Returns the SRID value
+  int srid() {
+    return sridValue;
+  }
+
+  // Sets the SRID value
+  void setSrid(int srid) {
+    this.sridValue = srid;
+  }
+
+  // Returns whether this geometry is empty (subclasses should override)
+  boolean isEmpty() {
+    return false;
+  }
+
+  // Returns the dimension count (2 for 2D, 3 for 3DZ/3DM, 4 for 4D)
+  // Subclasses should override this method
+  int getDimensionCount() {
+    return 2; // Default to 2D
+  }
+
+  // Returns true if this geometry has Z coordinate
+  boolean hasZ() {
+    return hasZ;
+  }
+
+  // Returns true if this geometry has M coordinate
+  boolean hasM() {
+    return hasM;
+  }
+
+  /** Type checking methods for GeometryModel subclasses. */
+
+  // Returns true if this geometry is a Point
+  boolean isPoint() {
+    return this instanceof Point;
+  }
+
+  // Returns true if this geometry is a LineString
+  boolean isLineString() {
+    return this instanceof LineString;
+  }
+
+  // Returns true if this geometry is a Polygon
+  boolean isPolygon() {
+    return this instanceof Polygon;
+  }
+
+  // Returns true if this geometry is a MultiPoint
+  boolean isMultiPoint() {
+    return this instanceof MultiPoint;
+  }
+
+  // Returns true if this geometry is a MultiLineString
+  boolean isMultiLineString() {
+    return this instanceof MultiLineString;
+  }
+
+  // Returns true if this geometry is a MultiPolygon
+  boolean isMultiPolygon() {
+    return this instanceof MultiPolygon;
+  }
+
+  // Returns true if this geometry is a GeometryCollection
+  boolean isGeometryCollection() {
+    return this instanceof GeometryCollection;
+  }
+
+  /** Type casting methods for GeometryModel subclasses. */
+  Point asPoint() {
+    if (isPoint()) {
+      return (Point) this;
+    }
+    throw new ClassCastException("Cannot cast " + getClass().getSimpleName() + 
" to Point");
+  }
+
+  LineString asLineString() {
+    if (isLineString()) {
+      return (LineString) this;
+    }
+    throw new ClassCastException("Cannot cast " + getClass().getSimpleName() + 
" to LineString");
+  }
+
+  Polygon asPolygon() {
+    if (isPolygon()) {
+      return (Polygon) this;
+    }
+    throw new ClassCastException("Cannot cast " + getClass().getSimpleName() + 
" to Polygon");
+  }
+
+  MultiPoint asMultiPoint() {
+    if (isMultiPoint()) {
+      return (MultiPoint) this;
+    }
+    throw new ClassCastException("Cannot cast " + getClass().getSimpleName() + 
" to MultiPoint");
+  }
+
+  MultiLineString asMultiLineString() {
+    if (isMultiLineString()) {
+      return (MultiLineString) this;
+    }
+    throw new ClassCastException(
+      "Cannot cast " + getClass().getSimpleName() + " to MultiLineString");
+  }
+
+  MultiPolygon asMultiPolygon() {
+    if (isMultiPolygon()) {
+      return (MultiPolygon) this;
+    }
+    throw new ClassCastException("Cannot cast " + getClass().getSimpleName() + 
" to MultiPolygon");
+  }
+
+  GeometryCollection asGeometryCollection() {
+    if (isGeometryCollection()) {
+      return (GeometryCollection) this;
+    }
+    throw new ClassCastException(
+      "Cannot cast " + getClass().getSimpleName() + " to GeometryCollection");
+  }
+}
+

Review Comment:
   Please remove the extra empty line at the end of file (currently it seems 
that there are 2 empty lines).



##########
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/util/geo/Ring.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ *
+ * In line with OGC standards, a ring must have at least 4 points,
+ * with the first and last point being identical to close the ring.
+ */
+class Ring {
+  private final List<Point> points;
+
+  Ring(List<Point> points) {
+    this.points = points;
+  }
+
+  List<Point> getPoints() {
+    return points;
+  }
+
+  int getNumPoints() {
+    return points.size();
+  }
+
+  boolean isEmpty() {
+    return points.isEmpty();
+  }
+
+  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());
+  }
+
+  /**
+   * Compares two coordinate arrays for equality.
+   */
+  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;
+      }
+    }
+    return true;
+  }
+}
+

Review Comment:
   Please remove the extra empty line at the end of file (currently it seems 
that there are 2 empty lines).



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