I downloaded a NOAA-provided KMZ file (link). When I point geopandas at the file:

gpd.read_file("/Users/abilogur/Downloads/NSIDC_SepSeaIceExtent.kmz", driver="KMZ")

I get:

FionaValueError: No dataset found at path '/Users/abilogur/Downloads/NSIDC_SepSeaIceExtent.kmz' using drivers: {'KMZ'}

But when I check if the file exists via Python standard lib (import os; os.path.exists('/Users/abilogur/Downloads/NSIDC_SepSeaIceExtent.kmz')) I get True, implying that it does.

What issue am I suffering from?


I'm afraid that in fiona there is not supported any "kmz" driver.

>>>import fiona
{'ESRI Shapefile': 'raw', 'SUA': 'r', 'ARCGEN': 'r', 'PDS': 'r', 'GeoJSON': 'rw', 
'Idrisi': 'r', 'GPX': 'raw', 'SEGY': 'r', 'BNA': 'raw', 'GMT': 'raw', 'AeronavFAA': 'r', 
'GPSTrackMaker': 'raw', 'DGN': 'raw', 'PCIDSK': 'r', 'MapInfo File': 'raw', 'DXF': 'raw'}

I suggest you download the data in geospatial vector or raster format, a quick look shows the sea ice extent is available in GeoTIFF and shapefile format

If you want to do things the hard way and get some data out of the KMZ, read on.

GDAL/OGR (2.1.2) can't read** that particular KMZ, which means fiona, geopandas and probably rasterio can't either.

Amongst other stuff (html popups and icons), that KMZ is full of GroundOverlay elements pointing at .png files.

You could extract the pngs from the KMZ (it's just a zip file) and georeference them.

For example:

gdal_translate -of VRT -a_srs EPSG:4326 -gcp 0 0 -180 90 -gcp 600 0 180 90 -gcp 600 900 180 -90 NSIDC_SepSeaIceExtent.kmz_FILES/images/goddard/199709_extn_google_v2.1_goddard.png 199709.vrt

Here is a screenshot of 199709.vrt overlaid on the NASA Blue Marble dataset, with sea ice extent shown in bright green (custom rendering in QGIS, just to highlight the data).

enter image description here

** Actually GDAL/OGR can read the bounding boxes of the GroundOverlay elements, but that's not going to help you much... They cover the world.

ogrinfo NSIDC_SepSeaIceExtent.kmz data
ERROR 1: ERROR parsing kml Style: No id
INFO: Open of `NSIDC_SepSeaIceExtent.kmz'
      using driver `LIBKML' successful.

Layer name: Data
Geometry: Unknown (any)
Feature Count: 38
Extent: (-180.000000, -90.000000) - (180.000000, 90.000000)
Layer SRS WKT:
  Name (String) = 197909 
  description (String) = (null)
  timestamp (DateTime) = (null)
  begin (DateTime) = 1979/01/01 00:00:00
  end (DateTime) = 1980/01/01 00:00:00
  icon (String) = images/goddard/197909_extn_google_v2.1_goddard.png
  POLYGON Z ((180 90 0,180 -90 0,-180 -90 0,-180 90 0,180 90 0))
  • While the other answer is the correct answer for this question, I found this most helpful. It's a shame they're releasing this data in such a junky format. – Aleksey Bilogur Sep 25 '17 at 15:59

Two steps: (1) enable KML drivers for fiona: fiona.drvsupport.supported_drivers['kml'] = 'rw' # enable KML support fiona.drvsupport.supported_drivers['KML'] = 'rw'

(2) Unzip the KMZ file to find the embedded KML file (my example assumes this to be called doc.kml but that may not always be the case) from zipfile import ZipFile kmz = ZipFile(kmlFilename, 'r') kmz.extract('doc.kml', tempDir)

Now you should be able to open the kml file with fiona, or geopandas etc import geopandas as gpd gdf = gpd.read_file(os.path.join(tempDir,'doc.kml'))


Looks like you can directly access the contents of a KMZ file using the Virtual File System Zip driver:

with fiona.open('/vsizip/' + path_to_KMZ + '/' + file_within_archive) as source:

Ref: * https://fiona.readthedocs.io/en/latest/manual.html#virtual-filesystems * https://gdal.org/user/virtual_file_systems.html (Using fiona v1.18.13)

Your Answer

