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

@turf/kinks returns false self-intersections in MultiLineString features with branches #2756

Open
ovdleondle opened this issue Nov 29, 2024 · 4 comments

Comments

@ovdleondle
Copy link

turf 7.1.0

When a MultiLineString feature has branches (e.g. a river with tributaries, or a street with side streets), kinks module returns self-intersection at the branching point.
For this geojson feature:
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"MultiLineString","coordinates":[[[0,0],[0,1],[0,2]],[[0,1],[1,1]]]}}]}
kinks
kinks would return a self-intersection at 0,1 coordinates, which is false.

@smallsaucepan
Copy link
Member

Thanks for reporting this @ovdleondle.

Could it possibly be related to #2722? Would you mind checking to see if the behaviour is correct for v6.5.0?

@pm0u
Copy link
Contributor

pm0u commented Dec 17, 2024

this appears to be unrelated to #2722:

  • this module actually uses its own line-intersect algorithm
  • this module, per its description in jsdoc, is intended to report only self intersections

i am not sure that this qualifies as a bug per the documentation within turf but i could be missing some context for what would be expected of a module by this name. this case seems to be behaving as expected just by appearance

@smallsaucepan
Copy link
Member

Thanks for ruling that out @pm0u. Will take a closer look at this one in due course then.

@ovdleondle
Copy link
Author

@smallsaucepan I confirm that this behavior is not related to #2722, as the same issue occurs in version 6.5.0.

After reviewing the kinks documentation, I also agree with @pm0u that the module is technically functioning as intended.

Our goal was to use the kinks module as a geometry validator on the client side. However, geometry validity is a nuanced concept, as described in the PostGIS introduction:

Validity is most important for polygons, which define bounded areas and require a good deal of structure. Lines are very simple and cannot be invalid, nor can points.
Some of the rules of polygon validity feel obvious, and others feel arbitrary (and in fact, are arbitrary).

Additionally, geometry validation in PostGIS evaluates whether a geometry is simple and whether it is valid:

A simple geometry is one that has no anomalous geometric points, such as self intersection or self tangency.

A MULTILINESTRING is simple only if all of its elements are simple and the only intersection between any two elements occurs at points that are on the boundaries of both elements.

Geometry validity primarily applies to 2-dimensional geometries (POLYGONs and MULTIPOLYGONs) .

For linear geometry the only validity rule is that LINESTRINGs must have at least two points and have non-zero length (or equivalently, have at least two distinct points.) Note that non-simple (self-intersecting) lines are valid.

To summarize, we plan to use the kinks module exclusively for polygon and multipolygon features. For lines, we will try using lineIntersect with ignoreSelfIntersections: false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants