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

add union operation for geometry #379

Merged
merged 5 commits into from
Mar 16, 2023
Merged

add union operation for geometry #379

merged 5 commits into from
Mar 16, 2023

Conversation

zredb
Copy link

@zredb zredb commented Mar 10, 2023

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

This is my first time to commit code to this repository. I see that vecotr only has an intersection operation at present, so I try to add a union operation to it. If it can be accepted, I will add other operations in the same way later.

Copy link
Contributor

@metasim metasim left a comment

Choose a reason for hiding this comment

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

@zredb Thank you for the contribution!
Could you please add documentation to union, similar to intersection?

@metasim
Copy link
Contributor

metasim commented Mar 13, 2023

Also, I'm not seeing an update to CHANGES.md.

unsafe {
let ogr_geom = gdal_sys::OGR_G_Union(self.c_geometry(), other.c_geometry());
if ogr_geom.is_null() {
return None;
Copy link
Member

Choose a reason for hiding this comment

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

I haven't tested, but it might be possible to return a proper error here?

But then I'm not sure what we should do in the !has_gdal_ptr() case...

Copy link
Author

Choose a reason for hiding this comment

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

According to gdal's document, when an error occurs, the return value is null, so here we return None, which seems to be consistent with gdal.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but in most cases GDAL will set an error code and message like here, even without documenting it explicitly.

But indeed, this doesn't seem to be done in a consistent fashion.


let inter = inter.unwrap();

assert_eq!(inter.area(), 135.0);
Copy link
Member

Choose a reason for hiding this comment

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

I think we have some assert_almost_eq helper somewhere.

.gitignore Outdated
@@ -8,3 +8,4 @@
GPATH
GTAGS
GRTAGS
/setenv.bat
Copy link
Member

Choose a reason for hiding this comment

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

Do we want this? In the long run every contributor might end up with a script like that, but with a different name.

Copy link
Author

Choose a reason for hiding this comment

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

Setenv is just my own configuration. I have removed it from gitignore.

add change log to CHANGES.md
.gitignore Outdated
@@ -7,4 +7,4 @@
# gtags
GPATH
GTAGS
GRTAGS
GRTAGS
Copy link
Member

Choose a reason for hiding this comment

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

Nit: your IDE is eating final newlines.

///
/// # Returns
/// Some(Geometry) if both Geometries contain pointers
/// None if either geometry is missing the gdal pointer, or there is an error.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// None if either geometry is missing the gdal pointer, or there is an error.
/// None if either geometry is missing the GDAL pointer, or there is an error.

///
/// # Returns
/// Some(Geometry) if both Geometries contain pointers
/// None if either geometry is missing the gdal pointer, or there is an error.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// None if either geometry is missing the gdal pointer, or there is an error.
/// `None` if either geometry is missing the gdal pointer, or there is an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I note that the documentation for intersection isn't that great. The docs in predicates.rs is closer to the mark. Would be great if you can bring it to that level, but if you can't I'll do a separate PR to normalize it.

/// otherwise the result might be wrong.
///
/// # Returns
/// Some(Geometry) if both Geometries contain pointers
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Some(Geometry) if both Geometries contain pointers
/// `Some(geometry)` if both Geometries contain pointers

? 😄

Copy link
Member

@lnicola lnicola left a comment

Choose a reason for hiding this comment

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

If it's not too much of a hassle, would you mind squashing?

@zredb zredb requested a review from metasim March 16, 2023 00:40
@zredb
Copy link
Author

zredb commented Mar 16, 2023

I think I would, but what does "squaring" mean? English is not my first language, so I don't quite understand what "squaring" really means.

@lnicola
Copy link
Member

lnicola commented Mar 16, 2023

Squashing, as in merging the 5 commits into a single one. Something like:

$ git reset @~5 # 5 commits before, or git reset 1dbc60215033caee1f99d933ae11354f70bc5f0e, the last commit before your changes
$ git commit -a
$ git status # make sure everything looks fine
$ git log # make sure everything looks fine
$ git push -f

(these commands reset your branch to the commit before your changes, leave your changes uncommitted in the working directory, then make a new commit with them)

But you don't need to worry about it.

I'll let metasim take another look before merging.

@metasim
Copy link
Contributor

metasim commented Mar 16, 2023

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 16, 2023

@bors bors bot merged commit 7b874de into georust:master Mar 16, 2023
bors bot added a commit that referenced this pull request May 9, 2023
394: Updated `set.rs` docs to be more consistent with those in `predicates.rs`. 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.
---

<img width="974" alt="image" src="https://user-images.githubusercontent.com/131013/236706192-fad8a481-5cc4-476d-9429-eedf66d419b8.png">


Context: #379 (comment)

Co-authored-by: Simeon H.K. Fitch <[email protected]>
@metasim metasim mentioned this pull request May 18, 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 this pull request may close these issues.

3 participants