-
Notifications
You must be signed in to change notification settings - Fork 48
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 customizable invalid geometry handling #46
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d1aaa2d
Add customizable invalid geometry handling
rmarianski 9660d52
Exception -> ValueError
rmarianski 6a1e8e0
Add validity assertion after buffer(0)
rmarianski 4e356b6
Add test for bowtie geometry
rmarianski 29e307c
Validate geometries repeatedly
rmarianski 3e7e4f2
Update deprecated unittest functions
rmarianski 6461920
Use shapely ops transform instead of custom
rmarianski 24ab05b
Use rounding consistent with python 3
rmarianski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to
assert shape.is_valid
after this, just to make sure that we are actually making the shape valid. Alternatively, we could chain some of these together, e.g:make_valid.andThen(ignore)
or something like that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an assertion in 6a1e8e0. A geometry validity monad could be an exercise for the reader 😜
Reading the shapely docs on buffer(0) (search for bowtie), it looks like it may generate a MultiPolygon to make the geometry valid. Could this affect the winding order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I had to guess, I'd assume that it would preserve the winding order... But it's entirely possible that it doesn't, or resets it to the more usual clockwise. It probably doesn't stick to integer coordinates either. We should probably be taking the output and re-quantizing it, orienting it and re-checking its validity. 🙀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it does seem to preserve the winding order. I added a test for that behavior in 4e356b6.
It's also true that the values became floating point after the
buffer
. We doround
them again, but like you hinted at, I suppose it is possible for this to alter the winding order again.Would we need to re-quantize though? I would assume that we would just need to do the rest of the chain, namely round, ensure the correct winding order, and then handle invalid geometries again. And maybe we try this 5 times or so before dropping the feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, by "quantize" I meant "round" - that the
buffer(0)
process might introduce new points at non-integer coordinates.I think we might also need to recurse into
MULTI*
types - it's possible that only one part of a multi-geometry is invalid and we wouldn't want to drop the whole thing. Yikes, this is getting complicated.