3

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?

2

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

>>>import fiona
>>>fiona.supported_drivers
{'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'}
2

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:
<snip>
OGRFeature(Data):1
  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
  <snip>
  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))
<snip>
  • 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
1

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

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.