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
CAPI for coverage operations #866
Conversation
What motivates the creation of a new |
I want to give the users the freedom to assemble the input and disassemble the output without having to make copies. I might have been over-worried about that, but the semantics of GeometryCollection, particularly in the CAPI I think might force more copying than ideal. |
Creating a non-owning Geometry collection might be a trickier implementation but I think it is a cleaner API. There are lots of operations we might want to do on a list of geometries (union, buffer, cluster, extent, distance, etc.) that might similarly benefit from avoiding the copy. |
Ironically (?) for PostGIS I think the owning GeometryCollection would be fine, since we're building copies anyways on both the way in and the way out of GEOS. |
Another semantic that some coverage operations use is to support null elements in the list. This is used in the CoverageValidator to indicate that an input coverage element is valid. |
I can see the appeal of a non-owning GeometryCollection. But it seems more likely to lead to errors by confused clients that forget to free the elements. |
This doesn't strike me as an ideal API or a compelling reason to add a new collection type.
I'm not sure why this seems likely (or less clear than a |
I'm entirely open to other approaches. We do need some way to signal null members of the list, for the output from CoverageValidator. We did talk about a much more at the metal approach, passing out and in **Geometry and a list size separately. |
I don't know if this is ideal. I think it is more explicit than "return NULL if no error" and more quickly answers the question "is the entire coverage valid?"
|
GeometryList elements are always owned by the client. Whereas if two kinds of GeometryCollection is provided, the client has to check which kind it is dealing with. Granted it may know from context, but it's less apparent to someone reading the code IMO. |
For the proposed structure What would be the API for other one-to-one coverage operations? (Currently: |
In this implementation the ownership is flexible and is made explicit only at destruction time (did we use
I am proposing a
In the signature above ownership is given to whoever calls
These strike me as simpler and being able to use a |
There is no need for |
I would expect |
The point is that a
Agreed, and it sounds like in the PostGIS case at least (and perhaps most other bindings) the input data is copied anyway. A |
So it would record if |
In fact |
I was envisioning that
unless there is a performance reason to have |
I'm not super sold on a new And in terms of avoiding new structs in the API, there is also the possibility of passing/receiving a **Geometry and a size_t on the input and output of each coverage operation. This would have the "advantage" of being super-explicit about memory management, since we'd just be laying all the sharp knives out on the table and saying "have at 'er!". |
I don't mean to advocate for avoiding new structs in the API. I think a special-purpose struct can bring a lot of clarity. My hesitation with |
As a downstream user this does indeed seem like the simplest approach, even though I'm not excited about the proliferation of EMPTY for this specific use case. I think it also may be a common pattern that if validation returns false that we may stop altogether rather than visiting and then freeing each validation error. Provided I'm following along correctly, my instinct is that GeometryCollection seems like the better container than the new GeometryList. Could the owning / non-owning GeometryCollection be deferred until later, or does it need to be worked out to move forward on this particular PR? Since that has a wider reach in the API, it seems like that may need separate discussion. For the coverage functions here, the inputs could be owning or non-owning GeometryCollections; it is up to the caller to free them correctly. Since the output of
It really seems like the caller should take a pretty strict approach to this, because the complexity probably should be on their side. Either have an entirely non-owning collection and free things individually, or an owning collection and free just that; mixing those two approaches seems like asking for trouble. So long as outputs of C API functions are entirely new and not some mix of passed in non-owned geometries and newly constructed geometries, then it is entirely up to the user to keep track of ownership.
This seems reasonable to me, and the implication is that if I call this, I'm on my own for managing the ownership of any geometries within it. |
What do we think of #867? |
Here is a PR showing a GeometryCollection approach to the API.
#867
P.
… On Apr 12, 2023, at 10:14 AM, Brendan Ward ***@***.***> wrote:
If the goal is simplicity, I'd tend to go for consuming/emitting GeometryCollection in all cases, and just fill in the valid slots of a validation with EMPTY, and add in a signature for a global true/false validation function.
As a downstream user this does indeed seem like the simplest approach, even though I'm not excited about the proliferation of EMPTY for this specific use case. I think it also may be a common pattern that if validation returns false that we may stop altogether rather than visiting and then freeing each validation error.
Provided I'm following along correctly, my instinct is that GeometryCollection seems like the better container than the new GeometryList.
Could the owning / non-owning GeometryCollection be deferred until later, or does it need to be worked out to move forward on this particular PR? Since that has a wider reach in the API, it seems like that may need separate discussion. For the coverage functions here, the inputs could be owning or non-owning GeometryCollections; it is up to the caller to free them correctly.
Since the output of GEOSCoverage_valid and GEOSCoverage_simplify both return new objects, I'd expect those to be owning GeometryCollections, and I'd expect to free them at the collection rather than individual level.
to support more complex usage patterns there should be a way for a client to tell if a geometry requires element-freeing or not
It really seems like the caller should take a pretty strict approach to this, because the complexity probably should be on their side. Either have an entirely non-owning collection and free things individually, or an owning collection and free just that; mixing those two approaches seems like asking for trouble. So long as outputs of C API functions are entirely new and not some mix of passed in non-owned geometries and newly constructed geometries, then it is entirely up to the user to keep track of ownership.
GEOSGeom_createCollectionView
This seems reasonable to me, and the implication is that if I call this, I'm on my own for managing the ownership of any geometries within it.
—
Reply to this email directly, view it on GitHub <#866 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAA3ZW5LJURYPLERLXJVGTLXA3PGDANCNFSM6AAAAAAW25Q6YU>.
You are receiving this because you authored the thread.
|
The key difference to existing uses of Some coverage operations (such as validation) may produce an empty result for some inputs, so the result structure needs to be able to express that. My original thinking was that the simplest and lightest way to do this was to return |
Another thing that makes me uneasy about a non-owning GeometryCollection is that result values with non-owning semantics will not be explicit in the API. The only way to indicate this will be via documentation (which is unreliable and tends to be overlooked). I suppose one way to mitigate this is to provide some kind of check in the I guess it could also be a policy to never return a non-owning collection. This still might cause 3rd-party code to be susceptible to mistakes, however. Having a distinct non-owning type (such as As for the desire to run geometry functions on the contents of a |
We have the capability to "releaseGeometries" in the C++ API, and this might be a nice bridge to allow end users to decompose returned GeometryCollections if they need to if we added it to the CAPI. The only overhead then would be the creation and disposal of a containing GeometryCollection. |
Sounds good to me. |
Active work is on #867. |
No description provided.