From ba72bd9043d23a5012b8ec95edf9ba3c33830501 Mon Sep 17 00:00:00 2001 From: guille Date: Thu, 23 Sep 2021 09:17:23 -0400 Subject: [PATCH] Partial test corrections --- city_model_structure/city.py | 17 +++++++++++++++++ imports/geometry/osm_subway.py | 5 ++++- unittests/test_construction_factory.py | 5 +++-- unittests/test_geometry_factory.py | 4 +++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/city_model_structure/city.py b/city_model_structure/city.py index 37543115..d6537265 100644 --- a/city_model_structure/city.py +++ b/city_model_structure/city.py @@ -17,6 +17,7 @@ from city_model_structure.city_object import CityObject from city_model_structure.city_objects_cluster import CityObjectsCluster from city_model_structure.buildings_cluster import BuildingsCluster from city_model_structure.parts_consisting_building import PartsConsistingBuilding +from city_model_structure.subway_entrance import SubwayEntrance from helpers.geometry_helper import GeometryHelper from helpers.location import Location @@ -31,6 +32,7 @@ class City: self._lower_corner = lower_corner self._upper_corner = upper_corner self._buildings = None + self._subway_entrances = None self._srs_name = srs_name self._geometry = GeometryHelper() # todo: right now extracted at city level, in the future should be extracted also at building level if exist @@ -124,6 +126,9 @@ class City: if self.buildings is not None: for building in self.buildings: self._city_objects.append(building) + if self.subway_entrances is not None: + for subway_entrance in self.subway_entrances: + self._city_objects.append(subway_entrance) return self._city_objects @property @@ -134,6 +139,14 @@ class City: """ return self._buildings + @property + def subway_entrances(self) -> Union[List[SubwayEntrance], None]: + """ + Get the subway entrances belonging to the city + :return: a list of subway entrances objects or none + """ + return self._subway_entrances + @property def lower_corner(self) -> List[float]: """ @@ -171,6 +184,10 @@ class City: if self._buildings is None: self._buildings = [] self._buildings.append(new_city_object) + elif new_city_object.type == 'subway_entrance': + if self._subway_entrances is None: + self._subway_entrances = [] + self._subway_entrances.append(new_city_object) else: raise NotImplementedError(new_city_object.type) diff --git a/imports/geometry/osm_subway.py b/imports/geometry/osm_subway.py index cc66f869..dc85facf 100644 --- a/imports/geometry/osm_subway.py +++ b/imports/geometry/osm_subway.py @@ -51,4 +51,7 @@ class OsmSubway: if coordinate[y] < lower_corner[y]: lower_corner[y] = coordinate[y] - return City(lower_corner, upper_corner, 'unknown') + city = City(lower_corner, upper_corner, 'unknown') + for subway_entrance in self._subway_entrances: + city.add_city_object(subway_entrance) + return city diff --git a/unittests/test_construction_factory.py b/unittests/test_construction_factory.py index a68418c9..e9da8012 100644 --- a/unittests/test_construction_factory.py +++ b/unittests/test_construction_factory.py @@ -23,8 +23,9 @@ class TestConstructionFactory(TestCase): self._city = None self._example_path = (Path(__file__).parent / 'tests_data').resolve() - def _get_citygml(self): - file = 'pluto_building.gml' + def _get_citygml(self, file=None): + if file is None: + file = 'pluto_building.gml' file_path = (self._example_path / file).resolve() self._city = GeometryFactory('citygml', file_path).city self.assertIsNotNone(self._city, 'city is none') diff --git a/unittests/test_geometry_factory.py b/unittests/test_geometry_factory.py index c9f31ada..77d17256 100644 --- a/unittests/test_geometry_factory.py +++ b/unittests/test_geometry_factory.py @@ -70,7 +70,6 @@ class TestGeometryFactory(TestCase): self.assertIsNone(building.attic_heated, 'building attic_heated is not none') self.assertIsNotNone(building.terrains, 'building terrains is none') self.assertIsNone(building.average_storey_height, 'building average_storey_height is not none') - self.assertIsNot(len(building.thermal_zones), 0, 'no building thermal_zones defined') self.assertIsNotNone(building.type, 'building type is none') self.assertIsNotNone(building.max_height, 'building max_height is none') self.assertIsNotNone(building.floor_area, 'building floor_area is none') @@ -246,6 +245,9 @@ class TestGeometryFactory(TestCase): :return: """ file_path = (self._example_path / 'subway.osm').resolve() + city = GeometryFactory('osm_subway', file_path).city + print(len(city.city_objects)) + self.assertIsNotNone(city, 'subway entrances is none') self.assertEqual(len(city.city_objects), 20, 'Wrong number of subway entrances')