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

feat: implement Validify repair trait #1120

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

RobWalt
Copy link
Contributor

@RobWalt RobWalt commented Nov 21, 2023

Description

While discouraging the handling of invalid geometries and prioritizing the maintenance of geometric validity as a fundamental principle, it is recognized that geometries may occasionally deviate from perfection. In such instances, we have to deal with checking the geometry and repairing it all on our own. That's why it's time for a trait in geo which does the job for us.

This pull request introduces a new feature by implementing the Validify for the first two candidates: Self intersecting Polygons and MultiPolygons. The Validity trait serves to repair these invalid geometries by splitting them up into smaller polygons which fulfill the implicit invariants.

Changes Made

  • Implemented the Validify trait
  • Add split_into_valid method on the trait and implement it for Polygon and MultiPolygon
  • Also handles splitting up banana polygons 🍌

Usage Example

use geo::Validify;

// Assuming `your_geometry` is an instance of a self intersecting `Polygon`
let valid_multi_polygon = your_geometry.split_into_valid();

Testing

  • Added a few unit tests to ensure the correct behavior of the Validify trait and methods used for the first impls

Documentation

  • Document everything about the Validify trait quiet heavily for the afterworld

  • 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.

  • Usage examples in trait docs

@RobWalt RobWalt self-assigned this Nov 21, 2023
@RobWalt RobWalt changed the title feat: implement Validity repair trait feat: implement Validify repair trait Nov 21, 2023
@urschrei
Copy link
Member

Very nice. Also worth having a look at https://github.com/tudelft3d/prepair (cc @hugoledoux) which uses a constrained triangulation approach for further inspiration if you're interested…

@RobWalt
Copy link
Contributor Author

RobWalt commented Nov 22, 2023

Lol that sounds a lot like what I did with SpadeBoolops. Now I wonder if I could just do a single polygon union to achieve the same 😅

Thanks a lot for the link! That's super useful!!

@hugoledoux
Copy link

Watch out: the machinery used to achieve what we did is CGAL, which allows us to use a robust constrained Delaunay triangulation where we can intersect constraints and attach attributes to edges and triangles, and etc etc.

A standard triangulation doesn't allow you to do this, although if https://github.com/Stoeoef/spade is used it would be a good basis (I think, I haven't thoroughly tested it).

Since you have GEOS in rust, perhaps it's simpler to translate the algo of ST_MakeValid (no docs AFAIK, the code is the ultimate docs here...).

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.

None yet

3 participants