cityjson / cityjson-qgis-plugin

A QGIS plugin that adds support for CityJSON files
Apache License 2.0
35 stars 8 forks source link

Breaks on CityObject without geometry #43

Closed balazsdukai closed 2 years ago

balazsdukai commented 2 years ago

From CityJSON v1.1 the geometry property is not mandatory anymore for CityObjects. If this is the case, the plugin breaks:

Traceback (most recent call last):
  File "/home/balazs/.local/share/QGIS/QGIS3/profiles/balazs/python/plugins/CityJSON-loader/cityjson_loader.py", line 301, in run
    self.load_cityjson(filepath)
  File "/home/balazs/.local/share/QGIS/QGIS3/profiles/balazs/python/plugins/CityJSON-loader/cityjson_loader.py", line 323, in load_cityjson
    skipped_geometries = loader.load()
  File "/home/balazs/.local/share/QGIS/QGIS3/profiles/balazs/python/plugins/CityJSON-loader/core/loading.py", line 114, in load
    self.layer_manager.add_object(key, obj)
  File "/home/balazs/.local/share/QGIS/QGIS3/profiles/balazs/python/plugins/CityJSON-loader/core/layers.py", line 55, in add_object
    new_features = self._feature_builder.create_features(self._fields, object_key, cityobject)
  File "/home/balazs/.local/share/QGIS/QGIS3/profiles/balazs/python/plugins/CityJSON-loader/core/layers.py", line 230, in create_features
    geom = self._geometry_reader.read_geometry(cityobject["geometry"])
KeyError: 'geometry'

File: DH_01_subs.zip

liberostelios commented 2 years ago

Thanks for reporting this! How do you think this should be better tackled? Create no feature at all, or create on with an empty geometry?

balazsdukai commented 2 years ago

If qgis allows empty geometries I think it would be good to create features with an empty geometry. That is in case the CO has attributes, they'll be added to the feature.

liberostelios commented 2 years ago

I decided to go with the latter option (load with empty geometries). There is only a issue, for now, that if you split features per LoD then all features without a geometry will be excluded (as there is no LoD to load these features at).

Nevertheless, this is now fixed and the fix is included in the latest release.

You can install it here or wait for the new version to be approved in the repository soon and upgrade from within QGIS plugin manager.

Thanks for reporting this again! :raised_hands: