GeoJSON MultiPolygon with multiple holes

ThomasReggi picture ThomasReggi · Apr 26, 2017 · Viewed 17.2k times · Source

Below I have what I'd expect is a way to create a GeoJSON MultiPolygon object with one polygon in it which has two "holes".

When I use the service http://geojson.io/ to validate this object, it returns with an error each element in a position must be a number and it does not render, however if I remove the "holes" nest, removing one of them then it works.

I'm looking for a way to describe a MultiPolygon where the polygons can have multiple holes.

I'm not looking for a way in code to create a polygon with holes.

I'm looking for a way to use the GeoJSON spec to represent MultiPolygons with multiple holes.

enter image description here

{
  "type": "MultiPolygon",
  "coordinates": [
    [
      [
        [
          -73.98114904754641,
          40.7470284264813
        ],
        [
          -73.98314135177611,
          40.73416844413217
        ],
        [
          -74.00538969848634,
          40.734314779027144
        ],
        [
          -74.00479214294432,
          40.75027851544338
        ],
        [
          -73.98114904754641,
          40.7470284264813
        ]
      ],
      [
        [
          [
            -73.99818643920906,
            40.74550031602355
          ],
          [
            -74.00298643920905,
            40.74550031602355
          ],
          [
            -74.00058643920897,
            40.74810024102966
          ],
          [
            -73.99818643920906,
            40.74550031602355
          ]
        ],
        [
          [
            -73.98917421691903,
            40.73646098717515
          ],
          [
            -73.99397421691901,
            40.73646098717515
          ],
          [
            -73.99157421691893,
            40.739061265535696
          ],
          [
            -73.98917421691903,
            40.73646098717515
          ]
        ]
      ]
    ]
  ]
}

Answer

ThomasReggi picture ThomasReggi · May 2, 2017

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
        ]
      ]
    ]
  ]
}