-
Notifications
You must be signed in to change notification settings - Fork 28
feat: Implement ST_Crosses and ST_Overlaps predicates #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
A few optional things to consider, but in general this looks good to me!
We also include integration tests for all our functions in Python (to check against PostGIS). It would be helpful if you did that here, but it is also no problem if you prefer not to (you or one of us can create a follow-on issue to ensure we do it at some point). These integration tests will be very similar to the other predicate integration tests:
sedona-db/python/sedonadb/tests/functions/test_predicates.py
Lines 53 to 82 in 95c156d
| @pytest.mark.parametrize("eng", [SedonaDB, PostGIS]) | |
| @pytest.mark.parametrize( | |
| ("geom1", "geom2", "expected"), | |
| [ | |
| (None, None, None), | |
| ("POINT (0 0)", None, None), | |
| (None, "POINT (0 0)", None), | |
| ("POINT (0 0)", "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", True), | |
| ("POINT (0.5 0.5)", "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", True), | |
| ("POINT (0 0)", "POINT EMPTY", False), | |
| ("POINT (0 0)", "LINESTRING (0 0, 1 1)", True), | |
| ("LINESTRING (0 0, 1 1)", "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", True), | |
| ( | |
| "POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", | |
| "POLYGON ((5 5, 6 5, 6 6, 5 6, 5 5))", | |
| False, | |
| ), | |
| ( | |
| "POINT (1 1)", | |
| "GEOMETRYCOLLECTION (POINT (0 0), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), LINESTRING (0 0, 1 1))", | |
| True, | |
| ), | |
| ], | |
| ) | |
| def test_st_covered_by(eng, geom1, geom2, expected): | |
| eng = eng.create_or_skip() | |
| eng.assert_query_result( | |
| f"SELECT ST_CoveredBy({geom_or_null(geom1)}, {geom_or_null(geom2)})", | |
| expected, | |
| ) |
...and some instructions on how to get started with the Python package are here: https://github.com/apache/sedona-db/blob/main/docs/contributors-guide.md#python
| let arg2 = create_array( | ||
| &[ | ||
| Some("POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))"), | ||
| Some("LINESTRING (1 0, 3 0)"), | ||
| Some("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))"), | ||
| ], | ||
| &WKB_GEOMETRY, | ||
| ); | ||
| let expected: ArrayRef = arrow_array!(Boolean, [Some(true), Some(true), None]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test would be more useful if one of the results were false
c/sedona-geos/src/geos.rs
Outdated
| } | ||
| } | ||
|
|
||
| /// Check if the geometries crosses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| /// Check if the geometries crosses | |
| /// Check if the geometries cross |
c/sedona-geos/src/geos.rs
Outdated
| } | ||
| } | ||
|
|
||
| /// Check if the geometries overlaps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| /// Check if the geometries overlaps | |
| /// Check if the geometries overlap |
|
Great work! how do these functions work with our current spatial join implementation? |
Spatial join has its own spatial predicate evaluators for statistics awareness and better performance; UDF implementations of these predicates have no impact on spatial join. |
|
Hi @paleolimbot My bad, I was following the reference PR mentioned in the issue description, it didn't seem to include integrated tests on the python side, but I've currently implemented that, I'd love you to give it a look again, For the nitpick suggestions/comments in the rust side, I've resolved them again as well, looking forward to getting a review at your earliest. @jiayuasu and @Kontinuation Thank y'all so much for the kind words! |
Yeah, this is my fault for not mentioning it in the issue, not yours. We added the integration test suite completely after all of the other predicates. Great job on adding them. |
| ("POINT (0 0)", "POINT (0 0)", False), | ||
| ("LINESTRING (0 0, 2 2)", "LINESTRING (1 1, 3 3)", True), | ||
| ("LINESTRING (0 0, 1 1)", "LINESTRING (0 1, 1 0)", False), | ||
| ("LINESTRING (0 0, 1 1)", "LINESTRING (1 1, 2 2)", False), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that we have some good edge cases here like identical geometries ("POINT (0 0)", "POINT (0 0)") and "touching geometries" (i.e. "LINESTRING (0 0, 1 1)", "LINESTRING (1 1, 2 2)")
| [ | ||
| (None, None, None), | ||
| ("POINT (0 0)", None, None), | ||
| (None, "POINT (0 0)", None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| (None, "POINT (0 0)", None), | |
| (None, "POINT (0 0)", None), | |
| ("POINT (0 0)", "POINT EMPTY", False), |
How about we add one more case (empty geometries) while we're here. I checked out the branch and tested these locally, and saw that they already pass.
| [ | ||
| (None, None, None), | ||
| ("POINT (0 0)", None, None), | ||
| (None, "POINT (0 0)", None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| (None, "POINT (0 0)", None), | |
| (None, "POINT (0 0)", None), | |
| ("POINT (0 0)", "POINT EMPTY", False), |
|
@petern48 it's all cool, your issue description and the PR linked was super helpful, gave me enough context to raise a PR, Thank you for that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closes #199