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

Updated set.rs docs to be more consistent with those in predicates.rs. #394

Merged
merged 4 commits into from
May 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions src/vector/ops/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ use crate::vector::Geometry;
///
/// These methods provide set operations over two geometries, producing a new geometry.
impl Geometry {
/// Compute intersection.
/// Computes the [geometric intersection][intersection] of `self` and `other`.
///
/// Generates a new geometry which is the region of intersection of
/// the two geometries operated on. Call intersects (Not yet implemented)
/// to check if there is a region of intersection.
/// Geometry validity is not checked. In case you are unsure of the
/// validity of the input geometries, call IsValid() before,
/// otherwise the result might be wrong.
/// Generates a new geometry which is the region of intersection of the two geometries operated on.
///
/// # Notes
/// * If you only need to determine if two geometries intersect and don't require
/// the resultant region, use [`Geometry::intersects`].
/// * Geometry validity is not checked, and invalid geometry will generate unpredictable results.
/// Use [`Geometry::is_valid`] if validity might be in question.
/// * If GEOS is *not* enabled, this function will always return `None`.
/// You may check for GEOS support with [`VersionInfo::has_geos`][has_geos].
metasim marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Returns
/// `Some(geometry)` if both Geometries contain pointers
/// `None` if either geometry is missing the GDAL pointer, or there is an error.
/// * `Some(geometry)`: a new `Geometry` representing the computed intersection
/// * `None`: when the geometries do not intersect or result could not be computed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along with this, frustrated to see the overloading of Option to handle both the empty geometry case as well as the error case. Not sure if we should try to fix this on the Rust side.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the geometries do not intersect

At least GEOS (didn't test with SFCGAL) returns an empty geometry (not NULL) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for testing that!!

///
/// See: [`OGR_G_Intersection`][OGR_G_Intersection]
///
/// See: [`OGR_G_Intersection`](https://gdal.org/api/vector_c_api.html#_CPPv418OGR_G_Intersection12OGRGeometryH12OGRGeometryH)
/// [OGR_G_Intersection]: https://gdal.org/api/vector_c_api.html#_CPPv418OGR_G_Intersection12OGRGeometryH12OGRGeometryH
/// [intersection]: https://en.wikipedia.org/wiki/Intersection_(geometry)
/// [has_geos]: crate::version::VersionInfo::has_geos
pub fn intersection(&self, other: &Self) -> Option<Self> {
if !self.has_gdal_ptr() {
return None;
Expand All @@ -33,19 +40,25 @@ impl Geometry {
Some(unsafe { Geometry::with_c_geometry(ogr_geom, true) })
}

/// Compute union.
/// Computes the [geometric union][union] of `self` and `other`.
///
/// Generates a new geometry which is the region of union of
/// the two geometries operated on.
/// Geometry validity is not checked. In case you are unsure of the
/// validity of the input geometries, call IsValid() before,
/// otherwise the result might be wrong.
/// Generates a new geometry which is the union of the two geometries operated on.
///
/// # Notes
/// * Geometry validity is not checked, and invalid geometry will generate unpredictable results.
/// Use [`Geometry::is_valid`] if validity might be in question.
/// * If GEOS is *not* enabled, this function will always return `None`.
/// You may check for GEOS support with [`VersionInfo::has_geos`][has_geos].
metasim marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Returns
/// `Some(geometry)` if both Geometries contain pointers.
/// `None` if either geometry is missing the GDAL pointer, or there is an error.
/// * `Some(geometry)`: a new `Geometry` representing the computed union
/// * `None`: when the union was not able to be computed
Copy link
Contributor Author

@metasim metasim May 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really frustrated by this, as the C/C++ docs say:

a new geometry representing the union or NULL if an error occurs.

which would imply to me that we should be returning Result<Geometry, GDALError>, except I'm not finding any evidence that an error message is ever posted.

Copy link
Member

@lnicola lnicola May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a moot point. I suspect it's impossible to get a GEOS-less GDAL unless you're compiling it yourself, but then not everyone might know that GEOS is important to have when you're using vector data.

Also, I wonder if we should mention SFCGAL, which is required for some geometry types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

metasim marked this conversation as resolved.
Show resolved Hide resolved
///
/// See: [`OGR_G_Union`][OGR_G_Union]
///
/// See: [`OGR_G_Union`](https://gdal.org/api/vector_c_api.html#_CPPv419OGR_G_UnionCascaded12OGRGeometryH)
/// [OGR_G_Union]: https://gdal.org/api/vector_c_api.html#_CPPv411OGR_G_Union12OGRGeometryH12OGRGeometryH
/// [union]: https://en.wikipedia.org/wiki/Constructive_solid_geometry#Workings
/// [has_geos]: crate::version::VersionInfo::has_geos
pub fn union(&self, other: &Self) -> Option<Self> {
if !self.has_gdal_ptr() {
return None;
Expand Down