[gdal-dev] Converting multilayer KML to single layer output

Rutger kassies at gmail.com
Wed Nov 30 04:44:54 PST 2016


Hey,

I am trying to convert a kml-file containing multiple layers to a new output
(GeoJSON for example), which only supports a single layer. All geometry
types in the kml are identical, all polygon.

The only way i can make it work (by using gdal.VectorTranslate) is to first
write a single layer to a file in 'overwrite' mode. And then run almost the
identical command for the remaining layers in 'append' mode. Writing all
layers in append mode sort of works, it creates the file and writes all
layers, but it doesn't close the file properly. In the case of GeoJSON, it
doesnt write ']}' at the end of the file. 

What i currently do is:
/
res = gdal.VectorTranslate(outfile, infile, format='GeoJSON',
accessMode='overwrite', layers=layers[0], layerName='outlayer')
res = None

res = gdal.VectorTranslate(outfile, infile, format='GeoJSON',
accessMode='append', layers=layers[1:], layerName='outlayer')
res = None/

Where 'layers' is a Python list populated by iterating over the layers and
calling 'lyr.GetName()'.

I dont like needing two commands to do this, and also iterating over all
layers manually, just to get the names, seems a bit redundant. So i'm
wondering if anyone knows ways to improve upon this.

Regards,
Rutger





--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Converting-multilayer-KML-to-single-layer-output-tp5298014.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list