Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript
https://turfjs.org/
MIT License
9.35k stars 941 forks source link

Apparent clipCells function issue in Voronoi #2303

Open nuno-sequeira opened 2 years ago

nuno-sequeira commented 2 years ago

I am using turf voronoi on roughly 15000 points. I define a bounding box previously to voronoi creation and then I get the following error:

\node_modules\d3-voronoi\build\d3-voronoi.js:496
        end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
                                                                            ^
TypeError: Cannot read properties of null (reading '0')
    at clipCells (\node_modules\d3-voronoi\build\d3-voronoi.js:496:77)
    at new Diagram (\node_modules\d3-voronoi\build\d3-voronoi.js:863:5)
    at voronoi (\node_modules\d3-voronoi\build\d3-voronoi.js:956:12)
    at Function.voronoi.polygons (\node_modules\d3-voronoi\build\d3-voronoi.js:965:12)
    at Module.voronoi (file:///node_modules/@turf/voronoi/dist/es/index.js:61:8)

The relevant code is:

this.voronoiData = turf.featureCollection(sepCells.map((e: { coords: number[]; id: string }) => turf.feature(turf.geometry("Point", e.coords), { cellName: e.id })));
var poly = turf.bboxPolygon([-9, 50, 1, 62]);
const bbox = turf.bbox(turf.geometry("Polygon", poly.geometry.coordinates));
let voronoiPolygons = turf.voronoi(this.voronoiData, {bbox: bbox});

I tried to use a smaller set (10 points) and it works.

EDIT: I have now noticed that the problem only arises on data with points closer than a meter. Shouldn't this be supported?

JamesLMilner commented 2 years ago

Hey, thanks for raising. I appreciate this might be tedious, but are you able to provide the smallest set of points that exhibit this behaviour with us as a GeoJSON FeatureCollection?