Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to run ogr2ogr to convert some geojson to shapefile. All is good until any of the geojson features have an invalid geometry (for example, the coordinate array of point geometry is empty).

I included the -skipfailures flag, but ogr2ogr quits as soon as it hits the first invalid feature. Am I not doing something wrong here?

Example ogr2ogr call:

ogr2ogr -skipfailures -f "ESRI Shapefile" myshape.shp mygeojson.geojson
share|improve this question
add comment

3 Answers

Try adding -nlt geometry to your ogr script:

ogr2ogr -skipfailures -f "ESRI Shapefile" myshape.shp mygeojson.geojson -nlt geometry

I've experienced the problem you describe using ogr2ogr to translate datasets containing both singlepart and multipart features in the same layer; for example, POINT and MULTIPOINT, LINE AND MULTILINE, and POLYGON and MULTIPOLYGON.

By default, OGR wants you to obey convention and use only one feature-type per dataset. If you break the rule, OGR will throw a generic error and recommend the -skipfailures flag. This can be misleading if the real issue is mixed/matched geometries in the same layer.

Since ESRI shapefile does allow single/multipart features in the same layer, you need to realize OGR may throw this error even if you have valid geometries. In that scenario you have two options: 1) Convert multipart features to singlepart (which ogr can do via the -explodecollections flag), or 2) use the -nlt flag and specify GEOMETRY as the option. The -nlt GEOMETRY option allows you to combine a mixture of feature types in the same layer. Of course, as a consequence, OGR won't won't protect best practices.

If your GeoJSON file "started life" as an ESRI shapefile, it's possible that you have both POINT and MULTIPOINT features contained in that dataset, in which case you might be encountering this issue even with valid points.

share|improve this answer
add comment

The intended behavior in my understanding is that if an invalid feature is encountered, it will be skipped and the conversion will continue with the next valid feature rather than stopping.

It appears that you are doing everything properly, so I don't know what's wrong! Have you tried going to a different format just to see if that works?

share|improve this answer
add comment
 -skipfailures: Continue after a failure, skipping the failed feature.

One explanation for the behavior you're experiencing could be that all features in your geoJSON file are broken. Have you tested their validity, e.g. using QGIS "Check geometry validity"?

share|improve this answer
    
All of the other features are valid. If I fix the one point geometry described in my original post, all of the other geojson points get added to the output shapefile. –  user890 Aug 28 '11 at 11:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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