1

I have a collection of very large KML files that I'm trying to convert to .shp. I'm iterating over 200+ KML files with an average size of around 20 MB. Each KML contains multiple layers, some of which have names that contain special characters including /.

When I run ogr2ogr on these KMLs the layers with names containing special characters do not get created, as the layer's .shp files are named by each layer and filenames cannot include things like /.

I wrote a script to replace all special characters using sed but due to the huge volume of text this looks like it will take several days to complete, even on a fast machine with SSD.

I was hoping to use ogr2ogr's -nln parameter to map outgoing layer names to character-safe names, but the parameter seems to only accommodate a single layer name.

Can anyone suggest a way to change the KML layer names before conversion that may be quicker than sed (Google Earth struggles and eventually crashes if I try to open the KML directly), or a way to explicitly tell ogr2ogr what to call the new .shp files?

1 Answer 1

1

You probably want to write a script, but starting point could be to take a list of the layers with ogrinfo:

ogrinfo kml_samples.kml INFO: Open of `kml_samples.kml' using driver `LIBKML' successful. 1: Placemarks 2: Styles and Markup 3: Highlighted Icon 4: Ground Overlays 5: Screen Overlays 6: Paths 7: Polygons 8: Google Campus 9: Extruded Polygon 10: Absolute and Relative 

Then write ogr2ogr commands for each layer you would like to convert

ogr2ogr -f "ESRI Shapefile" extruded_polygon.shp kml_samples.kml "Extruded Polygon" ... ... 
1
  • this looks like a great option, I'll try it out tonight Commented Apr 14, 2015 at 17:56

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.