""" TestGeometryFactory test and validate the city model structure geometric parameters SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ import os from pathlib import Path from unittest import TestCase from city_model_structure.city import City from imports.geometry_factory import GeometryFactory class TestGeometryFactory(TestCase): """ TestGeometryFactory TestCase 1 """ def setUp(self) -> None: """ Test setup :return: None """ self._city_gml = None self._example_path = (Path(__file__).parent / 'tests_data').resolve() def _get_citygml(self, file): if self._city_gml is None: file_path = (self._example_path / file).resolve() self._city_gml = GeometryFactory('citygml', file_path).city self.assertIsNotNone(self._city_gml, 'city is none') return self._city_gml def test_citygml_city_serialization(self): """ Test the City from citygml serialization de-serialization :return: None """ file = 'lod2_buildings.gml' pickle_file = (self._example_path / 'lod2_buildings.pickle').resolve() city = self._get_citygml(file) self.assertIsNotNone(city.city_objects, 'city_objects is none') for building in city.buildings: self.assertIsNotNone(city.city_object(building.name), 'city_object return none') self.assertIsNotNone(city.srs_name, 'srs_name is none') self.assertIsNotNone(city.lower_corner, 'lower_corner is none') self.assertIsNotNone(city.upper_corner, 'upper_corner is none') self.assertIsNotNone(city.name, 'name is none') self.assertIsNotNone(city.country_code, 'country code is none') city.save(pickle_file) city = City.load(pickle_file) # repeat the city tests self.assertIsNotNone(city.city_objects, 'city_objects is none') for building in city.buildings: self.assertIsNotNone(city.city_object(building.name), 'city_object return none') self.assertIsNotNone(city.srs_name, 'srs_name is none') self.assertIsNotNone(city.lower_corner, 'lower_corner is none') self.assertIsNotNone(city.upper_corner, 'upper_corner is none') self.assertIsNotNone(city.name, 'name is none') self.assertIsNotNone(city.country_code, 'country code is none') os.remove(pickle_file) def test_surfaces_triangulation(self): """ Test city surfaces triangulation and polygon creation :return: """ file = (self._example_path / 'gml_17_12_2020.gml').resolve() city = GeometryFactory('citygml', file).city counter = 0 for building in city.buildings: if str(building.volume) == 'inf': counter += 1 self.assertEqual(counter, 1, f'{counter} buildings had errors when triangulating surfaces')