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
Add GEOSPrepared<PRED>XY functions to C API #677
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.
Looks A-OK to me.
Do the following make sense?
|
GEOSPreparedCoveredByXY feels a little pointless (ha ha ha) but perhaps in a completionist sense, might as well do it? It is possible to have both true and false results from it I guess. |
Is it a synonym for |
Disregard, I think I'm confused by the wording of our docstrings. Lines 4299 to 4309 in c68119c
We are testing if the prepared geometry is covered by the provided geometry, but the text implies (to me) the reverse. So I should add GEOSPreparedCoversXY, not GEOSPreparedCoveredByXY. And it is probably misleading to add GEOSPreparedTouchesXY, since it just defaults to the underlying |
Is this not actually all achievable (performance-wise) by going:
|
There's an assumption that you stop touching the coordinate sequence once you use it to create a geometry. (We should document this!) There are at least two reasons for this:
|
In that case does the existence of a CAPI GEOSPoint_setXY() abrogate the need for the multiple GEOSPrepared*XY() signatures? |
It would meet the same need with fewer signatures. I think it's a bit less discoverable, though. |
Another take on the signatures is: is there any substantial use for anything other than PreparedIntersectsXY? (if we want discoverability... all other use cases could be handled with Point_setXY). Or we could just add an example of using Point_setXY() to the examples fleet. At this point I'm just flailing. What does your spidey sense tell you? |
|
More to test, maintain and document. |
There is a Usually I'm not crazy about mutating geometries, but this seems like one case where it's justified. |
Yes, though keep in mind we're talking about five two-line functions. |
Because of the much more limited semantics of Point relationships I suggest the following functions:
Disjoint is just Touches can be determined by |
I removed |
5c7b590
to
b52b389
Compare
This is a nice addition! (working on exposing this in shapely) I am wondering one thing: since this is restricted to checking against a Point, can there ever be a difference between Contains and ContainsProperly? Contains allows common points on the boundary but requires at least one point in the interior, while ContainsProperly disallows common boundary points (only intersecting the interior). |
Great point (so to speak). You are right, there is no difference between Contains and ContainsProperly for single points. I suggest the |
This PR adds a function
GEOSPreparedXY
to the C API to allow point-in-polygon tests without the overhead of point construction. The significance of this overhead depends on the data. When checking many points against a complex boundary, this PR makes almost no difference:With smaller polygons, it makes a measurable improvement (about 20%)
The C++ code surrounding prepared geometries is relatively complex, so rather than modify it to thread a
Coordinate
object through, I modified the C APIGEOSContextHandle
to hold a mutablePoint
object.The existing API for modifying a
Point
is rather complex and slow. This is the best I could do:So I added a
Point::setXY
method to make this easier and faster.If there is general support for this approach, I can document the new function and add
XY
variants in other cases where they would be useful (GEOSPreparedIntersectsXY
, etc.)