[gdal-dev] Determine which KML file inside a KMZ a Layer comes from?

Even Rouault even.rouault at spatialys.com
Mon Apr 15 12:23:05 PDT 2019


Simon,

> I have a KMZ which contains five KML files (not including the top-level
> doc.kml), most of which contains a single-digit number of layers, each with
> a large number (hundreds to thousands) of features.
> 
> When I open the KMZ with openGDALDataset() and then use
> OGRDataSource::GetLayers() (the new variant which returns a collection) I
> get a merged list of all the layers from all the KMLs.
> 
> I am importing the data and grouping it by layer, with a single global
> prefix provided by the user, but as some of the KMLs have layers which have
> the same name as layers in another KML, the resulting merged set of layer
> names may not all be unique.
> 
> Is there any way to determine which KML a particular layer came from, or to
> get the list of KML files and then iterate the layers for each in turn?

You can list the kml files with VSIReadDir("/vsizip/your.kmz"), and open each 
of them individually.

> 
> Also, one of those five KMLs actually has 1720 layers, each of which only
> contains one feature. As an aside, is this common?

Yes, this can happen sometimes if each feature in a KML Folder. The 
hierarchical nature of KML files is sometimes hard to translate in relevant 
OGR layers.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list