Turfjs / Turfjs/turf

Incorrect @turf/intersect result with polygon holes

Open
#2,230 2 comments 0 reactions 1 assignee View on GitHub

@rowanwins is already working on this.

Since Oct 9, 2022.

@turf/intersect @turf/mask
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.