How to convert a GeoJSON file to a shapefile in Python?

How to convert a GeoJSON file to a shapefile in Python?

I’m trying to convert a geojson file into a shapefile. I’m trying this way (I’m very new to Python so it might be incorrect).

How to write shapely geometries to shapefiles in Python?

I have put this together after reading How to create polygon shapefile from a list of coordinates using python gdal/ogr?, and How to write Shapely geometries to shapefiles? I am attempting to read a GeoJSON response and put together 3 different shapefiles; one for each geometric type that may be contained in the response.

Do you need to convert shapely to JSON?

You need to convert to JSON in order for mapbox, etc… to properly accept it. Now you can try to map features in mapbox. Hope this helps. Reference: https://gis.stackexchange.com/questions/213717/geometry-workflow-from-shapely-to-geojson

How to write a GeoJSON object using PANDAS?

To write a standard geojson object using pandas you shall use the driver provided by fiona as recommended in the documentation Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers.

What happens when I convert JSON to GeoJSON?

When I convert into geojson, I get output, but only one feature is getting formatted as JSON I got output like this:

Is it appropriate to write to shapefile using pickle?

EDIT: In response to comments – yes, pickle is not the appropriate way to go about writing to the file in this case. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.

Why is ogr2ogr not opening my shapefile?

First, ogr2ogr couldn’t open your shapefile, and you realized permissions issues were in fact affecting the OS user accessing your shapefile. But there is an important lesson here for others, specifically, ogr2ogr’s error message on this point was misleading!

Why do I get error import shapefile in PostGIS?

ERROR 1: Terminating translation prematurely after failed translation of layer world_boundaries (use -skipfailures to skip errors) I also tried to import it through the GUI shp2pgsql and I get the following error:

Can a shapefile be opened in another software?

As @user1919 discovered, make sure your OS user has sufficient privileges to access the shapefile! As they demonstrated, it can help to try opening the shapefile in another software, like QGIS—if it works in one software, then it’s not corrupt, and it should work in other software.