GeoJSON to Shapefile – How to Convert GeoJSON to Shapefile

geojsonpythonshapefile

I have a found a lot of questions about converting shapefiles to GeoJSON, but how do you convert a GeoJSON to a Shapefile?

I've seen Converting GeoJSON to Shapefile using ogr2ogr? that uses ogr2ogr, but they look like they are commands for a shell.

Is there a pure Python script to do it?

I've also found this solution that runs without any errors, but the output is still a GeoJSON.

Perhaps explaining how to write as a .shp?

import geojson
import subprocess
import urllib.request as ur

url = 'http://ig3is.grid.unep.ch/istsos/wa/istsos/services/ghg/procedures/operations/geojson?epsg=3857'
response = ur.urlopen(url)
data = geojson.loads(response.read())

with open('D:/Scripts/Stand19North.geojson', 'w') as f:
    geojson.dump(data, f)

args = ['ogr2ogr', '-f', 'ESRI Shapefile', 'D:/Scripts/converted_shp.shp',
        'Stand19North.geojson']
subprocess.Popen(args)

Best Answer

Geopandas can accomplish this.

Try this:

import geopandas as gpd

gdf = gpd.read_file('file.geojson')
gdf.to_file('file.shp')