From df2d7a3054638b73a94a981b0607ac8f61e4d922 Mon Sep 17 00:00:00 2001 From: s_ranjbar Date: Wed, 24 Jul 2024 10:26:45 -0400 Subject: [PATCH] Geojson class modified for the geojson format Guille suggested --- hub/imports/geometry/geojson.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/hub/imports/geometry/geojson.py b/hub/imports/geometry/geojson.py index 888045ad..6680b6b6 100644 --- a/hub/imports/geometry/geojson.py +++ b/hub/imports/geometry/geojson.py @@ -3,7 +3,6 @@ Geojson module parses geojson files and import the geometry into the city model SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2022 Concordia CERC group Project Coder Guillermo Gutierrez Guillermo.GutierrezMorote@concordia.ca -Project Collaborator Saeed Ranjbar saeed.ranjbar@concordia.ca """ import uuid @@ -130,16 +129,24 @@ class Geojson: function = str(feature['properties'][self._function_field]) if function == 'Mixed use' or function == 'mixed use': function_parts = [] - for key, value in feature['properties'].items(): - if key.startswith("mixed_type_") and not key.endswith("_percentage"): - type_key = key - percentage_key = f"{key}_percentage" - if percentage_key in feature['properties']: - if self._function_to_hub is not None and feature['properties'][type_key] in self._function_to_hub: - usage_function = self._function_to_hub[feature['properties'][type_key]] - function_parts.append(f"{feature['properties'][percentage_key]}-{usage_function}") - else: - function_parts.append(f"{feature['properties'][percentage_key]}-{feature['properties'][type_key]}") + if 'usages' in feature['properties']: + usages = feature['properties']['usages'] + for usage in usages: + if self._function_to_hub is not None and usage['usage'] in self._function_to_hub: + function_parts.append(f"{usage['percentage']}-{self._function_to_hub[usage['usage']]}") + else: + function_parts.append(f"{usage['percentage']}-{usage['usage']}") + else: + for key, value in feature['properties'].items(): + if key.startswith("mixed_type_") and not key.endswith("_percentage"): + type_key = key + percentage_key = f"{key}_percentage" + if percentage_key in feature['properties']: + if self._function_to_hub is not None and feature['properties'][type_key] in self._function_to_hub: + usage_function = self._function_to_hub[feature['properties'][type_key]] + function_parts.append(f"{feature['properties'][percentage_key]}-{usage_function}") + else: + function_parts.append(f"{feature['properties'][percentage_key]}-{feature['properties'][type_key]}") function = "_".join(function_parts) if self._function_to_hub is not None: # use the transformation dictionary to retrieve the proper function