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


##########
python/sedonadb/tests/geography/test_geog_mechanical_transforms.py:
##########
@@ -0,0 +1,695 @@
+# 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.
+
+"""
+Tests for mechanical geography transformations whose implementations are shared
+with geometry
+"""
+
+import pytest
+from sedonadb.testing import SedonaDB, geog_or_null, val_or_null
+
+
[email protected]("eng", [SedonaDB])
[email protected](
+    ("geog", "expected"),
+    [
+        pytest.param(None, None, id="null"),
+        pytest.param("POINT EMPTY", "POINT (nan nan)", id="point_empty"),
+        pytest.param("LINESTRING EMPTY", "LINESTRING EMPTY", 
id="linestring_empty"),
+        pytest.param("POLYGON EMPTY", "POLYGON EMPTY", id="polygon_empty"),
+        pytest.param("POINT (0 1)", "POINT (1 0)", id="point"),
+        pytest.param("LINESTRING (0 1, 2 3)", "LINESTRING (1 0, 3 2)", 
id="linestring"),
+        pytest.param(
+            "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))",
+            "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
+            id="polygon",
+        ),
+        pytest.param("POINT Z (0 1 5)", "POINT Z (1 0 5)", id="point_z"),
+        pytest.param("POINT M (0 1 5)", "POINT M (1 0 5)", id="point_m"),
+        pytest.param("POINT ZM (0 1 5 7)", "POINT ZM (1 0 5 7)", 
id="point_zm"),
+    ],
+)
+def test_st_flipcoordinates(eng, geog, expected):
+    eng = eng.create_or_skip()
+    eng.assert_query_result(
+        f"SELECT ST_FlipCoordinates({geog_or_null(geog)})", expected
+    )
+
+
[email protected]("eng", [SedonaDB])
[email protected](
+    ("geog", "expected_2d", "expected_3d"),
+    [
+        pytest.param(None, None, None, id="null"),
+        pytest.param(
+            "POINT EMPTY",
+            "POINT (nan nan)",
+            "POINT Z (nan nan nan)",
+            id="point_empty",
+        ),
+        pytest.param(
+            "LINESTRING EMPTY",
+            "LINESTRING EMPTY",
+            "LINESTRING Z EMPTY",
+            id="linestring_empty",
+        ),
+        pytest.param("POINT (0 1)", "POINT (0 1)", "POINT Z (0 1 5)", 
id="point"),
+        pytest.param("POINT Z (0 1 9)", "POINT (0 1)", "POINT Z (0 1 9)", 
id="point_z"),
+        pytest.param("POINT M (0 1 9)", "POINT (0 1)", "POINT Z (0 1 5)", 
id="point_m"),
+        pytest.param(
+            "POINT ZM (0 1 9 8)", "POINT (0 1)", "POINT Z (0 1 9)", 
id="point_zm"
+        ),
+    ],
+)
+def test_st_force_dim(eng, geog, expected_2d, expected_3d):
+    eng = eng.create_or_skip()
+    eng.assert_query_result(f"SELECT ST_Force2D({geog_or_null(geog)})", 
expected_2d)
+    eng.assert_query_result(f"SELECT ST_Force3D({geog_or_null(geog)}, 5)", 
expected_3d)
+
+
[email protected]("eng", [SedonaDB])
[email protected](
+    ("geog", "m", "expected_without_m", "expected_with_m"),
+    [
+        pytest.param(None, 5, None, None, id="null"),
+        pytest.param(
+            "POINT EMPTY",
+            5,
+            "POINT M (nan nan nan)",
+            "POINT M (nan nan nan)",
+            id="point_empty",
+        ),
+        pytest.param(
+            "POINT (0 1)", 5, "POINT M (0 1 0)", "POINT M (0 1 5)", id="point"
+        ),
+        pytest.param(
+            "POINT Z (0 1 2)", 5, "POINT M (0 1 0)", "POINT M (0 1 5)", 
id="point_z"
+        ),
+        pytest.param(
+            "POINT M (0 1 3)", 5, "POINT M (0 1 3)", "POINT M (0 1 3)", 
id="point_m"
+        ),
+        pytest.param(
+            "POINT ZM (0 1 2 3)",
+            5,
+            "POINT M (0 1 3)",
+            "POINT M (0 1 3)",
+            id="point_zm",
+        ),
+    ],
+)
+def test_st_force3dm(eng, geog, m, expected_without_m, expected_with_m):
+    eng = eng.create_or_skip()
+    eng.assert_query_result(
+        f"SELECT ST_Force3DM({geog_or_null(geog)})", expected_without_m
+    )
+    eng.assert_query_result(
+        f"SELECT ST_Force3DM({geog_or_null(geog)}, {val_or_null(m)})", 
expected_with_m
+    )
+
+
[email protected]("eng", [SedonaDB])
[email protected](
+    ("geog", "z", "m", "expected_without_defaults", "expected_with_defaults"),
+    [
+        pytest.param(None, 5, 7, None, None, id="null"),
+        pytest.param(
+            "POINT EMPTY",
+            5,
+            7,
+            "POINT ZM (nan nan nan nan)",
+            "POINT ZM (nan nan nan nan)",
+            id="point_empty",
+        ),
+        pytest.param(
+            "POINT (0 1)",
+            5,
+            7,
+            "POINT ZM (0 1 0 0)",
+            "POINT ZM (0 1 5 7)",
+            id="point",
+        ),
+        pytest.param(
+            "POINT Z (0 1 2)",
+            5,
+            7,
+            "POINT ZM (0 1 2 0)",
+            "POINT ZM (0 1 2 7)",
+            id="point_z",
+        ),
+        pytest.param(
+            "POINT M (0 1 3)",
+            5,
+            7,
+            "POINT ZM (0 1 0 3)",
+            "POINT ZM (0 1 5 3)",
+            id="point_m",
+        ),
+        pytest.param(
+            "POINT ZM (0 1 2 3)",
+            5,
+            7,
+            "POINT ZM (0 1 2 3)",
+            "POINT ZM (0 1 2 3)",
+            id="point_zm",
+        ),
+    ],
+)
+def test_st_force4d(eng, geog, z, m, expected_without_defaults, 
expected_with_defaults):
+    eng = eng.create_or_skip()
+    eng.assert_query_result(
+        f"SELECT ST_Force4D({geog_or_null(geog)})", expected_without_defaults
+    )
+    eng.assert_query_result(
+        f"SELECT ST_Force4D({geog_or_null(geog)}, {val_or_null(z)}, 
{val_or_null(m)})",
+        expected_with_defaults,
+    )
+
+
[email protected]("eng", [SedonaDB])
[email protected](
+    ("geog", "index", "expected"),
+    [
+        pytest.param(None, 1, None, id="null"),
+        pytest.param("POINT EMPTY", 1, "POINT (nan nan)", id="point_empty"),
+        pytest.param("MULTIPOINT EMPTY", 1, None, id="multipoint_empty"),
+        pytest.param("POINT (1 1)", 1, "POINT (1 1)", id="point_n1"),
+        pytest.param("POINT (1 1)", 2, None, id="point_n2_oob"),
+        pytest.param(
+            "MULTIPOINT ((1 1), (2 2), (3 3))", 2, "POINT (2 2)", 
id="multipoint_n2"
+        ),
+        pytest.param(
+            "MULTILINESTRING ((1 1, 2 2), (3 3, 4 4))",
+            1,
+            "LINESTRING (1 1, 2 2)",
+            id="multilinestring_n1",
+        ),
+        pytest.param(
+            "GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (3 4, 5 6))",
+            2,
+            "LINESTRING (3 4, 5 6)",
+            id="gc_n2",
+        ),
+        pytest.param(
+            "MULTIPOINT Z ((1 1 5), (2 2 6))",
+            1,
+            "POINT Z (1 1 5)",
+            id="multipoint_z",
+        ),
+        pytest.param(
+            "MULTIPOINT M ((1 1 5), (2 2 6))",
+            1,
+            "POINT M (1 1 5)",
+            id="multipoint_m",
+        ),
+        pytest.param(
+            "MULTIPOINT ZM ((1 1 5 7), (2 2 6 8))",
+            1,
+            "POINT ZM (1 1 5 7)",
+            id="multipoint_zm",
+        ),
+    ],
+)
+def test_st_geometryn(eng, geog, index, expected):
+    eng = eng.create_or_skip()
+    eng.assert_query_result(
+        f"SELECT ST_GeometryN({geog_or_null(geog)}, {val_or_null(index)})", 
expected
+    )
+
+
[email protected]("eng", [SedonaDB])
[email protected](
+    ("geog", "index", "expected"),
+    [
+        pytest.param(None, 1, None, id="null"),
+        pytest.param("POINT (0 0)", 1, None, id="point"),
+        pytest.param("LINESTRING (0 0, 1 1)", 1, None, id="linestring"),
+        pytest.param("POLYGON EMPTY", 1, None, id="polygon_empty"),
+        pytest.param(
+            "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", 1, None, 
id="polygon_no_holes"
+        ),
+        pytest.param(
+            "POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))",
+            1,
+            "LINESTRING (1 1, 1 2, 2 2, 2 1, 1 1)",
+            id="polygon_with_hole",
+        ),
+        pytest.param(
+            "POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))",
+            2,
+            None,
+            id="polygon_oob",
+        ),
+        pytest.param(
+            "POLYGON Z ((0 0 10, 4 0 10, 4 4 10, 0 4 10, 0 0 10), (1 1 5, 1 2 
5, 2 2 5, 2 1 5, 1 1 5))",
+            1,
+            "LINESTRING Z (1 1 5, 1 2 5, 2 2 5, 2 1 5, 1 1 5)",
+            id="polygon_z",
+        ),
+        pytest.param(
+            "POLYGON M ((0 0 1, 4 0 2, 4 4 3, 0 4 4, 0 0 5), (1 1 6, 1 2 7, 2 
2 8, 2 1 9, 1 1 10))",
+            1,
+            "LINESTRING M (1 1 6, 1 2 7, 2 2 8, 2 1 9, 1 1 10)",
+            id="polygon_m",
+        ),
+        pytest.param(
+            "POLYGON ZM ((0 0 10 1, 4 0 10 2, 4 4 10 3, 0 4 10 4, 0 0 10 5), 
(1 1 5 6, 1 2 5 7, 2 2 5 8, 2 1 5 9, 1 1 5 10))",
+            1,
+            "LINESTRING ZM (1 1 5 6, 1 2 5 7, 2 2 5 8, 2 1 5 9, 1 1 5 10)",
+            id="polygon_zm",
+        ),
+    ],
+)
+def test_st_interiorringn(eng, geog, index, expected):
+    eng = eng.create_or_skip()
+    eng.assert_query_result(
+        f"SELECT ST_InteriorRingN({geog_or_null(geog)}, 
{val_or_null(index)})", expected
+    )
+
+
[email protected]("eng", [SedonaDB])
[email protected](
+    ("geog", "expected"),
+    [
+        pytest.param(None, None, id="null"),
+        pytest.param("POINT EMPTY", "POINT (nan nan)", id="point_empty"),
+        pytest.param("LINESTRING EMPTY", "LINESTRING EMPTY", 
id="linestring_empty"),
+        pytest.param("POINT (1 2)", "POINT (1 2)", id="point"),
+        pytest.param(
+            "LINESTRING (0 0, 1 1, 2 2)",
+            "LINESTRING (2 2, 1 1, 0 0)",
+            id="linestring",
+        ),
+        pytest.param(
+            "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
+            "POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))",
+            id="polygon",
+        ),
+        pytest.param("MULTIPOINT (1 2, 3 4)", "MULTIPOINT (1 2, 3 4)", 
id="multipoint"),
+        pytest.param(
+            "LINESTRING Z (0 0 1, 1 1 2, 2 2 3)",
+            "LINESTRING Z (2 2 3, 1 1 2, 0 0 1)",
+            id="linestring_z",
+        ),
+        pytest.param(
+            "LINESTRING M (0 0 1, 1 1 2, 2 2 3)",
+            "LINESTRING M (2 2 3, 1 1 2, 0 0 1)",
+            id="linestring_m",
+        ),
+        pytest.param(
+            "LINESTRING ZM (0 0 1 4, 1 1 2 5, 2 2 3 6)",
+            "LINESTRING ZM (2 2 3 6, 1 1 2 5, 0 0 1 4)",
+            id="linestring_zm",
+        ),
+    ],
+)
+def test_st_reverse(eng, geog, expected):

Review Comment:
   should there be a test here about very large geographies and their 
interaction with the winding order and how we determine what the inside of the 
polygon is?
   
   Not sure how we handle determining the inside of a geog polygon in sedona db.



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