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)
ogr2ogr
as a subprocess. If you already have a GeoJSON file, then you may as well just runogr2ogr
on a shell, unless there's other work to do in Python. If this script works without raising an error, then you already haveogr2ogr
available as a command.