Closed nunojpg closed 7 years ago
Well if I log d3.geoArea(voronoi.features[0])
I get 2π.
The polygons are well-defined and if you look at the coordinates, you can see that they follow the left-hand rule (ahem!). But this is the rule of d3-geo!
Quoting README:
the exterior ring for polygons smaller than a hemisphere must be clockwise, while the exterior ring for polygons larger than a hemisphere must be anticlockwise. (…) This winding order convention is also used by TopoJSON and ESRI shapefiles; however, it is the opposite convention of GeoJSON’s RFC 7946.
I made a block to demonstrate how everything is displayed correctly, and geoArea and geoContains work (see the console).
Got it that d3 uses the opposite winding order as the RFC.
BUT, there is something beside that, and I can't understand how geoArea gives you any area, as all the Polygon coordinates are on the equator. All the latitudes are 0...
Also, your example seems to fail as soon as a third point is added (I tried 0,0). All features coordinates become NaN.
All the latitudes are 0
that's precisely the boundary of the polygon, which defines the north (respectively south) hemisphere, given the winding order.
example seems to fail with (0,0)
both planar and geo voronoi diagrams implementations have issues with precisely aligned points. Try adding a little bit of randomness in the coordinates, and it works. (Maybe that's an error that could be caught or avoided.)
A solution for my problem (not a issue with geo-voronoi) was provided at: https://github.com/d3/d3-geo/issues/104
@Fil I made a little demo on Leaflet, with polygons() and find(). Works perfectly and the code is very simple because there is no need to do any conversion to svg/canvas overlay pixels.
http://bl.ocks.org/nunojpg/cc204e57cc6c57dcc1f1ba311393e1f1
(click to activate the find() functionality)
Consider:
voronoi is now:
As both input points were symmetric to the equator, the voronoi polygons are the north and south hemisphere, but geoVoronoi outputs zero area polygons (lines).
This can be plotted/linted at http://geojsonlint.com/.