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

is_valid for all geometry types. #1130

Open
andriyDev opened this issue Dec 29, 2023 · 3 comments
Open

is_valid for all geometry types. #1130

andriyDev opened this issue Dec 29, 2023 · 3 comments

Comments

@andriyDev
Copy link
Contributor

As stated in the description of the geometry types (e.g., Polygon, LineString), validity is not enforced, but it is expected. While the validity requirements are clearly documented, there is no "canonical" way to check if your geometry adheres to the validity requirements.

An example of when this would be desirable is loading polygons from a file. There is no guarantee that the file contained valid geometry, but once we check this, the algorithms should produce valid polygons.

Therefore, if checking validity is expensive, that is ok, since this should be a one-time cost.

Ideally this is supported by each geometry type separately, and also on Geometry.

@andriyDev
Copy link
Contributor Author

For LineString, its requirements are either empty, or 2+ coordinates. This is trivial to check. In addition, if the LineString is closed, it must also not self-intersect. We can check this by using Intersections (inserting all the edges in the line string) and checking that all intersections are vertices of the original line string (it's not clear to me if a line string is allowed to use the same vertex twice, but if it's not then I think we can just check if there are any intersections).

@mthh
Copy link
Member

mthh commented Dec 29, 2023

Some time ago I tried to implement various validity checks for geo-types geometries : https://github.com/mthh/geo-validity-check

I think it implements most of the validity checks of GEOS as well as some other checks.

The non-validity diagnostic messages could greatly be improved, and there is no functionality to attempt to repair the geometries.
Anyway, if that would be useful, feel free to reuse code from this crate to implement an is_valid function directly in geo.

@dabreegster
Copy link
Contributor

Somewhat related to #1120

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

No branches or pull requests

3 participants