james-willis commented on code in PR #816:
URL: https://github.com/apache/sedona-db/pull/816#discussion_r3222862023


##########
python/sedonadb/tests/geography/test_geog_measures.py:
##########
@@ -16,38 +16,283 @@
 # under the License.
 
 import pytest
-from sedonadb.testing import BigQuery, PostGIS, SedonaDB, geog_or_null
 import sedonadb
+from sedonadb.testing import BigQuery, SedonaDB, PostGIS, geog_or_null
 
 if "s2geography" not in sedonadb.__features__:
     pytest.skip("Python package built without s2geography", 
allow_module_level=True)
 
 
[email protected]("eng", [SedonaDB, PostGIS, BigQuery])
[email protected]("eng", [SedonaDB, BigQuery, PostGIS])
 @pytest.mark.parametrize(
-    ("geom1", "geom2", "expected"),
+    ("geog", "expected"),
     [
-        (None, None, None),
-        # Single arg nulls are not handled by SedonaDB until upgrade
-        # ("POINT (0 0)", None, None),
-        # (None, "POINT (0 0)", None),
-        ("POINT (0 0)", "POINT (0 0)", 0),
-        (
-            "POINT(-72.1235 42.3521)",
-            "LINESTRING(-72.1260 42.45, -72.123 42.1546)",
-            123.47576072749062,  # 123.80207675
-        ),
-        (
-            "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
-            "POLYGON ((5 5, 6 5, 6 6, 5 6, 5 5))",
-            628519.1549911008,  # 627129.50261075
+        # Nulls
+        pytest.param(None, None, id="null_area"),
+        # Empties
+        pytest.param("POINT EMPTY", 0.0, id="point_empty"),
+        pytest.param("LINESTRING EMPTY", 0.0, id="linestring_empty"),
+        pytest.param("POLYGON EMPTY", 0.0, id="polygon_empty"),
+        # Points (zero area)
+        pytest.param("POINT (0 0)", 0.0, id="point"),
+        pytest.param("MULTIPOINT ((0 0), (1 1))", 0.0, id="multipoint"),
+        # Linestrings (zero area)
+        pytest.param("LINESTRING (0 0, 0 1)", 0.0, id="linestring"),
+        pytest.param(
+            "MULTILINESTRING ((0 0, 0 1), (1 0, 1 1))", 0.0, 
id="multilinestring"
+        ),
+        # Polygons
+        pytest.param(
+            "POLYGON ((0 0, 0 1, 1 0, 0 0))", 6182489130.9071951, id="triangle"
+        ),
+        pytest.param(
+            "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", 12364036567.076418, 
id="square"
+        ),
+        # Multipolygon
+        pytest.param(
+            "MULTIPOLYGON (((0 0, 0 1, 1 0, 0 0)), ((10 10, 10 11, 11 10, 10 
10)))",
+            12271037686.230379,
+            id="multipolygon",
+        ),
+        # Polygon with hole
+        pytest.param(
+            "POLYGON ((0 0, 0 2, 2 0, 0 0), (0.1 0.1, 0.1 0.5, 0.5 0.1, 0.1 
0.1))",
+            23744568445.094166,
+            id="polygon_with_hole",
+        ),
+        # GeometryCollection (area from polygon only)
+        pytest.param(
+            "GEOMETRYCOLLECTION (POINT (5 5), LINESTRING (0 0, 0 1), POLYGON 
((0 0, 0 1, 1 0, 0 0)))",
+            6182489130.9071951,
+            id="geometrycollection",
+        ),
+    ],
+)
+def test_st_area(eng, geog, expected):
+    eng = eng.create_or_skip()
+    # Use reduced precision for PostGIS because it is calculating true 
ellipsoidal area
+    # and not the spherical approximation
+    if eng.name() == "postgis":
+        eps = 1e-2
+    else:
+        eps = 1e-15
+
+    eng.assert_query_result(
+        f"SELECT ST_Area({geog_or_null(geog)})", expected, numeric_epsilon=eps
+    )
+
+
[email protected]("eng", [SedonaDB, BigQuery, PostGIS])
[email protected](
+    ("geog", "expected"),
+    [
+        # Nulls
+        pytest.param(None, None, id="null_length"),
+        # Empties
+        pytest.param("POINT EMPTY", 0.0, id="point_empty"),
+        pytest.param("LINESTRING EMPTY", 0.0, id="linestring_empty"),
+        pytest.param("POLYGON EMPTY", 0.0, id="polygon_empty"),
+        # Points (zero length)
+        pytest.param("POINT (0 0)", 0.0, id="point"),
+        pytest.param("MULTIPOINT ((0 0), (1 1))", 0.0, id="multipoint"),
+        # Linestrings
+        pytest.param(
+            "LINESTRING (0 0, 0 1)", 111195.10117748393, 
id="linestring_one_segment"
+        ),
+        pytest.param(
+            "LINESTRING (0 0, 0 1, 1 1)",
+            222373.26637265272,
+            id="linestring_two_segments",
+        ),
+        pytest.param(
+            "MULTILINESTRING ((0 0, 0 1), (1 0, 1 1))",
+            222390.20235496786,
+            id="multilinestring",
+        ),
+        # Polygons (zero length — perimeter is separate)
+        pytest.param("POLYGON ((0 0, 0 1, 1 0, 0 0))", 0.0, id="triangle"),
+        pytest.param("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", 0.0, id="square"),
+    ],
+)
+def test_st_length(eng, geog, expected):
+    eng = eng.create_or_skip()
+    # Use reduced precision for PostGIS because it is calculating true 
ellipsoidal length
+    # and not the spherical approximation
+    if eng.name() == "postgis":
+        eps = 1e-2
+    else:
+        eps = 1e-15

Review Comment:
   should we encode this into the assert_query_results method somehow? maybe an 
is_spheroidal flag?



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

Reply via email to