2020-06-09 14:07:47 -04:00
|
|
|
"""
|
|
|
|
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
|
2021-04-07 11:47:39 -04:00
|
|
|
Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
2020-06-09 14:07:47 -04:00
|
|
|
"""
|
2020-06-11 16:55:52 -04:00
|
|
|
import os
|
2020-05-29 07:25:33 -04:00
|
|
|
from pathlib import Path
|
2020-06-16 10:34:17 -04:00
|
|
|
from unittest import TestCase
|
2020-12-02 11:56:33 -05:00
|
|
|
from city_model_structure.city import City
|
2021-03-02 18:57:09 -05:00
|
|
|
from imports.geometry_factory import GeometryFactory
|
2020-05-29 07:25:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TestGeometryFactory(TestCase):
|
2020-06-11 15:45:11 -04:00
|
|
|
"""
|
2020-10-21 09:16:29 -04:00
|
|
|
TestGeometryFactory TestCase 1
|
2020-06-11 15:45:11 -04:00
|
|
|
"""
|
2020-05-29 07:25:33 -04:00
|
|
|
def setUp(self) -> None:
|
2020-06-11 15:45:11 -04:00
|
|
|
"""
|
|
|
|
Test setup
|
|
|
|
:return: None
|
|
|
|
"""
|
2020-05-29 07:25:33 -04:00
|
|
|
self._city_gml = None
|
2021-03-16 12:33:22 -04:00
|
|
|
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
2020-05-29 07:25:33 -04:00
|
|
|
|
2021-03-15 11:47:30 -04:00
|
|
|
def _get_citygml(self, file):
|
2020-05-29 07:25:33 -04:00
|
|
|
if self._city_gml is None:
|
2021-03-15 11:47:30 -04:00
|
|
|
file_path = (self._example_path / file).resolve()
|
2021-04-07 14:39:50 -04:00
|
|
|
self._city_gml = GeometryFactory('citygml', file_path).city
|
2020-05-29 07:25:33 -04:00
|
|
|
self.assertIsNotNone(self._city_gml, 'city is none')
|
|
|
|
return self._city_gml
|
|
|
|
|
2020-12-15 11:10:25 -05:00
|
|
|
def test_citygml_city_serialization(self):
|
2020-06-11 15:45:11 -04:00
|
|
|
"""
|
2021-06-04 09:22:06 -04:00
|
|
|
Test the City from citygml_classes serialization de-serialization
|
2020-06-11 15:45:11 -04:00
|
|
|
:return: None
|
|
|
|
"""
|
2021-03-15 11:47:30 -04:00
|
|
|
file = 'lod2_buildings.gml'
|
|
|
|
pickle_file = (self._example_path / 'lod2_buildings.pickle').resolve()
|
|
|
|
city = self._get_citygml(file)
|
2020-06-22 13:26:50 -04:00
|
|
|
self.assertIsNotNone(city.city_objects, 'city_objects is none')
|
2020-06-26 10:06:43 -04:00
|
|
|
for building in city.buildings:
|
|
|
|
self.assertIsNotNone(city.city_object(building.name), 'city_object return none')
|
2020-05-29 07:25:33 -04:00
|
|
|
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')
|
2020-06-04 12:47:48 -04:00
|
|
|
self.assertIsNotNone(city.country_code, 'country code is none')
|
2021-03-15 11:47:30 -04:00
|
|
|
city.save(pickle_file)
|
|
|
|
city = City.load(pickle_file)
|
2020-12-02 11:56:33 -05:00
|
|
|
# repeat the city tests
|
2020-12-01 16:29:20 -05:00
|
|
|
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')
|
2021-03-15 11:47:30 -04:00
|
|
|
os.remove(pickle_file)
|
2021-01-13 12:24:02 -05:00
|
|
|
|
2021-03-15 11:47:30 -04:00
|
|
|
def test_surfaces_triangulation(self):
|
|
|
|
"""
|
|
|
|
Test city surfaces triangulation and polygon creation
|
|
|
|
:return:
|
|
|
|
"""
|
2021-04-07 10:33:05 -04:00
|
|
|
file = (self._example_path / 'gml_17_12_2020.gml').resolve()
|
2021-04-07 14:39:50 -04:00
|
|
|
city = GeometryFactory('citygml', file).city
|
2021-01-13 12:24:02 -05:00
|
|
|
|
2021-01-27 16:08:11 -05:00
|
|
|
counter = 0
|
|
|
|
for building in city.buildings:
|
2021-04-08 11:47:58 -04:00
|
|
|
if str(building.volume) == 'inf':
|
|
|
|
counter += 1
|
|
|
|
self.assertEqual(counter, 1, f'{counter} buildings had errors when triangulating surfaces')
|
2021-03-01 16:42:03 -05:00
|
|
|
|