Skip to content

Incorrect @turf/intersect result with polygon holes #2230

@TractsCTO

Description

@TractsCTO

@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:

import {polygon} from '@turf/helpers';
import turfMask from '@turf/mask';
import turfIntersect from '@turf/intersect';

// coordinates of a 16 x 16 square:
const square = [[[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:
const withHole = [[[0,0],[16,0],[16,16],[0,16],[0,0]],[[6,6],[6,10],[10,10],[10,6],[6,6]]];
const pSquare = polygon(square); // the square polygon
const pWithHole = polygon(withHole); // the square with hole polygon
const mask = turfMask(pWithHole); // the mask (inverse) of the square with hole
// the intersection of the mask with the square:
const result= turfIntersect(mask, pSquare); // result is null, should be a 4 x 4 square

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions