This is an automated email from the ASF dual-hosted git repository.
jiayu 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 3b13ae8dff [GH-2120] Support serializing LinearRing in C bindings for
Python interface (#2124)
3b13ae8dff is described below
commit 3b13ae8dffd9e76d45bf4a72ca1a8be7fefae094
Author: Peter Nguyen <[email protected]>
AuthorDate: Sat Jul 19 18:56:02 2025 -0700
[GH-2120] Support serializing LinearRing in C bindings for Python interface
(#2124)
* Support serializing linearring in python
* Temporarily set fail-fast: false to debug ci failure
* Use only valid linear rings in tests and revert ci temp change
* Skip type assertion if empty geom for shapely < 2 compatbility
---
python/src/geomserde.c | 4 +---
python/tests/utils/test_geometry_serde.py | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/python/src/geomserde.c b/python/src/geomserde.c
index 18a57714f1..c1f7427738 100644
--- a/python/src/geomserde.c
+++ b/python/src/geomserde.c
@@ -645,12 +645,10 @@ SedonaErrorCode sedona_serialize_geom(GEOSContextHandle_t
handle,
p_buf_size);
break;
case GEOS_LINESTRING:
+ case GEOS_LINEARRING:
err = sedona_serialize_linestring(handle, geom, srid, &cs_info, p_buf,
p_buf_size);
break;
- case GEOS_LINEARRING:
- err = SEDONA_UNSUPPORTED_GEOM_TYPE;
- break;
case GEOS_POLYGON:
err = sedona_serialize_polygon(handle, geom, srid, &cs_info, p_buf,
p_buf_size);
diff --git a/python/tests/utils/test_geometry_serde.py
b/python/tests/utils/test_geometry_serde.py
index 32bca7b376..1eeb895b4c 100644
--- a/python/tests/utils/test_geometry_serde.py
+++ b/python/tests/utils/test_geometry_serde.py
@@ -25,6 +25,7 @@ from shapely.geometry import (
MultiPolygon,
Point,
Polygon,
+ LinearRing,
)
from shapely.wkt import loads as wkt_loads
from tests.test_base import TestBase
@@ -102,6 +103,22 @@ class TestGeometrySerde(TestBase):
).take(1)[0][0]
assert geom.equals_exact(returned_geom, 1e-6)
+ @pytest.mark.parametrize(
+ "geom",
+ [
+ LinearRing(),
+ LinearRing([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]),
+ ],
+ )
+ def test_linearring_spark_serde(self, geom):
+ returned_geom = TestGeometrySerde.spark.createDataFrame(
+ [(geom,)], StructType().add("geom", GeometryType())
+ ).take(1)[0][0]
+ # Shapely < 2.0.0 returns an empty GeometryCollection instead
+ if not geom.is_empty:
+ assert isinstance(returned_geom, LineString)
+ assert geom.equals(returned_geom)
+
@pytest.mark.parametrize(
"wkt",
[
@@ -143,6 +160,8 @@ class TestGeometrySerde(TestBase):
"MULTIPOLYGON (EMPTY, EMPTY)",
"GEOMETRYCOLLECTION (POINT (10 20), POINT EMPTY, LINESTRING (10
20, 30 40))",
"GEOMETRYCOLLECTION (MULTIPOINT EMPTY, MULTILINESTRING EMPTY,
MULTIPOLYGON EMPTY, GEOMETRYCOLLECTION EMPTY)",
+ "LINEARRING EMPTY",
+ "LINEARRING (-1 -1, -1 1, 1 1, 1 -1, -1 -1)",
],
)
def test_spark_serde_compatibility_with_scala(self, wkt):
@@ -181,6 +200,7 @@ class TestGeometrySerde(TestBase):
"MULTIPOLYGON ZM (((10 10 10 1, 20 20 10 1, 20 10 10 1, 10 10 10
1)), "
+ "((0 0 0 1, 0 10 0 1, 10 10 0 1, 10 0 0 1, 0 0 0 1), (1 1 0 1, 1
2 0 1, 2 2 0 1, 2 1 0 1, 1 1 0 1)))",
"GEOMETRYCOLLECTION (POINT ZM (10 20 30 1), LINESTRING ZM (10 20
30 1, 40 50 60 1))",
+ "LINEARRING ZM (0 0 0 1, 0 0 1 0, 0 1 0 0, 1 0 0 0, 0 0 0 1)",
],
)
def test_spark_serde_on_4d_geoms(self, wkt):
@@ -205,6 +225,7 @@ class TestGeometrySerde(TestBase):
"MULTIPOLYGON M (((10 10 10, 20 20 10, 20 10 10, 10 10 10)), "
+ "((0 0 0, 0 10 0, 10 10 0, 10 0 0, 0 0 0), (1 1 0, 1 2 0, 2 2 0,
2 1 0, 1 1 0)))",
"GEOMETRYCOLLECTION (POINT M (10 20 30), LINESTRING M (10 20 30,
40 50 60))",
+ "LINEARRING M (0 0 0, 1 0 0, 0 1 0, 0 0 1, 0 0 0)",
],
)
def test_spark_serde_on_xym_geoms(self, wkt):