Fix GEOJson self intersections

327 Views Asked by At

I'm trying to use the geo json from https://github.com/simonepri/geo-maps but they seem to have intersections which don't pass geo json validation (for example elastic)

I've tried python with the ogr library but it doesn't seem to do anything:

from osgeo import ogr

with open(cwd + '/earth-seas-10km.geo.json') as f:
    data = json.load(f)
    geom = ogr.CreateGeometryFromJson(json.dumps(data))
    valid = geom.MakeValid()

    with open(cwd + f'/output.json', 'w') as json_file:
        json.dump(json.loads(valid.ExportToJson()), json_file)

All this does is put the thing inside another GeometryCollection

How would I go about fixing them?

1

There are 1 best solutions below

0
On

Try the command line method like outlined here. The python wrapper of osgeo should do the same though.