1

I have this PNG and I use gdal_polygonize 0VxOhek.png -f "geojson" 0VxOhek.geojson This is the output.

There is a "features"-array which contains many objects with "type", "properties" and "geometry" elements. "geometry" contains "type" and "coordinates". "coordinates" is a 3 dimensional array. Usually its outermost array contains one array which contains arrays with coordinates in them. So each element of the "features"-array looks like this:

{ "type": "Feature", "properties": { "DN": 2 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ X1, Y1 ], [ X2, Y2 ], [ X3, Y3 ], [ X4, Y4] ] ] } }

But as you can see in the output file there are some "coordinates" with more than one array in the outermost array of "coordinates" (Begin of counting at 0: 48th (line 53), 50th (line 55), 54th, 64th). These "coordinates" look like this: "coordinates": [ [ [ X1, Y1 ], [ X2, Y2 ], [ X3, Y3 ] ], [ [ X4, Y4 ], [X5, Y5], [X6, Y6] ] ]

What happened? Is there a way to prevent that? Can I just combine these 2 into one array?

5
  • 1
    The image has interior rings ("holes"). Multi-part rings may also be generated. You need to handle the possibility that interior or exterior rings (or both) may exist in the coordinates JSON array. If you merge the array elements, you will corrupt the geometry.
    – Vince
    Commented Dec 29, 2014 at 20:31
  • I see! So if I would delete the second group off coordinates ([X4,Y4]-[X6,Y6]) I would get a big circle instead of a Donut right?
    – Selphiron
    Commented Dec 29, 2014 at 20:42
  • 1
    Yes, if you drop the interior ring of a donut you get a circle.
    – Vince
    Commented Dec 29, 2014 at 20:46
  • I'll try to put something together this evening.
    – Vince
    Commented Dec 29, 2014 at 20:52
  • 1
    The GeoJSON specification is good reference geojson.org/geojson-spec.html#id4.
    – user30184
    Commented Dec 29, 2014 at 21:33

1 Answer 1

3

GDAL is not wrong, since there are interior rings ("holes"). Specifically, "DN:4" has two tiny holes: PNG (zoomed in) zoom

GeoJSON uses a three-dimension coordinates array to capture multi-ring data. Rings can be exterior or interior (interior rings are the "donut holes" in simple Polygons, and multiple exterior rings are used for island chains, aka "MultiPolygons") -- the array structure doesn't differentiate, and you could actually have a combination of both.

You certainly wouldn't want to merge the arrays, since the result would have lines crossing the polygon figure from ring0 start-stop point to ring1 start-stop point, and that will often produce erratic results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.