I can not run the turf.mask()
function with more than 9 randomly created points. It just does not return any result.
JavaScript
x
19
19
1
import { featureCollection, polygon } from '@turf/helpers';
2
import createCircle from '@turf/circle';
3
import createMask from '@turf/mask';
4
5
const howManyCircles = 9;
6
7
const cover = polygon([
8
[[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]]
9
],
10
{ name: 'cover' });
11
const bbox = [83.16964204361335,83.47466091885153,-83.16964204362385,-83.47466091885192];
12
const randomPoints = randomPoint(howManyCircles, { bbox: bbox });
13
const radius = 1000;
14
const options = { steps: 64, units: 'kilometers', properties: { foo: 'bar' } };
15
const circles = randomPoints.features.map(points => {
16
return createCircle(points.geometry.coordinates, radius, options);
17
});
18
const mask = createMask(featureCollection(circles), cover);
19
This works as expected. There are nine holes (created through the randomPoints()
function) in the polygon.
However, as soon as I change howManyCircles
to a number greater than 9
, I do not get any result. It calculates and calculates but does not come to an end. Here is a fiddle to play around with: https://jsfiddle.net/6m3qsnu1/
Why is that?
“@turf/helpers”: “^6.3.0”, “@turf/random”: “^6.3.0”, “@turf/turf”: “^6.3.0”,
Advertisement
Answer
Apparently this is a known bug and got fixed in v7
. However, yarn add @turf/turf
or npm i @turf/turf
installs turf 6.3.0
. In order to install the most recent version use npm i turf@7.0.0-alpha.1