How to merge adjacent polygons

I am using Fortune's Javascript implementation to compute voronoi cells ( https://github.com/gorhill/Javascript-Voronoi ). My sites for calculation are points on the map (therefore (lat,lng) ). First I made a projection (lat,lng) -> (x,y) , then I calculated the voronoi cells and made a half-edge projection in another way.
It works great, I show the result using the flyer, but I need to do one more thing.

Each site that I initially compute depends on the identifier, I reclassify voronoi cells by ID, and I end up with each identifier with a standard data structure that looks 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] ]] } } ] }; 

The set of polygons (made from a half-edge in voronoi cells) for a given ID.

I need to combine these 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 tried to get around a pair (lat,lng) from 10 ^ -14 to 10 ^ -7, but it really didn't work. Before searching for the kinks and trying to delete them, I printed a few examples of the data, and I know, I ask myself if I used good data from the Fortune algorithm. When I display all polygons for all identifiers, I have the correct diagram, but when I show all polygons for one ID or several polygons for one ID, I end up with incomplete diagrams:

part of the full chart

Part of the complete diagram

enter image description here

Part of the diagram for a single identifier

enter image description here

Two "polygons" for a given ID

Does anyone have an idea how to combine a polygon that has at least one common vertex? And why is there a topology error?

Edit: Polygons are not "incomplete" (I used a polyline)

enter image description here

I also tried a simpler example:

enter image description here

And still got the error:

 Uncaught TopologyError: side location conflict [ (44.8220601, -0.5869532) ] 

So it’s not (or at least not only) because of kinks

+5
source share
1 answer

Your problem occurs before the data gets into Turf. Running GeoJSON from a GitHub problem using GeoJSON validation shows two errors. First, you only include a geometry object for each function, and GeoJSON requires that all functions also have a properties object, even if it is empty. Secondly, and more importantly, the valid GeoJSON polygon must be a closed loop with the same coordinates for the first and last points. This second problem is what makes Turf throw its error. Polygons will merge successfully as soon as the first group of coordinates is copied to the end to close the ring.

After displaying the data on the map, it also becomes clear that your latitude and longitude are reversed. The coordinates should be lon,lat in GeoJSON, and since yours are in lat,lon , polygons appear in the middle of the Indian Ocean. Once this is fixed, they appear in the right place.

Here is a fiddle showing their successful merge:

http://fiddle.jshell.net/nathansnider/p7kfxvk7/

+2
source

Source: https://habr.com/ru/post/1245971/


All Articles