-
Notifications
You must be signed in to change notification settings - Fork 94
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
Borrowed vs. owned geometries #4
Comments
What would be the duplication/harm/opinions in having separate sub-packages? one for native or borrowed. |
You mean, having completely separate types, that share nothing? It would be duplicating the implementation of a bunch of methods (exporting to json/wkt/wkb, testing for overlap/containment/intersection, computing buffer/centroid/hull/area/etc), and not allowing the API user to use them interchangeably, even though in OGR they're actually the same type. |
For now we cannot avoid some package specific types. I think it's OK to keep these types and export them publicly. (Perhaps in a We only need to provide To/From traits and impls to convert them into our geo types for integration. |
Admittedly I don't know too much about the OGR C API, but this approach sounds the most Rust-like |
See also: #360 |
The OGR C API has two ways of accessing geometries:
OGR_F_GetGeometryRef
, and you're not supposed to modify or deallocate it,OGR_G_CreateFromWkt
, and you can modify it, and you're responsible for deallocating; you can also pass ownership back to OGR by attaching it to a feature, usingOGR_F_SetGeometryDirectly
.In both cases, you have a pointer to
OGRGeometryH
. We should support operations on both, e.g. transforming them to JSON or WKT, and it makes sense to share the implementation.A naive approach would be to always copy geometries, and only work with owned geometries from Rust, but that seems wasteful. But I'm probably implementing this initially, to have a working API.
Another option is to create different types for owned and borrowed geometries and share the implementation by a common trait. I've experimented with this in the feature-geometry branch.
A third option is to have an owned geometry type, which wraps a borrowed geometry type, similar to
String
andstr
.@georust/core, any input is much appreciated :)
The text was updated successfully, but these errors were encountered: