Incorrect @turf/intersect result with polygon holes
@rowanwins is already working on this.
Since Oct 9, 2022.
- Dominant language
- TypeScript
- Stars
- 10.5k
- Forks
- 1k
- Avg merge
- 1h 11m
- Merged PRs (30d)
- 4
Description
@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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.