I have a geojson-file (geojsonfile.geojson) with points, lines and polygons.

I would like to convert the geojson-file to 3 shapefiles (points, lines and polygons) and keep all the attributes.

Therefore i used ogr2ogr, see this topic:

GeoJson to ESRI Shapefile using ogr2ogr

with the following commands:

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

the exported point shapefiles show the exact same amount of features (2142 in shapefile, 2142 in geojson), but the linestring and polygon feature count is different (linestring: 511 in shapefile, 132 in geojson line, polygon: 426 in shapefile, 379 in geojson polygon). The additional features are also visible.

How can a conversion from geojson to shapefile lead to additional features? Also some errors have been reported while converting, but I guess this is because I forced the SHP geometry type (explained in other topic)?

Any ideas?

  • It might help if you could upload the files. Maybe multilinestrings or multipolygons were converted to single features or vice versa. Have you checked for geometry errors, intersections etc? – AndreJ Jul 6 '16 at 11:36

I would try to filter by Geometry Type during each conversion. For example, only Lines should be forced into the Line shapefile. I think your examples are Casting Lines to Polygons and Polygons to Lines. The geometry filter should prevent this from happening. Please see the OGR_GEOMETRY example in the OGR_SQL help. http://www.gdal.org/ogr_sql.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.