-
Notifications
You must be signed in to change notification settings - Fork 365
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 clustering functions to C API #1154
base: main
Are you sure you want to change the base?
Conversation
A suggestion for naming of a couple of the methods, with clarifying comments:
|
Rather than adding another type to the API, perhaps a function similar to That has the downside that all clusters have to be materialized at once, rather than individually. But perhaps this is fine for the anticipated use cases? |
I'm OK with either approach, but I think the extra functionality of the added object is pretty good, and it's supporting 4 different functions, so it's not like it's an extra "junk object" or something. |
Thanks for the feedback. I've implemented a new version with the custom type, but I don't want to rush it out before Friday. I'm OK leaving this until 3.14. |
There is at least one other non-clustering algorithm that could benefit from this approach - Given this, is it worth renaming the API so that it's more general than just clustering? The term
Or, LineMerge can be though of as a kind of clustering, so an alternative design choice is to use this API and name the GEOS C API function appropriately (say |
Since we wouldn't want to change the existing signatures of |
4c3109e
to
a26df82
Compare
extern size_t GEOS_DLL* GEOSClusterInfo_getClustersForInputs_r(GEOSContextHandle_t, const GEOSClusterInfo* clusters); | ||
|
||
/** \see GEOSClusterInfo_getInputsForClusterN */ | ||
extern const size_t GEOS_DLL* GEOSClusterInfo_getInputsForClusterN_r(GEOSContextHandle_t, const GEOSClusterInfo* clusters, size_t i); |
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.
Note that we are returning const size_t*
here. This avoids a memory allocation and array copy for each cluster, but constrains our implementation of GEOSClusterInfo
to actually store these values in a contiguous block somewhere. I think that's a reasonable tradeoff.
a26df82
to
1a0d072
Compare
This PR resurrects the C API that was removed from #688 and changes it to return an array of cluster IDs instead of a GeometryCollection, as suggested in #823.
This is clearly a more flexible API than the one implemented in e464b79, but it becomes somewhat awkward to construct geometries representing the clusters (see function
construct_clusters
in the test suite).I am a bit averse to adding new types to the C API, but I am wondering if something like the following would be an improvement.