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

FR: Wrapper for OGR_G_Difference #432

Closed
Tracked by #484
nms-scribe opened this issue Aug 31, 2023 · 1 comment · Fixed by #487
Closed
Tracked by #484

FR: Wrapper for OGR_G_Difference #432

nms-scribe opened this issue Aug 31, 2023 · 1 comment · Fixed by #487

Comments

@nms-scribe
Copy link

nms-scribe commented Aug 31, 2023

(Sorry if I'm getting annoying with these feature requests)

I needed to do a 'difference' on two polygon features and realized it wasn't implemented. The following is my helper trait to work around it, but in this case, because of private fields, I couldn't just copy the code in union, so I'm unsure if this is safe. (That's related to #306 )

pub(crate) trait GeometryFix: Sized {
    fn difference(&self, other: &Self) -> Option<Self>;
}

impl GeometryFix for Geometry {
    fn difference(&self, other: &Self) -> Option<Self>  {
        if !self.has_gdal_ptr() {
            return None;
        }
        if !other.has_gdal_ptr() {
            return None;
        }
        unsafe {
            let ogr_geom = gdal_sys::OGR_G_Difference(self.c_geometry(), other.c_geometry());
            if ogr_geom.is_null() {
                return None;
            }
            // TODO: Unfortunately, with_c_geometry is private, so I can't use it.
            let geometry = Self::lazy_feature_geometry();
            geometry.set_c_geometry(ogr_geom);
            // TODO: DANGER!: I can't set owned = true on the thing, there's no way.
            // However, I *think* cloning will take care of that. Because the original
            // value won't dereference the API handle, as it's not owned, but clone
            // will set it to owned.
            Some(geometry.clone())
        }
    }
}
@lnicola
Copy link
Member

lnicola commented Sep 6, 2023

Yup, that's really annoying. I needed to use it recently and I went through WKT instead 😅.

This was referenced Dec 2, 2023
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

Successfully merging a pull request may close this issue.

2 participants