Fiona icon indicating copy to clipboard operation
Fiona copied to clipboard

UnsupportedGeometryTypeError (16) with shape file from open data base.

Open uvchik opened this issue 2 years ago • 3 comments

Expected behavior and actual behavior.

I expected to be able read a 3D shapefile (via zip) downloaded from the open geodata base of Lower Saxonia in Germany as I am able to open it in QGIS (v3.26.0).

https://opengeodata.lgln.niedersachsen.de/#lod2

By the way it works if I open the file with QGIS and store the file with QGIS, so it seems that QGIS is fixing something simple by using load/store.

I was not able to find the problematic geometry.

Geometry type 16 lead me to PR #679 so it should be fixed in my Fiona versions (1.8.21 or 1.9a2). See: https://github.com/Toblerity/Fiona/blob/9c8fe736d4381526905c6976c399a33d10e3ecbf/fiona/ogrext.pyx#L301-L320

Steps to reproduce the problem.

Download the following zip-test-file.

import geopandas as gpd

fn = "path/to/downloaded/file/LoD2_25505804_2_2020-11-19.zip"
gpd.read_file(fn)

Reading the file leads to:

Traceback (most recent call last):
  File "open_geo_data_test.py", line 72, in <module>
    maps.append(gpd.read_file(shp_filename))
  File "...\site-packages\geopandas\io\file.py", line 253, in _read_file
    return _read_file_fiona(
  File "...\site-packages\geopandas\io\file.py", line 340, in _read_file_fiona
    df = GeoDataFrame.from_features(
  File "...\site-packages\geopandas\geodataframe.py", line 640, in from_features
    for feature in features_lst:
  File "fiona\ogrext.pyx", line 1658, in fiona.ogrext.Iterator.__next__
  File "fiona\ogrext.pyx", line 384, in fiona.ogrext.FeatureBuilder.build
  File "fiona\_geometry.pyx", line 159, in fiona._geometry.GeomBuilder.build
  File "fiona\_geometry.pyx", line 140, in fiona._geometry.GeomBuilder._buildGeometryCollection
  File "fiona\_geometry.pyx", line 141, in fiona._geometry.GeomBuilder._buildGeometryCollection
  File "fiona\_geometry.pyx", line 121, in fiona._geometry.GeomBuilder._buildParts
  File "fiona\_geometry.pyx", line 154, in fiona._geometry.GeomBuilder.build
fiona.errors.UnsupportedGeometryTypeError: 16

As it seems to be an exception raised by fiona I posted it here even though I used fiona via geopandas.

Operating system

Windows 10

Fiona and GDAL version and provenance

Fiona 1.8.21 with pip 22.2.2

and

Fiona 1.9a2 with pip 22.2.2

uvchik avatar Aug 04 '22 10:08 uvchik

@uvchik thank you for the report. Geometry type 16 is OGR's "wkbTIN" type, which has no GeoJSON representation and thus is outside the capabilities of Fiona versions 1.8 and lower. We might be able to do something about this in version 1.9.0. The features in this shapefile are essentially polygons, yes?

sgillies avatar Aug 04 '22 13:08 sgillies

The features in this shapefile are essentially polygons, yes?

Thank you, @sgillies for your answer. Yes, Polygons or MultiPolygons.

uvchik avatar Aug 05 '22 07:08 uvchik

with fiona.version 1.8.13.post1 I got a similar error on open data from Institut National Geographique, and Type is a strange number - Also 789, another user report the features with the None geometry now indicate a 2**31 code (0x80000000): 2147483648

It occurs for 18 layers, and as the read fails, I have no data in gdf, but for 7/ 25 layers of this geopackage for BDT3.0. You may reproduce it with:


# download and extract data for Département 76 - Seine-Maritime :
https://wxs.ign.fr/859x8t863h6a09o9o6fy4v60/telechargement/prepackage/BDTOPOV3-TOUSTHEMES-DEPARTEMENT_GPKG_PACK_222$BDTOPO_3-0_TOUSTHEMES_GPKG_LAMB93_D076_2022-06-15/file/BDTOPO_3-0_TOUSTHEMES_GPKG_LAMB93_D076_2022-06-15.7z


dir = 'BDT_3-0_GPKG_LAMB93_D034-ED2022-06-15'
key='batiment' 
gdf = gpd.read_file(Path(dir, os.path.basename(dir)+'.gpkg'), layer=key)


fiona/ogrext.pyx in fiona.ogrext.Session.get_schema()
fiona/_geometry.pyx in fiona._geometry.normalize_geometry_type_code()

UnsupportedGeometryTypeError: 2147483648

Other geopackage from that source with same layers were loaded correctly. I expect fiona to warn for unsupported data, but not fail the load. I am interested in workaround to ignore and possibly count these data rows, to check if this is just a few missing geometry or a more consistent problem.

bardout avatar Aug 09 '22 16:08 bardout