4

I have mapbox map with ~2000 points and I have voronoi polygons drawn around them vith turf.js, how can set boundaries around country so polygon don't stretch all over the world? I just want to mask/trim them and keep polygons around country borders.

What I already tried is using turf.js mask feature (https://turfjs.org/docs/#mask) but I lose all layers (there are no polygons/points anymore).

Here is my code on JSFiddle:
https://jsfiddle.net/eqxdjv6z/
Dominik
  • 121
  • 9

2 Answers2

1

Loop through each Border of each Voronoi cell and check if it crosses the outer shell. If so, set the Intersection as a new edge of the Voronoi cell and delete all edges that are outside the meshing area.

Maybe this helps you, as well: https://discourse.mcneel.com/t/trim-voronoi-cell/78408

Pixel_95
  • 954
  • 2
  • 9
  • 21
1

I see this has been answered, but I had the same issue and I believe there is a cleaner solution. You can simply use the turf/intersect function to clip the voronoi cells to another geometry. No manual border checking or anything.

Sam
  • 300
  • 3
  • 10