How can I invert a GeoJson-Polygon

In the coordinates array add this array as the the first coordinates and it'll do the invert

    [
      [
        0,
        90
      ],
      [
        180,
        90
      ],
      [
        180,
        -90
      ],
      [
        0,
        -90
      ],
      [
        -180,
        -90
      ],
      [
        -180,
        0
      ],
      [
        -180,
        90
      ],
      [
        0,
        90
      ]
    ],

And you can find examples to exactly what you want to do here https://github.com/minaalfy/city-map


Here a code snippet for leaflet + GeoJson, to add a world rectangle to the coordinates. That will cut out/invert/reverse the polygon in geoJson.

geoJson.geometry.coordinates[0].unshift([[180, -90], [180, 90], [-180, 90], [-180, -90]]);
L.geoJSON(geoJson, { style: { color: '#ccc', weight: 2, fillOpacity: 0.5 } }).addTo(map);

Tags:

Geojson