system_assignation/tests/test_geometry_factory.py

76 lines
2.8 KiB
Python
Raw Normal View History

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
Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
2020-06-09 14:07:47 -04:00
"""
import os
2020-05-29 07:25:33 -04:00
from pathlib import Path
from unittest import TestCase
from city_model_structure.city import City
from imports.geometry_factory import GeometryFactory
2020-05-29 07:25:33 -04:00
class TestGeometryFactory(TestCase):
"""
2020-10-21 09:16:29 -04:00
TestGeometryFactory TestCase 1
"""
2020-05-29 07:25:33 -04:00
def setUp(self) -> None:
"""
Test setup
:return: None
"""
2020-05-29 07:25:33 -04:00
self._city_gml = None
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-12-15 11:10:25 -05:00
Test the City from citygml serialization de-serialization
: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')
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)
# 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-03-15 11:47:30 -04:00
def test_surfaces_triangulation(self):
"""
Test city surfaces triangulation and polygon creation
:return:
"""
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-27 16:08:11 -05:00
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')