-
Notifications
You must be signed in to change notification settings - Fork 8
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
Exposing S2 / s2geography options (for boolean predicates / building operations) #70
Comments
@paleolimbot based on your experience with R Or is the |
The relevant R concept is This is kind of a mishmash of overlay construction options, boolean operation options, and a few other things. I'm not sure squishing all of those into the same concept was a great idea because it's not clear exactly which options are relevant to each function. It would probably be a good idea to separate those at the C++ level too in any place where I didn't, but it also doesn't matter as much there. In general, we found exposing all of those options to be totally essential to working around user problems with various corner cases! (Mostly: fixing invalid or weirdly defined geometries). |
s2 in R is also less of a user-facing package and more of a front for sf's mapping of simple features on to s2, which are not the s2 defaults in most cases. So it was more essential that we had all the options exposed so that Edzer could experiment (rather than have a great user experience toying with advanced non-default options). Wrapping all of them up in to one place made it slightly easier to include them everywhere. |
Also, quite a few new boolean operation options since I last looked! https://github.com/google/s2geometry/blob/master/src/s2/s2boolean_operation.h#L281 |
I agree with both :). Global options are useful if we want to make sure those are consistently applied over a whole processing pipeline (e.g., snap). One way to support both in spherely (in a rather pythonic way?) could be to:
We could start with 1 and then implement 2 later. |
On the other hand, most of the options that are in the R
In general I am more a fan of separate keyword arguments (potentially through
Do we think it will be useful to allow setting options globally? For some probably yes (I assume setting a snapping method might be useful to be able to set globally, to avoid having to specify that in every function call). But for example for the output dimension of an operation (i.e. do you want to preserve only the polygonal parts, or only the lines, etc), that depends a lot on the function you call and the input data, and that might be better specified per function. Same for the model (where you might want a different default depending on the operation). Now, we can of course start with only exposing those options globally that we think makes sense. We can probably also start with just exposing a subset of the relevant options as we go to get some experience on what is useful/needed. |
Yes I also generally prefer separate keyword arguments over option classes. I'm not too worried about how to manage a lot of repeated kwargs at the C++ level. Although it will require some work, I'm confident that some helper functions will do the job (maybe also for generating parts of the API docstrings).
Agreed. |
I can see how you might want to do something like: with spherely.s2_options(snap_function=spherely.snap_level(20)):
# ...a bunch of operations where you only care about a certain level of precision
If pyarrow had reasonable autocomplete, this would probably be fine (and a much better experience than
I wonder if you're hitting the limits of what you can accomplish without a Python wrapper layer? |
Since |
The spatial predicates already use those options, but at the moment we only set them under the hood and don't allow to override them by the user. In this case,
s2geography
's functions directly allow you to specify the s2geometryS2BooleanOperation::Options
Those
S2BooleanOperation
options allow you to set the snap function , the polygon/polyline model (open/closed), and a bunch of other things.And for example we implement
covers
by callingcontains
with a "closed" model.The boolean (overlay, i.e. union/intersection/difference) operations I am adding in #62 also have a somewhat similar (super)set of options. In this case,
s2geography
defines aGlobalOptions
options class (which includes theS2BooleanOperation::Options
)Those options allow you, among other things, to specify whether the output should contain points/polylines/polygons (for example, allowing to limit the intersection of polygons to only return the polygonal intersections).
So for both the predicates and the overlays we need a way to allow the spherely user to customize those options.
In the R
s2
package, there is as2_options()
object that gathers all those options (https://r-spatial.github.io/s2/reference/s2_options.html) and that can be passed in those places (https://r-spatial.github.io/s2/reference/s2_contains.html, https://r-spatial.github.io/s2/reference/s2_boundary.html)(the C++ side of this
s2_options()
object: https://github.com/r-spatial/s2/blob/main/src/s2-options.h)The text was updated successfully, but these errors were encountered: