GeoJSON MultiPolygon with multiple holes

For your example in fact it's not really a MultiPolygon (in the sense of geoJSON) but a simple Polygon (with a single outer ring and multiple inner rings for the holes). Note the difference with Multipolygons in OSM (which represents them as a relation containing ways, and whose first and last node should be merged to the same "node" element (something that does not exist in geoJSON where they are unified only by the fact that the two nodes have the same coordinates, but will in reality be automatically closed by an additional segment for "Polygon" and "MultiPolygon" types of GeoJSON)

Note that when you import a geoJSON in OSM editors (such as JOSM) they will be imported with separate nodes for the first and last node, even if they have the same coordinates - you need to use the JOSM validator to detect superposed nodes and merge them after the import in JOSM but before submission to OSM.

But in scripts or general use of geoJSON, all rings (arrays of coordinate pairs) in a "type":"Polygon" or members of a "type":"Polygon" are not required to include the same coordinates for the last node as the first node, because it is implicit (but it is still recommended to add this duplicate node for compatibility). Such closure of rings is implicit for "Polygon" and "MultiPolygon" (as they represent surfaces), but not for "Polyline" and "MultiPolyline" (as they represent curves) where you still need to include twice the same coordinates for the first and last node to get closed curves.

To represent an OSM "multipolygon" with multiple "outer" rings, you have to include several "[ {outer},{inner*} ]" in the main array of coordinates for the geoJSON "MultiPolygon" type, i.e.

{"type":"MultiPolygon", "coordinates":[
  [
    [[x0,y0], [x1,y1], ... [x0,y0]], /*outer1*/
    [[x0,y0], [x1,y1], ... [x0,y0]], /*inner1, optional*/
    [[x0,y0], [x1,y1], ... [x0,y0]], /*inner2, optional*/
  ],[
    [[x0,y0], [x1,y1], ... [x0,y0]], /*outer2*/
  ],...,[
    [[x0,y0], [x1,y1], ... [x0,y0]], /*outer3*/
  ],[
    [[x0,y0], [x1,y1], ... [x0,y0]], /*outer4*/
  ]
]}

So for your example, the solution is:

{"type":"Polygon", "coordinates":[
  [[x0,y0], [x1,y1], [x2,y2], [x3,y3], [x0,y0]], /*outer1*/
  [[x4,y4], [x5,y5], [x6,y6], [x4,y4]],          /*inner1*/
  [[x7,y7], [x8,y8], [x9,y9], [x7,y7]]           /*inner2*/
]}

If you had several outer rings only (possibly overlapping to create an union of surfaces, but this is not recommended) it would need to be a MultiPolygon, and here you would get no "holes":

{"type":"MultiPolygon", "coordinates":[
  [[[x0,y0], [x1,y1], [x2,y2], [x3,y3], [x0,y0]]], /*outer1*/
  [[[x4,y4], [x5,y5], [x6,y6], [x4,y4]]],          /*outer2*/
  [[[x7,y7], [x8,y8], [x9,y9], [x7,y7]]]           /*outer3*/
]}

Note there's one less level of [square braces] because we can use "Polygon" here instead of a Multipolygon that would contain only one member in your example.


This is how it works:

{
  "type": "MultiPolygon",
  "coordinates": [
    [
      {polygon},
      {hole},
      {hole},
      {hole}
    ]
  ]
}

Not like this:

{
  "type": "MultiPolygon",
  "coordinates": [
    [
      {polygon},
      [
        {hole},
        {hole},
        {hole}
      ]
    ]
  ]
}

Here's an example!

{
  "type": "MultiPolygon",
  "coordinates": [
    [
      [
        [
          -47.900390625,
          -14.944784875088372
        ],
        [
          -51.591796875,
          -19.91138351415555
        ],
        [
          -41.11083984375,
          -21.309846141087192
        ],
        [
          -43.39599609375,
          -15.390135715305204
        ],
        [
          -47.900390625,
          -14.944784875088372
        ]
      ],
      [
        [
          -46.6259765625,
          -17.14079039331664
        ],
        [
          -47.548828125,
          -16.804541076383455
        ],
        [
          -46.23046874999999,
          -16.699340234594537
        ],
        [
          -45.3515625,
          -19.31114335506464
        ],
        [
          -46.6259765625,
          -17.14079039331664
        ]
      ],
      [
        [
          -44.40673828125,
          -18.375379094031825
        ],
        [
          -44.4287109375,
          -20.097206227083888
        ],
        [
          -42.9345703125,
          -18.979025953255267
        ],
        [
          -43.52783203125,
          -17.602139123350838
        ],
        [
          -44.40673828125,
          -18.375379094031825
        ]
      ]
    ]
  ]
}