2

I am trying to use ogr2ogr to convert a SHP to KML. I want to use the LIBKML driver because it has more options for customizing the KML output. Code is below (running in Jupyter notebook).

! ogr2ogr -f LIBKML out.kml in.shp
ERROR 1: Unable to find driver `LIBKML'.

Windows, Python 3.7, gdal 3.3.1, libkml 1.3.0

I'm in a new Anaconda environment, set up like this:

conda create -n gdal python=3.7
conda activate gdal
conda config --env --add channels conda-forge
conda config --env --set channel_priority strict
conda install -c conda-forge gdal
conda install -c conda-forge matplotlib pandas geopandas 
conda install -c conda-forge jupyterlab notebook
ipython kernel install --name "gdal" --user
conda install -c conda-forge libkml 

The same question was asked here, and based on the comments I can see ogr doesn't recognize the libkml driver even though I installed it and it shows up in conda list

! ogrinfo --formats|findstr KML
KML -vector- (rw+v): Keyhole Markup Language (KML)
1
  • I also tried conda update gdal since I installed libkml after gdal, but the error message persists
    – a11
    Commented Jul 14, 2021 at 20:53

2 Answers 2

3

The GDAL LIBKML driver relies on the external libkml library which you have installed, however the LIBKML driver is not built in to GDAL by default.

Just installing the libkml library will not automatically add the LIBKML driver to GDAL, you will need to either install a GDAL build that includes the LIBKML driver or compile GDAL from source yourself with the LIBKML driver enabled.

The conda-forge repo Linux and MacOS GDAL builds include LIBKML driver support, but the Windows build does not. I assume they never got around to enabling it for Windows after they managed to get the libkml library to build on Windows.

Suggest you submit an issue requesting enabling the LIBKML driver in the Windows GDAL build.

1
  • Great answer and explanation, thank you.
    – a11
    Commented Jul 15, 2021 at 1:38
0

GDAL has two KML drivers:

KML https://gdal.org/drivers/vector/kml.html

LIBKML https://gdal.org/drivers/vector/libkml.html

Your orginfo test confirms that you do not have the LIBKML driver. You can use the KML driver that you have

ogr2ogr -f KML out.kml in.shp

but KML driver has some limitations. Alternatively you must find out what is wrong with your LIBKML driver installation.

5
  • agreed, how would I find out what is wrong with the libkml install? looking to use libkml, not kml, driver
    – a11
    Commented Jul 14, 2021 at 21:08
  • 1
    Maybe conda version of GDAL is not built with LIBKML? ttps://gis.stackexchange.com/questions/120101/building-gdal-with-libkml-support.
    – user30184
    Commented Jul 14, 2021 at 21:20
  • that's a good point, but I think it should work in Anaconda because I am following this tutorial (quick link to libkml section)
    – a11
    Commented Jul 14, 2021 at 21:24
  • 1
    If command ogrinfo --format LIBKML does not list the driver it is definitely missing. Perhaps the tutorial in not up to date?
    – user30184
    Commented Jul 14, 2021 at 21:51
  • good points thank you; although they use gdal 3.3.0 release only a couple months ago (April 2021), so it is curious
    – a11
    Commented Jul 14, 2021 at 22:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.