Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounding box support for geoVoronoi #46

Closed
jrauschenbusch opened this issue Feb 17, 2022 · 4 comments
Closed

Bounding box support for geoVoronoi #46

jrauschenbusch opened this issue Feb 17, 2022 · 4 comments

Comments

@jrauschenbusch
Copy link

Currently one is able to generate Voronoi polygons by passing a set of points. Unfortunately there is no support for bounding box clipping like the Delaunay.vornoi(bbox) or the turf.voronoi(points, { bbox }) function. Is it possible that this functionality can be added or is there another way to achieve this?

@Fil
Copy link
Owner

Fil commented Feb 17, 2022

Good question! It makes sense to clip spherical coordinates to a rectangular bounding-box is when the projection is cylindrical (Mercator or equirectangular, for example). Otherwise the clipped area can be unexpected:

turf.voronoi example

Of course, if the region you're working on is very small, it's a good idea to project first with a locally conformal projection, then compute the voronoi tessellation (with clipping) on the resulting pixel coordinates. turf.voronoi doesn't do this, and as a consequence is not accurate outside of the equatorial region if you feed it spherical coordinates.

When you need a large region of the globe and want a correct spherical voronoi, you can use d3-geo-voronoi, and then clip its polygons to a rectangle. It can be done with the clipExtent option of d3-geo's projections:

d3.geoMercator()
  .fitExtent([[10, 10],[630, 490]], points)
  .clipExtent([[1, 1], [639, 499]])

a

@Fil Fil closed this as completed Feb 17, 2022
@jrauschenbusch
Copy link
Author

One last question. Since my main goal is to produce a GeoJSON output from a BBox bounded Voronoi diagram (for further processing) and not to produce a d3 rendering, is there an easy approach to achieve? I mean the mentioned clipping based on a d3 projection only works for a d3 rendering context, right?

@Fil
Copy link
Owner

Fil commented Feb 21, 2022

I knew you'd want that :)

untitled (12)

https://observablehq.com/@fil/clipped-geovoronoi

@jrauschenbusch
Copy link
Author

@Fil Thank you so much! You made my day! The world needs more developers like you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants