[GIS] Converting GeoJSON to Shapefile using ogr2ogr

fwtoolsgeojsonogr2ogr

I have a GeoJson file that I want to convert to ESRI Shapefile using ogr2ogr in FWTools.

I tried using

ogr2ogr -F "ESRI Shapefile" filename.shp geojsonfile.json OGRGeoJSON

I got output

ERROR 6: Can't create fields of type StringList on shapefile layers. ERROR 1: Attempt to write non-polygon (POINT)
geometry to type shapefile. ERROR 1: Terminating translation
prematurely after failed translation of layer OGRGeoJSON

GeoJSON input we are giving is in standard geojson format.

content of geojson are like {to share I took only a part from features array }

{"id":1223,
"properties":{"name":"3","level":2},
"map_version":11,"type":"FeatureCollection","x_id":1234,"obj_type":"LevelGeometry",
"features":[

{
"my_area":[131.40093253528894,33.58879853190332,6.515867411008615,3.490549810987222,-0.6237271428108215],
"id":1984791,
"location":{"type":"Point","coordinates":[131.4009325,33.5887985]},
"properties":{"display_name":"xyz"},
"type":"Feature",
"geometry":{"type":"Polygon","coordinates":[[[131.4009508,33.5888314],[131.4008895,33.5887946],[131.4009148,33.5887653],[131.4009761,33.5888020],[131.4009508,33.5888314]]]},
"obj_type":"Geometry"
}

]
}

Best Answer

You have to force the SHP geometry type (because the geometry type of GeoJSON Geometry Collection is not supported in SHPs) and use the -skipfailures option:

ogr2ogr -nlt POINT -skipfailures points.shp geojsonfile.json OGRGeoJSON    
ogr2ogr -nlt LINESTRING -skipfailures linestrings.shp geojsonfile.json OGRGeoJSON
ogr2ogr -nlt POLYGON -skipfailures polygons.shp geojsonfile.json OGRGeoJSON

(Tested with GDAL 1.10.0, released 2013/04/24)