Skip to content
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

Provide an API to create a Geometry object from an owned OGRGeometryH #306

Open
thomas001 opened this issue Sep 4, 2022 · 4 comments
Open

Comments

@thomas001
Copy link

Currently not all of the C Geometry API is wrapped, so users will need to go to gdal-sys and raw unsafe C calls from time to time. This is fine, wrapping all of GDAL is a huge undertaking. So right now I have code like this:

let p = gdal_sys::OGR_G_MakeValid(geom.c_geometry());
let v = Geometry::lazy_feature_geometry();
v.set_c_geometry(p);
v

As you can see creating a Geometry back from the raw C pointer is cumbersome and it leaks memory since v doesn't own the C geometry. I am asking for a function like Geometry::from_owned_c_geometry which will own the passed C object. So the above code could become

unsafe { 
  Geometry::from_owned_c_geometry(gdal_sys::OGR_G_MakeValid(geom.c_geometry()))
}

Please consider implementing it in public API. There seems to be a crate local function that almost does this, so maybe just change it to public .

@metasim
Copy link
Contributor

metasim commented Sep 4, 2022

@thomas001 Is OGR_G_MakeValid just one of many calls you're wanting to make, or would the more convenient approach be to add something like Geometry::make_valid instead?

In the future, I wonder if we would we regret letting an internal hack leak out (to never be put back in the box), and wish we'd just go ahead and implement the desired functionality? Not sure what the scope is of what you need, but feel like it's worth asking the question.

@thomas001
Copy link
Author

@metasim Okay here is my brain dump on this topic, sorry if it is a bit unstructured.

There are a few functions that I missed, MakeValid is one of them, but also some set operation (Union, Difference, ...) or things like Polygonize seem to be not wrapped.

Yes, implementing the missing functions would be one way to go forward here (for a simple case like MakeValid I could also send a PR).

The more general question is: if you agree that not all functionality of GDAL is wrapped in this crate, should we offer users at least a supported way to go back and forth with gdal-sys which is more of a complete (since generated) wrapper?

Finally, I think there are some hackish functions already out there. There is at least set_c_geometry which is just not taking ownership of the C geometry.

So maybe two possible directions:

  • C interop is supported and common, then my ask seems valid
  • C interop is considered a hack and users should only interact using safe rust API, then
    • missing functions should be added (i am willing so send PR since I use this crate quite a bit)
    • maybe: unsafe functions should be deprecated
    • but: it might becomea cat&mouse game with upstream GDAL development to keep every user happy

bors bot added a commit that referenced this issue Jan 10, 2023
356: Implements `Geometry::make_valid`. r=metasim a=metasim

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/gdal/blob/master/CODE_OF_CONDUCT.md).
- [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

Partially addresses #306.

cc: `@thomas001`

Co-authored-by: Simeon H.K. Fitch <fitch@astraea.io>
@lnicola
Copy link
Member

lnicola commented Feb 10, 2023

I think we should wrap more of the GDAL methods, but also offer a good interop story. Unfortunately, I'm not convinced that the current API is a good one, cf. #365.

bors bot added a commit that referenced this issue Feb 10, 2023
366: Exposed spatial predicates over `Geometry` r=metasim a=metasim

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/gdal/blob/master/CODE_OF_CONDUCT.md).
- [X] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

Partially addresses #306 

cc: `@thomas001`

Co-authored-by: Simeon H.K. Fitch <fitch@astraea.io>
bors bot added a commit that referenced this issue Feb 10, 2023
366: Exposed spatial predicates over `Geometry` r=metasim a=metasim

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/gdal/blob/master/CODE_OF_CONDUCT.md).
- [X] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

Partially addresses #306 

cc: `@thomas001`

Co-authored-by: Simeon H.K. Fitch <fitch@astraea.io>
@metasim
Copy link
Contributor

metasim commented May 16, 2023

See also: #360

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants