geopandas / pyogrio

Vectorized vector I/O using OGR
https://pyogrio.readthedocs.io
MIT License
268 stars 22 forks source link

Impossible to read KMZ file #444

Open remi-braun opened 1 month ago

remi-braun commented 1 month ago

GeoPandas 1.0+ is not able to read KMZ files with pyogrio's engine, when setting engine=fiona works:

With fiona:

gpd.read_file(
    "AOI_kmz.kmz", driver="KMZ", layer="General Information", engine="fiona"
)
>>>   Name  ...                                           geometry
>>> 0   03  ...  MULTIPOLYGON Z (((-72.31143 -36.56225 0, -72.5...
>>> [1 rows x 13 columns]

With pyogrio:

gpd.read_file(
    "AOI_kmz.kmz", driver="KMZ", layer="General Information"
)
>>>   pyogrio.errors.DataSourceError: 'AOI_kmz.kmz' not recognized as a supported file format. It might help to specify the correct driver explicitly by prefixing the file path with '<DRIVER>:', e.g. 'CSV:path'.

Here is the file: AOI_kmz.zip


Versions:

geopandas.__version__
'1.0.1'
pyogrio.__version__
'0.9.0'
fiona.__version__
'1.9.6'
martinfleis commented 1 month ago

Hi, how did you install geopandas and pyogrio? In my installation from conda-forge, the snippet above works. Can you also show thew output of pyogrio.list_drivers()?

import pyogrio

pyogrio.list_drivers()
remi-braun commented 1 month ago

The install is done via pip in a Docker (without conda) on Debian 11

The drivers are:

{'PCIDSK': 'rw', 'PDS4': 'rw', 'VICAR': 'rw', 'PDF': 'rw', 'MBTiles': 'rw', 'EEDA': 'r', 'OGCAPI': 'r', 'ESRI Shapefile': 'rw', 'MapInfo File': 'rw', 'UK .NTF': 'r', 'LVBAG': 'r', 'OGR_SDTS': 'r', 'S57': 'rw', 'DGN': 'rw', 'OGR_VRT': 'r', 'Memory': 'rw', 'CSV': 'rw', 'GML': 'rw', 'GPX': 'rw', 'KML': 'rw', 'GeoJSON': 'rw', 'GeoJSONSeq': 'rw', 'ESRIJSON': 'r', 'TopoJSON': 'r', 'OGR_GMT': 'rw', 'GPKG': 'rw', 'SQLite': 'rw', 'WAsP': 'rw', 'OpenFileGDB': 'rw', 'DXF': 'rw', 'FlatGeobuf': 'rw', 'Geoconcept': 'rw', 'GeoRSS': 'rw', 'VFK': 'r', 'PGDUMP': 'rw', 'OSM': 'r', 'GPSBabel': 'rw', 'OGR_PDS': 'r', 'WFS': 'r', 'OAPIF': 'r', 'EDIGEO': 'r', 'SVG': 'r', 'Idrisi': 'r', 'ODS': 'rw', 'XLSX': 'rw', 'Elasticsearch': 'rw', 'Carto': 'rw', 'AmigoCloud': 'rw', 'SXF': 'r', 'Selafin': 'rw', 'JML': 'rw', 'PLSCENES': 'r', 'CSW': 'r', 'VDV': 'rw', 'MVT': 'rw', 'NGW': 'rw', 'MapML': 'rw', 'GTFS': 'r', 'PMTiles': 'rw', 'JSONFG': 'rw', 'TIGER': 'r', 'AVCBin': 'r', 'AVCE00': 'r', 'HTTP': 'r'}

remi-braun commented 1 month ago

KML files are read fine, only KMZ files fail

martinfleis commented 1 month ago

I think that the reason is that the PyPI wheels contain the KML driver while the conda-forge contain LIBKML driver.

remi-braun commented 1 month ago

Is there a workaround to replicate the conda behaviour natively with pypi?

theroggy commented 1 month ago

You can normally prepend the filename with "/vsizip/" to use the virtual filesystem feature of GDAL to do the unzipping.

I wonder if there is something wrong with the test file you uploaded... because for another .kmz this workaround works, but not for your test file.

import geopandas as gpd

print(gpd.read_file(r"/vsizip/C:/Temp/example.kmz"))
remi-braun commented 1 month ago

This file has been part of the test suite for years and worked :'(

I have other KMZ that fails too, so maybe there is an issue inside that is weird?

Unfortunately, the /vsizip/ workaround fails too for me

theroggy commented 1 month ago

This file has been part of the test suite for years and worked :'(

Hmm... indeed, I can open it without problems in e.g. QGIS, so apparently the "KML" driver doesn't only limit the support to uncompressed .kml files but also to a subset of them... so it seems you'll really need the "LIBKML" driver.