4

I am trying to convert a KML file to Shapefile using GDAL (ogr2ogr). Regular KML files convert fine but KML files containing MultiGeometry features (eg: Geometry containing both Point and Polygon) do not get transformed.

The output is simply a blank shapefile containing no shapes or attributes.

I have tried this command:

ogr2ogr -overwrite -f "ESRI Shapefile" -where OGR_GEOMETRY='MultiGeometry' <ouputfolder> <input kml>

For an example, KML file which has MultiGeometry, you can see the us_states.kml hosted by Google.

US States KML - Google.com

Other info: I am using 'GDAL 1.10.1, released 2013/08/26' for windows.

4

Shapefiles don't support MultiGeometry or GeometryCollections, but ogr2ogr can explode them:

ogr2ogr -nlt POLYGON -explodecollections -skipfailures us_states.shp us_states.kml

-explodecollections: (starting with GDAL 1.8.0) produce one feature for each geometry in any kind of geometry collection in the source file

1

You can run following commands to save geometry specific KML files using ogr2ogr tool

$ ogr2ogr -where "OGR_GEOMETRY='Point'" -f "ESRI Shapefile" us_states_points.shp us_states.kml
$ ogr2ogr -where "OGR_GEOMETRY='LineString'" -f "ESRI Shapefile" us_states_linestrings.shp us_states.kml

and so on

I hope it will help.

  • using gdal 2.2.0 the command does not work. Instead of creating a point shp, it remains a line layer... and it's empy – JGH Jul 11 '17 at 16:19
1

MultiGeometry is not yet implemented in the GDAL shapefile driver:

http://www.gdal.org/ogr/drv_shapefile.html

You can try loading the kml into QGIS, which might bring you one layer for each geometry type. You can then export each of those layers to single shapefiles.

  • 1
    QGIS also does not support MultiGeometry. – user26152 Jan 23 '14 at 22:30

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.