I'm using a Javascript implementation of Fortune's algorithm to compute voronoi cells (https://github.com/gorhill/Javascript-Voronoi). My sites to compute are points on a map (so (lat,lng)
). I first made the projection (lat,lng) -> (x,y)
, I then computed the voronoi cells and made the projection of the half edges the other way.
It works fine, I display the result using leaflet but I need to do one more thing.
Each site I initially compute depends of an ID, I reclassify the voronoi cells by ID and I end up, for each ID with a standard data structure looking like this :
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[
[9.994812, 53.549487],
[10.046997, 53.598209],
[10.117721, 53.531737],
[9.994812, 53.549487]
]]
}
}, {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[
[10.000991, 53.50418],
[10.03807, 53.562539],
[9.926834, 53.551731],
[10.000991, 53.50418]
]]
}
}
]
};
A set of polygons (made form the half edge of the voronoi cells) for a given ID.
I need to merge those polygons by ID, I intended to use turf.merge()
, but I have topology errors
turf.min.js:13 Uncaught TopologyError: side location conflict
Based on this post (http://lists.refractions.net/pipermail/jts-devel/2009-March/002939.html), I've tried to round the (lat,lng)
couple from 10^-14 to 10^-7 but it didn't really worked.
Before looking for the kinks and trying to remove them, I printed some data sample and I'm know asking myself if I used the good data from Fortune's algorithm. When I display all the polygons for all IDs, I have the right diagram, but when I display all the polygons for one ID or some polygons for one ID I end up with incomplete diagrams :
Part of the full diagram
Part of the diagram for one ID
Two "polygons" for a given ID
Does anyone has an idea how to merge polygon that share at least one common vertex ? And why there is a topology error ?
Edit : The polygons are not "incomplete" (I was using polyline)
I also tried on an easier sample :
And still got the error :
Uncaught TopologyError: side location conflict [ (44.8220601, -0.5869532) ]
So it's not (or at least not only) due to kinks