Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Shapefiles can only have one geometry type, but many other formats (kml, geojson) can have multiple types.

When converting to shapefiles, is it possible to to tell ogr2ogr to create multiple shapefiles, one for each type?

It seems like the "-where" option might be useful but the man page does not explain the syntax.

For example, here's a command that fails:

$ wget
$ ogr2ogr -f "ESRI Shapefile" transit.shp transit.kml
Warning 6: Normalized/laundered field name: 'Description' to 'Descriptio'
ERROR 1: Attempt to write non-linestring (POINT) geometry to ARC type shapefile.
ERROR 1: Terminating translation prematurely after failed
translation of layer Transit (use -skipfailures to skip errors)
share|improve this question
Found the solution but I'm not allowed to answer my own question because I don't have enough karma, I'm supposed to wait 8 hours :-p You can run multiple times to write separate shapefiles and give eg. the option -where "OGR_GEOMETRY='Point'" to include only Points in one output file, then run again with -where "OGR_GEOMETRY='LineString'", etc. – slinkp Jun 1 '12 at 16:57
up vote 12 down vote accepted

Figured it out by reading the OGR SQL documentation at

This works, using one command and one output file per geometry type:

$ ogr2ogr -where "OGR_GEOMETRY='Point'" -f "ESRI Shapefile" transit_points.shp transit.kml
$ ogr2ogr -where "OGR_GEOMETRY='LineString'" -f "ESRI Shapefile" transit_linestrings.shp transit.kml
share|improve this answer
Thanks a ton, you probably saved me quite a few hours! – Doc Dec 1 '15 at 23:17

If the output parameter is a directory instead of a file name, ogr2ogr will automatically convert all geometry types into separate shapefiles:

ogr2ogr out_dir d:\incoming\nhn_09AA001_1_0.gml

Unfortunately for the OP this doesn't work for KML, but it does for some of the other multiple geometry type formats like ArcInfo Coverages and GML. Posting here because this is the highest voted question on selecting geometry type.

D:\>dir /s/b converted\*.shp

share|improve this answer

ogr2ogr: convert a single kml to shapefile:

ogr2ogr -f "ESRI Shapefile" C:\kml\LJ0047.shp C:\kml\LJ0047_.kml

ogr2ogr: convert multiples kml files to shapefiles:

for %f in (*.kml) do ogr2ogr -f "ESRI Shapefile" %~nf.shp %f

It's necessary to access the input folder.

share|improve this answer
Thanks, but that is not the question I asked. – slinkp Jun 4 '12 at 19:08

Your Answer


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.