Search code examples
javascripttypescriptturfjs

TURF booleanwithin is not working as expected


im currently trying to validate that a polygon is completely within another polygon. But there is a use case for more complicated polygons where it should return false but turf understand it as a valid one.

Here is the sandbox.

https://codesandbox.io/embed/adoring-lamarr-6mi8wv?fontsize=14&hidenavigation=1&theme=dark

And here are the polygons. https://gist.github.com/tomascenteno42/107c19531ebbcf8f8106c27282bf3891

Thanks (:


Solution

  • The problem is that, currently, booleanWithin only handles a very limited case of testing convex polygons. That's because it only checks if the vertices of the 1st polygon are within the 2nd polygon.

    This might not be get fixed before v7.

    For now you might consider to use de9im library.

    It's from turf's issue page.