Cannot access LibKML driver using OGR in Python

by isevans77   Last Updated July 12, 2019 18:22 PM

I am trying to read a kmz file using OGR in Python. I believe the standard driver for reading .kmz files is LibKML (Can ogr2ogr read .kmz files? How?), but I am only getting None when I am building the driver:

import ogr

in_driver = ogr.GetDriverByName('LIBKML')

print(in_driver)
None

Other drivers I tested work as expected:

in_driver = ogr.GetDriverByName('KML')
print(in_driver)
<osgeo.ogr.Driver; proxy of <Swig Object of type 'OGRDriverShadow *' at 0x0000018E73FBCC00> >

in_driver = ogr.GetDriverByName('Esri Shapefile')
print(in_driver)
<osgeo.ogr.Driver; proxy of <Swig Object of type 'OGRDriverShadow *' at 0x0000018E73FBCC90> >

in_driver = ogr.GetDriverByName('NetCDF')
print(in_driver)
<osgeo.ogr.Driver; proxy of <Swig Object of type 'OGRDriverShadow *' at 0x0000018E73FBCBA0> >

SOME BACKGROUND:

I installed GDAL, which includes OGR, using the conda command. LibKML is one of the dependencies that gets installed with GDAL.

conda install gdal

I know that the LIBKML driver must be compiled against the latest version of LibKML (not version 1.2) (https://trac.osgeo.org/gdal/wiki/LibKML). I checked my version with conda list, and confirmed the I have LibKML 1.3.0 installed, which I believe is the latest version (i.e. no updates are available from Conda)

The other thing I checked was the list of ogr drivers, created by the following code:

import ogr
cnt = ogr.GetDriverCount()
formatsList = []  # Empty List
for i in range(cnt):
    driver = ogr.GetDriver(i)
    driverName = driver.GetName()
    if not driverName in formatsList:
        formatsList.append(driverName)
print(formatsList)
['ARCGEN', 'AVCBin', 'AVCE00', 'AeronavFAA', 'AmigoCloud', 'BNA', 'CAD', 'CSV', 'CSW', 'Carto', 'Cloudant', 'CouchDB', 'DB2ODBC', 'DGN', 'DXF', 'EDIGEO', 'ESRI Shapefile', 'ESRIJSON', 'ElasticSearch', 'GFT', 'GML', 'GMLAS', 'GPKG', 'GPSBabel', 'GPSTrackMaker', 'GPX', 'GeoJSON', 'GeoRSS', 'Geoconcept', 'Geomedia', 'HTF', 'HTTP', 'Idrisi', 'JML', 'KML', 'MBTiles', 'MSSQLSpatial', 'MVT', 'MapInfo File', 'Memory', 'NAS', 'ODBC', 'ODS', 'OGR_GMT', 'OGR_PDS', 'OGR_SDTS', 'OGR_VRT', 'OSM', 'OpenAir', 'OpenFileGDB', 'PCIDSK', 'PDF', 'PGDUMP', 'PGeo', 'PLSCENES', 'PostgreSQL', 'REC', 'S57', 'SEGUKOOA', 'SEGY', 'SQLite', 'SUA', 'SVG', 'SXF', 'Selafin', 'TIGER', 'TopoJSON', 'UK .NTF', 'VDV', 'VFK', 'WAsP', 'WFS', 'WFS3', 'Walk', 'XLS', 'XLSX', 'XPlane', 'netCDF']

The printed list does NOT contain LibKML, which I am guessing is symptom of the problem. How can I get LibKML to work with OGR in python?



Related Questions


GDAL 2.1.3 doesn't have LIBKML

Updated February 17, 2017 22:22 PM

How to style KML through LIBKML layer creation options?

Updated September 30, 2018 18:22 PM


python GDAL translate to convert and coloring

Updated March 03, 2018 02:22 AM

WMS Tutorial on Python Gdal

Updated February 28, 2019 14:22 PM