This is an automated email from the ASF dual-hosted git repository.
petern pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new ab73e829ed [GH-2389] replace `GeometryType()` with `ST_GeometryType()`
(#2416)
ab73e829ed is described below
commit ab73e829ed71e4e6148be282f7898132a40f6f76
Author: Yunchi Pang <[email protected]>
AuthorDate: Fri Nov 14 20:18:44 2025 -0800
[GH-2389] replace `GeometryType()` with `ST_GeometryType()` (#2416)
Co-authored-by: Peter Nguyen <[email protected]>
---
python/sedona/spark/geopandas/geoseries.py | 20 ++++++-----
python/tests/geopandas/test_geoseries.py | 53 ++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/python/sedona/spark/geopandas/geoseries.py
b/python/sedona/spark/geopandas/geoseries.py
index 65c87201c1..95cf7d752b 100644
--- a/python/sedona/spark/geopandas/geoseries.py
+++ b/python/sedona/spark/geopandas/geoseries.py
@@ -740,21 +740,25 @@ class GeoSeries(GeoFrame, pspd.Series):
def length(self) -> pspd.Series:
spark_expr = (
F.when(
- stf.GeometryType(self.spark.column).isin(
- ["LINESTRING", "MULTILINESTRING"]
+ stf.ST_GeometryType(self.spark.column).isin(
+ ["ST_LineString", "ST_MultiLineString"]
),
stf.ST_Length(self.spark.column),
)
.when(
- stf.GeometryType(self.spark.column).isin(["POLYGON",
"MULTIPOLYGON"]),
+ stf.ST_GeometryType(self.spark.column).isin(
+ ["ST_Polygon", "ST_MultiPolygon"]
+ ),
stf.ST_Perimeter(self.spark.column),
)
.when(
- stf.GeometryType(self.spark.column).isin(["POINT",
"MULTIPOINT"]),
+ stf.ST_GeometryType(self.spark.column).isin(
+ ["ST_Point", "ST_MultiPoint"]
+ ),
0.0,
)
.when(
-
stf.GeometryType(self.spark.column).isin(["GEOMETRYCOLLECTION"]),
+
stf.ST_GeometryType(self.spark.column).isin(["ST_GeometryCollection"]),
stf.ST_Length(self.spark.column) +
stf.ST_Perimeter(self.spark.column),
)
)
@@ -953,7 +957,7 @@ class GeoSeries(GeoFrame, pspd.Series):
# Geopandas and shapely return NULL for GeometryCollections, so we
handle it separately
#
https://shapely.readthedocs.io/en/stable/reference/shapely.boundary.html
spark_expr = F.when(
- stf.GeometryType(self.spark.column).isin(["GEOMETRYCOLLECTION"]),
+
stf.ST_GeometryType(self.spark.column).isin(["ST_GeometryCollection"]),
None,
).otherwise(stf.ST_Boundary(self.spark.column))
return self._query_geometry_column(
@@ -1148,8 +1152,8 @@ class GeoSeries(GeoFrame, pspd.Series):
align = False if extended else align
spark_expr = F.when(
- (stf.GeometryType(F.col("L")) == "GEOMETRYCOLLECTION")
- | (stf.GeometryType(F.col("R")) == "GEOMETRYCOLLECTION"),
+ (stf.ST_GeometryType(F.col("L")) == "ST_GeometryCollection")
+ | (stf.ST_GeometryType(F.col("R")) == "ST_GeometryCollection"),
None,
).otherwise(stp.ST_Crosses(F.col("L"), F.col("R")))
result = self._row_wise_operation(
diff --git a/python/tests/geopandas/test_geoseries.py
b/python/tests/geopandas/test_geoseries.py
index 30d791b5bf..8d3455fa8f 100644
--- a/python/tests/geopandas/test_geoseries.py
+++ b/python/tests/geopandas/test_geoseries.py
@@ -674,6 +674,21 @@ e": "Feature", "properties": {}, "geometry": {"type":
"Point", "coordinates": [3
df_result = geoseries.to_geoframe().length
self.check_pd_series_equal(df_result, expected)
+ # Ensure M-dimension doesn't break things.
+ s = GeoSeries(
+ [
+ wkt.loads("POINT M (0 0 0)"),
+ wkt.loads("LINESTRING M (0 0 0, 1 1 0)"),
+ wkt.loads("POLYGON M ((0 0 0, 1 0 0, 1 1 0, 0 0 0))"),
+ wkt.loads(
+ "GEOMETRYCOLLECTION M (POINT M (0 0 0), LINESTRING M (0 0
0, 1 1 0), POLYGON M ((0 0 0, 1 0 0, 1 1 0, 0 0 0)))"
+ ),
+ ]
+ )
+ result = s.length
+ expected = pd.Series([0.000000, 1.414214, 3.414214, 4.828427])
+ self.check_pd_series_equal(result, expected)
+
def test_is_valid(self):
geoseries = sgpd.GeoSeries(
[
@@ -1088,6 +1103,15 @@ e": "Feature", "properties": {}, "geometry": {"type":
"Point", "coordinates": [3
result = s.to_geoframe().is_closed
self.check_pd_series_equal(result, expected)
+ s = GeoSeries(
+ [
+ wkt.loads("LINESTRING M (0 0 0, 1 1 0, 1 -1 0, 0 0 0)"),
+ ]
+ )
+ result = s.is_closed
+ expected = pd.Series([True])
+ self.check_pd_series_equal(result, expected)
+
def test_has_z(self):
s = sgpd.GeoSeries(
[
@@ -1181,6 +1205,20 @@ e": "Feature", "properties": {}, "geometry": {"type":
"Point", "coordinates": [3
df_result = s.to_geoframe().boundary
self.check_sgpd_equals_gpd(df_result, expected)
+ # Ensure M-dimension doesn't break things.
+ s = GeoSeries(
+ [
+ wkt.loads("GEOMETRYCOLLECTION M (POINT M (1 2 3))"),
+ ]
+ )
+ result = s.boundary
+ expected = gpd.GeoSeries(
+ [
+ None,
+ ]
+ )
+ self.check_sgpd_equals_gpd(result, expected)
+
def test_centroid(self):
s = sgpd.GeoSeries(
[
@@ -1557,6 +1595,21 @@ e": "Feature", "properties": {}, "geometry": {"type":
"Point", "coordinates": [3
df_result = s.to_geoframe().crosses(s2, align=False)
self.check_pd_series_equal(df_result, expected)
+ # Sedona ST_Crosses doesn't support GeometryCollection, so it returns
NULL for now.
+ # https://github.com/apache/sedona/issues/2417
+ # Once this is resolved, we can update the expected result of this
test.
+ # Ensure M-dimension doesn't break things.
+ s = GeoSeries(
+ [
+ wkt.loads("GEOMETRYCOLLECTION M (POINT M (1 2 3))"),
+ wkt.loads("LINESTRING M (0 0 1, 1 1 2)"),
+ ]
+ )
+ line = LineString([(0, 0), (1, 1)])
+ result = s.crosses(line)
+ expected = pd.Series([None, False])
+ self.check_pd_series_equal(result, expected)
+
def test_disjoint(self):
pass