You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Intersect does not produce a correct result when a polygon contains a hole, that hole contains an island, and the polygon to be intersected intersects that island. The part intersecting the island is ignored in the output.
As a simple example, here we create a large square with a small square hole in the middle, and use turf mask to invert it, then intersect that resulting mask with another large square of the same dimensions but without the hole. In this example, result is null, when in fact it should be a polygon with the same dimensions as the small square:
import{polygon}from'@turf/helpers';importturfMaskfrom'@turf/mask';importturfIntersectfrom'@turf/intersect';// coordinates of a 16 x 16 square:constsquare=[[[0,16],[0,0],[16,0],[16,16],[0,16]]];// coordinates of the same square, but with a 4 x 4 hole in the middle:constwithHole=[[[0,0],[16,0],[16,16],[0,16],[0,0]],[[6,6],[6,10],[10,10],[10,6],[6,6]]];constpSquare=polygon(square);// the square polygonconstpWithHole=polygon(withHole);// the square with hole polygonconstmask=turfMask(pWithHole);// the mask (inverse) of the square with hole// the intersection of the mask with the square:constresult=turfIntersect(mask,pSquare);// result is null, should be a 4 x 4 square
The text was updated successfully, but these errors were encountered:
I think that this fails at a different stage. turf-mask doesn't care about inverting the inner rings of its input, so the geometry for mask in this example is just a world geom minus the square geometry.
I think, as far as I can tell, that the bug is that turf-mask should return a MultiPolygon in this case, which would allow the "inverted" geometry to have an island:
And that then works properly with turf-intersect.
This hinges on whether turf-mask is really expected to "invert" features, or whether it's just masking the outer ring. I don't have a preference or leaning there.
I've added a PR #2346 that adds support for holes to @turf/mask, I've left default behaviour the same but there is now an optional argument so that it can be over-ridden in cases like these.
@turf/intersect version: 6.5.0
@turf/mask version: 6.5.0
@turf/helpers version: 6.5.0
Intersect does not produce a correct result when a polygon contains a hole, that hole contains an island, and the polygon to be intersected intersects that island. The part intersecting the island is ignored in the output.
As a simple example, here we create a large square with a small square hole in the middle, and use turf mask to invert it, then intersect that resulting mask with another large square of the same dimensions but without the hole. In this example, result is null, when in fact it should be a polygon with the same dimensions as the small square:
The text was updated successfully, but these errors were encountered: