From f6955130be9c50a5b9639290832704a9cc4a182a Mon Sep 17 00:00:00 2001 From: majidrezaei93 Date: Mon, 7 Oct 2024 12:43:55 -0400 Subject: [PATCH] feat: add centroid to the attributes of the simplified building --- hub/city_model_structure/simplified_building.py | 7 ++++++- hub/imports/geometry/csv.py | 7 +++++++ hub/imports/geometry_factory.py | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hub/city_model_structure/simplified_building.py b/hub/city_model_structure/simplified_building.py index 4d49f232..d8b5b8d7 100644 --- a/hub/city_model_structure/simplified_building.py +++ b/hub/city_model_structure/simplified_building.py @@ -5,8 +5,9 @@ class SimplifiedBuilding: """ SimplifiedBuilding class """ - def __init__(self, name, total_floor_area=None, year_of_construction=None, function=None, city=None): + def __init__(self, name, centroid=None, total_floor_area=None, year_of_construction=None, function=None, city=None): self._name = name + self._centroid = centroid self._total_floor_area = total_floor_area self._year_of_construction = year_of_construction self._function = function @@ -17,6 +18,10 @@ class SimplifiedBuilding: def name(self): return self._name + @property + def centroid(self): + return self._centroid + @property def total_floor_area(self): return self._total_floor_area diff --git a/hub/imports/geometry/csv.py b/hub/imports/geometry/csv.py index 4978b375..0a62ddfa 100644 --- a/hub/imports/geometry/csv.py +++ b/hub/imports/geometry/csv.py @@ -11,11 +11,13 @@ class Csv: def __init__(self, path, + centroid=None, year_of_construction_field=None, function_field=None, function_to_hub=None, total_floor_area_field=None): self._simplified_city = None + self._centroid = centroid self._year_of_construction_field = year_of_construction_field self._function_field = function_field self._function_to_hub = function_to_hub @@ -53,6 +55,10 @@ class Csv: if self._simplified_city is None: self._simplified_city = SimplifiedCity() for row in self._csv_data: + centroid = None + if self._centroid: + centroid = self.safe_int(row[self._centroid]) + year_of_construction = None if self._year_of_construction_field: year_of_construction = self.safe_int(row[self._year_of_construction_field]) @@ -74,6 +80,7 @@ class Csv: building = SimplifiedBuilding( name=building_name, + centroid=centroid, total_floor_area=total_floor_area, year_of_construction=year_of_construction, function=function diff --git a/hub/imports/geometry_factory.py b/hub/imports/geometry_factory.py index 6e47ebfc..072dd3f6 100644 --- a/hub/imports/geometry_factory.py +++ b/hub/imports/geometry_factory.py @@ -22,6 +22,7 @@ class GeometryFactory: path=None, aliases_field=None, height_field=None, + centroid=None, year_of_construction_field=None, function_field=None, function_to_hub=None, @@ -32,6 +33,7 @@ class GeometryFactory: self._path = path self._aliases_field = aliases_field self._height_field = height_field + self._centroid = centroid self._year_of_construction_field = year_of_construction_field self._function_field = function_field self._function_to_hub = function_to_hub @@ -75,6 +77,7 @@ class GeometryFactory: @property def _csv(self) -> SimplifiedCity: return Csv(self._path, + self._centroid, self._year_of_construction_field, self._function_field, self._function_to_hub,