paleolimbot commented on code in PR #816: URL: https://github.com/apache/sedona-db/pull/816#discussion_r3230293699
########## python/sedonadb/tests/geography/test_geog_overlay.py: ########## @@ -0,0 +1,605 @@ +# 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. + +import pytest +import sedonadb +from sedonadb.testing import BigQuery, SedonaDB, geog_or_null + +if "s2geography" not in sedonadb.__features__: + pytest.skip("Python package built without s2geography", allow_module_level=True) + + +# ST_Intersection tests [email protected]("eng", [SedonaDB, BigQuery]) [email protected]( + ("geom1", "geom2", "expected"), + [ + # Nulls + pytest.param(None, "POINT (0 0)", None, id="null_intersection"), + pytest.param("POINT (0 0)", None, None, id="intersection_null"), + pytest.param(None, None, None, id="null_intersection_null"), + # Point + Point: same + pytest.param("POINT (0 0)", "POINT (0 0)", "POINT (0 0)", id="point_same"), + # Multipoint + Point: overlap + pytest.param( + "MULTIPOINT ((0 0), (1 1))", + "POINT (0 0)", + "POINT (0 0)", + id="multipoint_point_overlap", + ), + # Linestring + Linestring: same + pytest.param( + "LINESTRING (0 0, 10 0)", + "LINESTRING (0 0, 10 0)", + "LINESTRING (0 0, 10 0)", + id="linestring_same", + ), + # Linestring + Linestring: crossing (intersection is a point) + pytest.param( + "LINESTRING (0 -5, 0 5)", + "LINESTRING (-5 0, 5 0)", + "POINT (0 0)", + id="linestring_crossing", + ), + # Polygon + Polygon: same + pytest.param( + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", + id="polygon_same", + ), + # Point + Linestring: point at endpoint + pytest.param( + "POINT (0 0)", + "LINESTRING (0 0, 10 0)", + "POINT (0 0)", + id="point_on_linestring", + ), + # Point + Polygon: point inside + pytest.param( + "POINT (5 5)", + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", + "POINT (5 5)", + id="point_inside_polygon", + ), + # Point + Polygon: point on boundary + pytest.param( + "POINT (10 5)", + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", + "POINT (10 5)", + id="point_on_polygon_boundary", + ), + # Linestring + Polygon: line inside + pytest.param( + "LINESTRING (2 5, 8 5)", + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", + "LINESTRING (2 5, 8 5)", + id="linestring_inside_polygon", + ), + ], +) +def test_st_intersection(eng, geom1, geom2, expected): + eng = eng.create_or_skip() + eng.assert_query_result( + f"SELECT ST_Intersection({geog_or_null(geom1)}, {geog_or_null(geom2)})", + expected, + wkt_precision=6, + ) + + +# Empties - BigQuery doesn't return specific empty types consistently [email protected]("eng", [SedonaDB]) [email protected]( + ("geom1", "geom2", "expected"), + [ + pytest.param( + "POINT EMPTY", + "POINT EMPTY", + "GEOMETRYCOLLECTION EMPTY", + id="both_empty", + ), + pytest.param( + "POINT EMPTY", + "POINT (0 0)", + "GEOMETRYCOLLECTION EMPTY", + id="empty_a_point", + ), + pytest.param( + "POINT (0 0)", + "POINT EMPTY", + "GEOMETRYCOLLECTION EMPTY", + id="empty_b_point", + ), + pytest.param( + "POLYGON EMPTY", + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", + "GEOMETRYCOLLECTION EMPTY", + id="empty_a_polygon", + ), + pytest.param( + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", + "POLYGON EMPTY", + "GEOMETRYCOLLECTION EMPTY", + id="empty_b_polygon", + ), + ], +) +def test_st_intersection_empties(eng, geom1, geom2, expected): + eng = eng.create_or_skip() + eng.assert_query_result( + f"SELECT ST_Intersection({geog_or_null(geom1)}, {geog_or_null(geom2)})", + expected, + wkt_precision=6, + ) + + +# Results that return EMPTY - BigQuery differs in handling [email protected]("eng", [SedonaDB]) [email protected]( + ("geom1", "geom2", "expected"), + [ + # Linestring + Linestring: disjoint + pytest.param( + "LINESTRING (0 0, 10 0)", + "LINESTRING (0 10, 10 10)", + "LINESTRING EMPTY", + id="linestring_disjoint", + ), + # Polygon + Polygon: disjoint + pytest.param( + "POLYGON ((0 0, 5 0, 5 5, 0 5, 0 0))", + "POLYGON ((10 10, 15 10, 15 15, 10 15, 10 10))", + "POLYGON EMPTY", + id="polygon_disjoint", + ), + # Linestring + Polygon: line outside + pytest.param( + "LINESTRING (20 0, 30 0)", + "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))", + "LINESTRING EMPTY", + id="linestring_outside_polygon", + ), + ], +) +def test_st_intersection_returns_empty(eng, geom1, geom2, expected): + eng = eng.create_or_skip() + eng.assert_query_result( + f"SELECT ST_Intersection({geog_or_null(geom1)}, {geog_or_null(geom2)})", + expected, + wkt_precision=6, + ) + + +# Results that return POINT (nan nan) - BigQuery differs in handling [email protected]("eng", [SedonaDB]) [email protected]( + ("geom1", "geom2", "expected"), + [ + # Point + Point: different + pytest.param( + "POINT (0 0)", "POINT (0 1)", "POINT (nan nan)", id="point_different" + ), + # Multipoint + Point: disjoint + pytest.param( + "MULTIPOINT ((0 0), (1 1))", + "POINT (2 2)", + "POINT (nan nan)", Review Comment: This is a bug in the testing framework/geoarrow-c. I annotated this like is done elsewhere in the tests -- 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]
