Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mask/trim voronoi polygons around country?

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/
like image 803
Dominik Avatar asked Sep 02 '25 09:09

Dominik


1 Answers

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

like image 157
Pixel_95 Avatar answered Sep 04 '25 08:09

Pixel_95