Turfjs / Turfjs/turf

turf.intersect(poly1, poly2) crashes with an OOME

Open
#2,833 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

polyclip-ts
Dominant language
TypeScript
Stars
10.5k
Forks
1k
Avg merge
1h 11m
Merged PRs (30d)
4

Description

Running this code on v7.2.0 hangs and eventually ends in a OOME

import * as turf from '@turf/turf';
const poly1coords = [
  [-2.232359, 53.349714],
  [-2.23244, 53.349848],
  [-2.232526, 53.349986],
  [-2.23262, 53.350125],
  [-2.232699, 53.350257],
  [-2.232757, 53.350349],
  [-2.232762, 53.350357],
  [-2.232771, 53.350365],
  [-2.232777, 53.350369],
  [-2.232784, 53.350372],
  [-2.23279, 53.350374],
  [-2.232837, 53.350365],
  [-2.232833, 53.35036],
  [-2.232802, 53.350318],
  [-2.232359, 53.349714],
];
const poly2coords = [
  [-2.232359, 53.349714],
  [-2.23244, 53.349848],
  [-2.232526, 53.349986],
  [-2.23262, 53.350125],
  [-2.232699, 53.350257],
  [-2.232757, 53.350349],
  [-2.232762, 53.350357],
  [-2.232771, 53.350365],
  [-2.232777, 53.350369],
  [-2.232784, 53.350372],
  [-2.23279, 53.350374],
  [-2.232834, 53.350366],
  [-2.23283, 53.350359],
  [-2.232808, 53.350326],
  [-2.23281, 53.350329],
  [-2.232802, 53.350318],
  [-2.232359, 53.349714],
];

const poly1 = turf.polygon([poly1coords]);
const poly2 = turf.polygon([poly2coords]);

const intersection = turf.intersect(turf.featureCollection([poly1, poly2]));

The polygons are thin strips of land, almost entirely overlapping apart from the top-left corner:

Image

I've tried running this in different environments (in a Node app, on a browser) and it hits the same error

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.

Research direction

Start by reproducing the provided polygon example with @turf/turf v7.2.0 and trace the turf.intersect entry point. Investigate why these nearly overlapping thin polygons cause an out-of-memory error; done means the example terminates without an OOME and returns the correct intersection.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.