Skip to content
Advertisement

turf’s mask() function does not run with 10 or more polygons

I can not run the turf.mask() function with more than 9 randomly created points. It just does not return any result.

import { featureCollection, polygon } from '@turf/helpers';
import createCircle from '@turf/circle';
import createMask from '@turf/mask';

const howManyCircles = 9;

const cover = polygon([
    [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]]
],
    { name: 'cover' });
const bbox = [83.16964204361335,83.47466091885153,-83.16964204362385,-83.47466091885192];
const randomPoints = randomPoint(howManyCircles, { bbox: bbox });
const radius = 1000;
const options = { steps: 64, units: 'kilometers', properties: { foo: 'bar' } };
    const circles = randomPoints.features.map(points => {
        return createCircle(points.geometry.coordinates, radius, options);
    });
const mask = createMask(featureCollection(circles), cover);

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

3 People found this is helpful
Advertisement