3

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.


(test_env) C:\>conda list
# packages in environment at C:\Anaconda3\envs\test_env:
#
# Name Version Build Channel
_r-mutex 1.0.1 anacondar_1 conda-forge
altair 3.1.0 py37_0 conda-forge
arrow-cpp 0.11.1 py37_vc14h261ab4c_1000 conda-forge
asn1crypto 0.24.0 py37_1003 conda-forge
atomicwrites 1.3.0 py_0 conda-forge
attrs 19.1.0 py_0 conda-forge
backcall 0.1.0 py_0 conda-forge
bcrypt 3.1.6 py37hfa6e2cd_1 conda-forge
blas 1.0 mkl
bleach 3.1.0 py_0 conda-forge
blosc 1.16.3 h6538335_1 conda-forge
bokeh 1.2.0 py37_0 conda-forge
boost-cpp 1.68.0 h6a4c333_1000 conda-forge
branca 0.3.1 py_0 conda-forge
brotli 1.0.7 he025d50_1000 conda-forge
bzip2 1.0.6 hfa6e2cd_1002 conda-forge
c-ares 1.15.0 h2fa13f4_1001 conda-forge
ca-certificates 2019年6月16日 hecc5488_0 conda-forge
certifi 2019年6月16日 py37_0 conda-forge
cffi 1.12.3 py37hb32ad35_0 conda-forge
cfitsio 3.430 hfa6e2cd_1002 conda-forge
cftime 1.0.3.4 py37h452e1ab_1001 conda-forge
chardet 3.0.4 py37_1003 conda-forge
colorama 0.4.1 py_0 conda-forge
cryptography 2.7 py37hb32ad35_0 conda-forge
curl 7.65.1 h4496350_0 conda-forge
cycler 0.10.0 py_1 conda-forge
decorator 4.4.0 py_0 conda-forge
defusedxml 0.5.0 py_1 conda-forge
double-conversion 3.1.5 h6538335_1 conda-forge
entrypoints 0.3 py37_1000 conda-forge
ephem 3.7.6.0 py37hfa6e2cd_1001 conda-forge
expat 2.2.5 habb2df7_1003 conda-forge
folium 0.9.1 py_0 conda-forge
freetype 2.10.0 h5db478b_0 conda-forge
freexl 1.0.5 hd288d7e_1002 conda-forge
gdal 3.0.1 py37he6b6c38_2 conda-forge
geos 3.7.2 habb2df7_1 conda-forge
geotiff 1.5.1 h8f84788_2 conda-forge
gettext 0.19.8.1 hb01d8f6_1002 conda-forge
gflags 2.2.2 he025d50_1001 conda-forge
glib 2.58.3 hc0c2ac7_1001 conda-forge
glog 0.3.5 h6538335_1
grpc-cpp 1.22.0 h4d7d3fa_0 conda-forge
hdf4 4.2.13 hf8e6fe8_1002 conda-forge
hdf5 1.10.5 nompi_hcc15c50_1100 conda-forge
huracan 0+untagged.310.gd65af62.dirty dev_0 <develop>
icc_rt 201900 h0cc432a_1
icu 58.1 vc14_0 conda-forge
idna 2.8 py37_1000 conda-forge
importlib_metadata 0.18 py37_0 conda-forge
intel-openmp 2019.4 245
ipykernel 5.1.1 py37h39e3cac_0 conda-forge
ipython 7.6.1 py37h5ca1d4c_0 conda-forge
ipython_genutils 0.2.0 py_1 conda-forge
jedi 0.14.0 py37_0 conda-forge
jinja2 2.10.1 py_0 conda-forge
joblib 0.13.2 py_0 conda-forge
jpeg 9c hfa6e2cd_1001 conda-forge
json5 0.8.5 py_0 conda-forge
jsonschema 3.0.1 py37_0 conda-forge
jupyter_client 5.3.0 py_0 conda-forge
jupyter_core 4.4.0 py_0 conda-forge
jupyterlab 1.0.1 py37_0 conda-forge
jupyterlab_server 1.0.0 py_1 conda-forge
kealib 1.4.10 hf7dc31f_1005 conda-forge
kiwisolver 1.1.0 py37he980bc4_0 conda-forge
krb5 1.16.3 hdd46e55_1001 conda-forge
libblas 3.8.0 8_mkl conda-forge
libcblas 3.8.0 8_mkl conda-forge
libcurl 7.65.1 h4496350_0 conda-forge
libffi 3.2.1 h6538335_1006 conda-forge
libgdal 3.0.1 h73c0052_2 conda-forge
libiconv 1.15 hfa6e2cd_1005 conda-forge
libkml 1.3.0 h4fd0f3b_1009 conda-forge
liblapack 3.8.0 8_mkl conda-forge
libnetcdf 4.6.2 ha953453_1002 conda-forge
libpng 1.6.37 h7602738_0 conda-forge
libpq 11.4 hb0bdaea_1 conda-forge
libprotobuf 3.8.0 h1a1b453_0 conda-forge
libsodium 1.0.16 h2fa13f4_1001 conda-forge
libspatialite 4.3.0a h832c139_1029 conda-forge
libssh2 1.8.2 h642c060_2 conda-forge
libtiff 4.0.10 h6512ee2_1003 conda-forge
libxml2 2.9.9 h9ce36c8_1 conda-forge
llvmlite 0.29.0 py37hed17590_1 conda-forge
lz4-c 1.8.3 he025d50_1001 conda-forge
m2w64-bwidget 1.9.10 2
m2w64-bzip2 1.0.6 6
m2w64-expat 2.1.1 2
m2w64-fftw 3.3.4 6
m2w64-flac 1.3.1 3
m2w64-gcc-libgfortran 5.3.0 6
m2w64-gcc-libs 5.3.0 7
m2w64-gcc-libs-core 5.3.0 7
m2w64-gettext 0.19.7 2
m2w64-gmp 6.1.0 2
m2w64-gsl 2.1 2
m2w64-libiconv 1.14 6
m2w64-libjpeg-turbo 1.4.2 3
m2w64-libogg 1.3.2 3
m2w64-libpng 1.6.21 2
m2w64-libsndfile 1.0.26 2
m2w64-libtiff 4.0.6 2
m2w64-libvorbis 1.3.5 2
m2w64-libwinpthread-git 5.0.0.4634.697f757 2
m2w64-libxml2 2.9.3 4
m2w64-mpfr 3.1.4 4
m2w64-openblas 0.2.19 1
m2w64-pcre 8.38 2
m2w64-speex 1.2rc2 3
m2w64-speexdsp 1.2rc3 3
m2w64-tcl 8.6.5 3
m2w64-tk 8.6.5 3
m2w64-tktable 2.10 5
m2w64-wineditline 2.101 5
m2w64-xz 5.2.2 2
m2w64-zlib 1.2.8 10
markupsafe 1.1.1 py37hfa6e2cd_0 conda-forge
matplotlib 3.1.1 py37_0 conda-forge
matplotlib-base 3.1.1 py37h2852a4a_0 conda-forge
mistune 0.8.4 py37hfa6e2cd_1000 conda-forge
mkl 2019.4 245
mock 3.0.5 py37_0 conda-forge
more-itertools 7.1.0 py_0 conda-forge
msys2-conda-epoch 20160418 1
nbconvert 5.5.0 py_0 conda-forge
nbformat 4.4.0 py_1 conda-forge
netcdf4 1.5.1.2 py37h8c66456_1 conda-forge
notebook 5.7.8 py37_1 conda-forge
numba 0.44.1 py37hf9181ef_0
numexpr 2.6.9 py37h6538335_1000 conda-forge
numpy 1.16.4 py37hc71023c_0 conda-forge
olefile 0.46 py_0 conda-forge
openjpeg 2.3.1 ha922770_0 conda-forge
openssl 1.1.1c hfa6e2cd_0 conda-forge
owslib 0.18.0 py_0 conda-forge
packaging 19.0 py_0 conda-forge
pandas 0.24.2 py37he350917_0 conda-forge
pandoc 2.7.3 0 conda-forge
pandocfilters 1.4.2 py_1 conda-forge
paramiko 2.6.0 py37_0 conda-forge
parquet-cpp 1.5.1 2 conda-forge
parso 0.5.0 py_0 conda-forge
patsy 0.5.1 py_0 conda-forge
pcre 8.41 h6538335_1003 conda-forge
pickleshare 0.7.5 py37_1000 conda-forge
pillow 6.1.0 py37h9a613e6_0 conda-forge
pip 19.1.1 py37_0 conda-forge
plotly 3.10.0 py_0 conda-forge
pluggy 0.12.0 py_0 conda-forge
poppler 0.67.0 heddaa77_6 conda-forge
poppler-data 0.4.9 1 conda-forge
postgresql 11.4 h06f7779_1 conda-forge
proj4 6.1.0 hc2d0af5_2 conda-forge
prometheus_client 0.7.1 py_0 conda-forge
prompt_toolkit 2.0.9 py_0 conda-forge
pvlib-python 0.6.3 py_0 conda-forge
py 1.8.0 py_0 conda-forge
pyarrow 0.11.1 py37h8c67754_1001 conda-forge
pycparser 2.19 py37_1 conda-forge
pycrs 1.0.1 py_0 conda-forge
pygments 2.4.2 py_0 conda-forge
pynacl 1.3.0 py37h62dcd97_0
pyodbc 4.0.26 py37h6538335_0 conda-forge
pyopenssl 19.0.0 py37_0 conda-forge
pyparsing 2.4.0 py_0 conda-forge
pyproj 2.2.1 py37h3f740ce_0 conda-forge
pyqt 5.9.2 py37h6538335_0 conda-forge
pyrsistent 0.15.3 py37hfa6e2cd_0 conda-forge
pysocks 1.7.0 py37_0 conda-forge
pytables 3.5.2 py37h26f9782_1 conda-forge
pytest 5.0.1 py37_0 conda-forge
python 3.7.3 h510b542_1 conda-forge
python-dateutil 2.8.0 py_0 conda-forge
pytz 2019.1 py_0 conda-forge
pywinpty 0.5.5 py37_1000 conda-forge
pyyaml 5.1.1 py37hfa6e2cd_0 conda-forge
pyzmq 18.0.2 py37he7828b0_0 conda-forge
qt 5.9.7 hc6833c9_1 conda-forge
r-assertthat 0.2.1 r351h6115d3f_0 conda-forge
r-backports 1.1.4 r351h6115d3f_0 conda-forge
r-base 3.5.1 hdf77c54_1008 conda-forge
r-base64enc 0.1_3 r351h6115d3f_1002 conda-forge
r-cli 1.1.0 r351h6115d3f_0 conda-forge
r-crayon 1.3.4 r351h6115d3f_1001 conda-forge
r-digest 0.6.20 r351h796a38f_0 conda-forge
r-ellipsis 0.2.0.1 r351hda5aaf8_0 conda-forge
r-evaluate 0.14 r35h6115d3f_0 conda-forge
r-fansi 0.4.0 r351h6115d3f_1000 conda-forge
r-glue 1.3.1 r351h6115d3f_0 conda-forge
r-htmltools 0.3.6 r351hca4a3dc_1002 conda-forge
r-irdisplay 0.7 r351_1000 conda-forge
r-irkernel 1.0.1 r351h6115d3f_0 conda-forge
r-jsonlite 1.6 r351h6115d3f_1000 conda-forge
r-pbdzmq 0.3_3 r351h9c2a3b9_1001 conda-forge
r-pillar 1.4.2 h6115d3f_0 conda-forge
r-rcpp 1.0.1 r351h6115d3f_0 conda-forge
r-repr 1.0.1 r351h6115d3f_0 conda-forge
r-rlang 0.4.0 r35hda5aaf8_0 conda-forge
r-utf8 1.1.4 r351h6115d3f_1000 conda-forge
r-uuid 0.1_2 r351h6115d3f_1001 conda-forge
r-vctrs 0.2.0 r351hda5aaf8_0 conda-forge
r-zeallot 0.1.0 r351h6115d3f_1000 conda-forge
re2 2019年07月01日 vc14h6538335_0 [vc14] conda-forge
requests 2.22.0 py37_0 conda-forge
retrying 1.3.3 py_2 conda-forge
scikit-learn 0.21.2 py37h7208079_1 conda-forge
scipy 1.2.0 py37h29ff71c_0
seaborn 0.9.0 py_1 conda-forge
send2trash 1.5.0 py_0 conda-forge
setuptools 41.0.1 py37_0 conda-forge
shapely 1.6.4 py37ha35856d_1006 conda-forge
simplekml 1.3.0 py_1 conda-forge
sip 4.19.8 py37h6538335_1000 conda-forge
six 1.12.0 py37_1000 conda-forge
snappy 1.1.7 h6538335_1002 conda-forge
sqlite 3.28.0 hfa6e2cd_1 conda-forge
statsmodels 0.10.0 py37hfa6e2cd_0 conda-forge
tbb 201805 he980bc4_0 conda-forge
terminado 0.8.2 py37_0 conda-forge
testpath 0.4.2 py_1001 conda-forge
thrift-cpp 0.12.0 h59828bf_1002 conda-forge
tiledb 1.5.1 vc14h30b6f50_2 [vc14] conda-forge
tk 8.6.9 hfa6e2cd_1002 conda-forge
toolz 0.9.0 py_1 conda-forge
tornado 6.0.3 py37hfa6e2cd_0 conda-forge
traitlets 4.3.2 py37_1000 conda-forge
tzwhere 3.0.3 py37_0 huracan
uriparser 0.9.3 he025d50_1 conda-forge
urllib3 1.24.3 py37_0 conda-forge
vc 14.1 h0510ff6_4
vincent 0.4.4 py_1 conda-forge
vs2015_runtime 14.15.26706 h3a45250_4
wcwidth 0.1.7 py_1 conda-forge
webencodings 0.5.1 py_1 conda-forge
wheel 0.33.4 py37_0 conda-forge
win_inet_pton 1.1.0 py37_0 conda-forge
wincertstore 0.2 py37_1002 conda-forge
winpty 0.4.3 4 conda-forge
xerces-c 3.2.2 hb1a71c1_1002 conda-forge
xz 5.2.4 h2fa13f4_1001 conda-forge
yaml 0.1.7 hfa6e2cd_1001 conda-forge
zeromq 4.3.1 he025d50_1000 conda-forge
zipp 0.5.1 py_0 conda-forge
zlib 1.2.11 h2fa13f4_1004 conda-forge
zstd 1.4.0 hd8a0e53_0 conda-forge

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']

And checking ogrinfo from the Anaconda prompt:

(my_env) C:\>ogrinfo --formats|findstr KML
 KML -vector- (rw+v): Keyhole Markup Language (KML)

The printed list in Python does not contain LibKML. ogrinfo only returns the older KML driver, not LibKML How can I get LibKML to work with OGR in python?

GDAL 3.0.1, Python 3.7.3, Windows 10

asked Jul 12, 2019 at 17:32
3
  • GDAL 3.0.1 Python 3.7.3 Commented Jul 12, 2019 at 19:17
  • Works for me (GDAL 3.0.1 & Python 3.7.3 from conda-forge). What's the output of ogrinfo --formats|grep KML (linux/macos) or ogrinfo --formats|findstr KML (windows)? And what's the output of conda list? Both run in the activated conda env. Please edit your question to add info, don't use comments. Commented Jul 13, 2019 at 5:58
  • I found this on geostack from osgeo import ogr Commented Jul 13, 2019 at 13:15

1 Answer 1

1

Works for me in gdal 2.4.1 when installed using the wheel file from:

https://www.lfd.uci.edu/~gohlke/pythonlibs/

download the relevant .whl file as needed and install using pip.

answered Jul 15, 2019 at 13:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.