NetTopologySuite.IO.GeoJSON icon indicating copy to clipboard operation
NetTopologySuite.IO.GeoJSON copied to clipboard

GeoJSON Multipoligon ring order not correct.

Open kyjote opened this issue 3 years ago • 1 comments

RFC 7946 states: "For Polygons with more than one of these rings, the first MUST be the exterior ring, and any others MUST be interior rings. The exterior ring bounds the surface, and the interior rings (if present) bound holes within the surface."

When using the NetTopologySuite.IO.GeoJSONSerializer and returning the GeoJSON from a Multipolygon in out SQL tables (geography), the order of the rings inside the out array are not consistent with the above standard. I have needed to add a function that reorders the rings so that the outer ring is first by using the area of all of the polygons inside the outer array. This works for me as a workaround but I would like to have the NetTopologySuite.IO.GeoJSONSerializer comply to the above standard. My workaround function is below so you can see what has fixed the problem on my end.

                  ```

foreach (JArray t in polyList) { LoopCount++; List<PointDouble> PointList = GeomHelpers.InnerGeometryToPointList(t); var area = GetAreaOfPolygon(PointList);

                        if (area >= runningArea)
                        {
                            runningArea = area;
                            countIsBiggest = LoopCount;
                        }
                    }

                    List<JArray> newPolyList = new List<JArray>();

                    newPolyList.Add(polyList[countIsBiggest - 1]);

                    LoopCount = 0;

                    foreach (var t in polyList)
                    {
                        LoopCount++;
                        if (LoopCount != countIsBiggest)
                        {
                            newPolyList.Add(t);
                        }
                    }

kyjote avatar May 09 '22 15:05 kyjote

can be related to #52 ? you states you're using the GeoJSONSerializer , but probably both serializers follow the same rules under the hood

DGuidi avatar May 30 '22 07:05 DGuidi

Duplicate of #52

FObermaier avatar Nov 18 '22 20:11 FObermaier