3

Attempting a run-of-the-mill ogr2ogr process with a KMZ file failed:

FAILURE:
Unable to open datasource `Rail.kmz' with the following drivers.

Is there a trick? (Obvious workaround is to unzip the .kmz first, but that's sometimes clunky, and you don't know what the internal structure will be exactly.)

GDAL 1.11.0, released 2014/04/16

5

GDAL has two drivers for KML, "KML" http://www.gdal.org/drv_kml.html and "LIBKML" http://www.gdal.org/drv_libkml.html. The LIBKML driver can read KMZ files out-of-the-box. This works for me with the GDAL 2.1-dev version from gisinternals.com:

Acquire test data from https://code.google.com/p/kml-samples/

Run ogrinfo:

ogrinfo time-stamp-point.kmz -al -so
INFO: Open of "time-stamp-point.kmz"
      using driver `LIBKML' successful.

Layer name: time-stamp-point
Geometry: Unknown (any)
Feature Count: 361
Extent: (-122.556706, 37.848038) - (-122.536226, 37.860470)
Layer SRS WKT:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        TOWGS84[0,0,0,0,0,0,0],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9108"]],
    AUTHORITY["EPSG","4326"]]
Name: String (0.0)
description: String (0.0)
timestamp: DateTime (0.0)
begin: DateTime (0.0)
end: DateTime (0.0)
altitudeMode: String (0.0)
tessellate: Integer (0.0)
extrude: Integer (0.0)
visibility: Integer (0.0)
drawOrder: Integer (0.0)
icon: String (0.0)

The KML driver can't rean zipped KML files directly but there is an easy workaround by using the GDAL vsizip-system https://trac.osgeo.org/gdal/wiki/UserDocs/ReadInZip.

Test with KML driver (notice how to skip the default LIBKML driver if both drivers are installed):

ogrinfo /vsizip/time-stamp-point.kmz -al -so --config ogr_skip libkml
ERROR 1: Random access not supported for /vsizip
Had to open data source read-only.
INFO: Open of `/vsizip/time-stamp-point.kmz'
      using driver `KML' successful.

Layer name: TimeStamp'ed Points
Geometry: 3D Point
Feature Count: 361
Extent: (-122.556706, 37.848038) - (-122.536226, 37.860470)
Layer SRS WKT:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        TOWGS84[0,0,0,0,0,0,0],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9108"]],
    AUTHORITY["EPSG","4326"]]
Name: String (0.0)
Description: String (0.0)

Notice also that KML driver finds far less attributes from the data so I would recommend to get a GDAL that has LIBKML driver.

2

You need to use the LibKML driver instead of the older KML one. This requires GDAL to be built with libkml support.

It sounds like the GDAL binaries you have don't have this support built in; according to the docs:

Note that if you build and include this LIBKML driver, it will become the default reader of KML for ogr ...

You will either need to rebuild GDAL or find a build with that support.

Or just unzip your KMZs and use the KML driver.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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