Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnsupportedGeometryTypeError in Fiona 1.8.22 #1155

Closed
sehHeiden opened this issue Oct 21, 2022 · 10 comments
Closed

UnsupportedGeometryTypeError in Fiona 1.8.22 #1155

sehHeiden opened this issue Oct 21, 2022 · 10 comments

Comments

@sehHeiden
Copy link

Expected behavior and actual behavior.

Opening the file. Is working wit some files. Others raises the error below:

Steps to reproduce the problem.

open the file with geopandas' read_file

Operating system

OS Ubuntu 20.04 derivative

Fiona and GDAL version and provenance

installed with mamba 0.27.0:
fiona 1.8.2.2
gdal 3.5.2
Example Shape File: LoD1_23445938.zip
(1/3 of the LoD1 files (by Lower Saxony (open Data)) I tried did not open). But this example opens in QGIS.



  File "fiona/ogrext.pyx", line 1515, in fiona.ogrext.Iterator.__next__
  File "fiona/ogrext.pyx", line 317, in fiona.ogrext.FeatureBuilder.build
  File "fiona/_geometry.pyx", line 187, in fiona._geometry.GeomBuilder.build
  File "fiona/_geometry.pyx", line 168, in fiona._geometry.GeomBuilder._buildGeometryCollection
  File "fiona/_geometry.pyx", line 169, in fiona._geometry.GeomBuilder._buildGeometryCollection
  File "fiona/_geometry.pyx", line 149, in fiona._geometry.GeomBuilder._buildParts
  File "fiona/_geometry.pyx", line 182, in fiona._geometry.GeomBuilder.build
fiona.errors.UnsupportedGeometryTypeError: 16
@jorisvandenbossche
Copy link
Member

Do you know what type of geometries you have stored in the file? The error indicates that fiona received a geometry type it doesn't support (16 typically indicates TIN, https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary)

@sehHeiden
Copy link
Author

sehHeiden commented Oct 21, 2022

QGIS states MultiPolygonZ, which makes sence for LoD1. I could open about 66 %. (I added an example in my first post).
Source is: https://opengeodata.lgln.niedersachsen.de/

@jorisvandenbossche
Copy link
Member

Using ogrinfo -al LoD1_23445938_2_2021-01-19.shp from the command line, there are indeed TIN geometries included in GeometryCollections (most of the geoemtries are MultiPolygons, a few of those mixed collections):

...
OGRFeature(LoD1_23445938_2_2021-01-19):102
  ALKISOID (String) = http://repository.gdi-de.org/schemas/adv/citygml/fdv/art.htm#_9100$$$DENILD23000004Fa
  GEBID (String) = DENILD1513150232765_22741340
  NAME (String) = (null)
  FUNKTION (String) = 31001_1000
  AGS (String) = 03457002
  ABLDATUM (String) = 2021-01-19
  BPDACH (Integer64) = 0
  DQDACH (Integer64) = 1000
  DQLAGE (Integer64) = 1000
  DQBODEN (Integer64) = 1400
  DACHFORM (Integer64) = 1000
  HOEHEGEB (Real) = 6.62200000000
  HOEHEBD (Real) = 5.01000000000
  HOEHETRAUF (Real) = 11.63200000000
  HOEHEFIRST (Real) = 11.63200000000
  GEMEINDE (String) = (null)
  LAGEHNR (String) = (null)
  GEOMETRYCOLLECTION Z (TIN Z (((345359.106 5939644.725 11.632,345365.457 5939641.258 11.632,345365.433 5939641.213 11.632,345359.106 5939644.725 11.632))),TIN Z (((345365.457 5939641.258 5.01,345359.106 5939644.725 5.01,345365.433 5939641.213 5.01,345365.457 5939641.258 5.01))),MULTIPOLYGON Z (((345365.432999997 5939641.21299999 11.632,345359.106 5939644.725 11.632,345359.106 5939644.725 11.0475,345361.999827903 5939643.11868996 11.0475,345365.432999997 5939641.213 11.0475,345365.432999997 5939641.21299999 11.632)),((345365.457 5939641.258 11.632,345365.457 5939641.258 5.01,345359.106000042 5939644.72500008 5.01,345359.106000042 5939644.72500008 11.632,345365.457 5939641.258 11.632)),((345365.433 5939641.213 11.632,345365.433 5939641.213 5.01,345365.456999999 5939641.258 5.01,345365.456999999 5939641.258 11.632,345365.433 5939641.213 11.632)),((345361.999827903 5939643.11868996 11.0475,345359.106 5939644.725 11.0475,345359.106 5939644.725 5.01,345361.999827903 5939643.11868996 5.01,345361.999827903 5939643.11868996 11.0475)),((345365.432999997 5939641.213 11.0475,345361.999827903 5939643.11868996 11.0475,345361.999827903 5939643.11868996 5.01,345365.432999997 5939641.213 5.01,345365.432999997 5939641.213 11.0475))))
...

@jorisvandenbossche
Copy link
Member

QGIS states MultiPolygonZ,

QGIS automatically maps TIN to MultiPolygon (https://gdal.org/development/rfc/rfc64_triangle_polyhedralsurface_tin.html, qgis/QGIS#5298). Something similar could probably be done for Fiona (or optionally)

@rbuffat
Copy link
Contributor

rbuffat commented Oct 21, 2022

There should be support for converting TIN's to MultiPolygon:
https://github.com/Toblerity/Fiona/blob/master/tests/test_rfc64_tin.py

Thus, there might be something not working as intended.

@jorisvandenbossche
Copy link
Member

Ah, wasn't aware that this was already supported. Indeed I can read the test file that is included in Fiona:

In [1]: geopandas.read_file("Fiona/tests/data/test_tin.shp")
Out[1]: 
  id                                           geometry
0  1  MULTIPOLYGON Z (((0.00000 0.00000 0.00000, 0.0...

But so with the same Fiona install, reading the file provided here results in the UnsupportedGeometryTypeError: 16 error. So something else is still going wrong.

Maybe the issue here is that it's actually a GeometryCollection containing a TIN? So the type code of the actual geometry is not 16 for TIN, but 7 for GeometryCollection. For that reason, it's not converted on the GDAL, and then when actually converting the geometry in the GeomBuilder class, it sees TIN as one of the parts (so also in _buildParts, we should again check the type code and potentially convert TIN to MultiPolygon, if we want to support this case)

@rbuffat
Copy link
Contributor

rbuffat commented Oct 21, 2022

I will have a look at it probably on Sunday. On first glance it looks strange that if code = 16 on line 296, then line 317 is executed.

@jorisvandenbossche
Copy link
Member

t looks strange that if code = 16 on line 296, then line 317 is executed.

Yes, but so it is not code 16 on line 296, at that point it is a GeometryCollection, so code 7

@rbuffat
Copy link
Contributor

rbuffat commented Oct 21, 2022

@jorisvandenbossche thanks, now it makes sense! It looks as if the code in https://github.com/Toblerity/Fiona/blob/maint-1.8/fiona/ogrext.pyx#L298-L311 needs to be also in https://github.com/Toblerity/Fiona/blob/master/fiona/_geometry.pyx#L148, or better refactored that it is only in one place, e.g. in GeomBuilder.build.

@sgillies
Copy link
Member

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants