forked from s_ranjbar/city_retrofit
added region to city.py
This commit is contained in:
parent
043eecf814
commit
6f58fde55b
|
@ -14,6 +14,7 @@ from pyproj import Transformer
|
|||
from city_model_structure.building import Building
|
||||
from city_model_structure.city_object import CityObject
|
||||
from helpers.geometry_helper import GeometryHelper
|
||||
import math
|
||||
|
||||
|
||||
class City:
|
||||
|
@ -183,3 +184,21 @@ class City:
|
|||
"""
|
||||
with open(city_filename, 'wb') as f:
|
||||
pickle.dump(self, f)
|
||||
|
||||
def region(self, center, radius):
|
||||
"""
|
||||
Save a city into the given filename
|
||||
:param center: specific point in space [x, y, z]
|
||||
:param radius: distance to center of the sphere selected in meters
|
||||
:return: selected_region_city
|
||||
"""
|
||||
selected_region_lower_corner = [center[0] - radius, center[1] - radius, center[2] - radius]
|
||||
selected_region_upper_corner = [center[0] + radius, center[1] + radius, center[2] + radius]
|
||||
selected_region_city = City(selected_region_lower_corner, selected_region_upper_corner, srs_name=self.srs_name)
|
||||
for city_object in self.city_objects:
|
||||
location = city_object.location
|
||||
distance = math.sqrt(math.pow(location[0]-center[0], 2) + math.pow(location[1]-center[1], 2)
|
||||
+ math.pow(location[2]-center[2], 2))
|
||||
if distance < radius:
|
||||
selected_region_city.add_city_object(city_object)
|
||||
return selected_region_city
|
||||
|
|
|
@ -9,7 +9,6 @@ from unittest import TestCase
|
|||
|
||||
from city_model_structure.city import City
|
||||
from factories.geometry_factory import GeometryFactory
|
||||
from helpers.geometry_helper import GeometryHelper
|
||||
|
||||
|
||||
class TestGeometryFactory(TestCase):
|
||||
|
@ -23,7 +22,7 @@ class TestGeometryFactory(TestCase):
|
|||
"""
|
||||
self._city_gml = None
|
||||
self._example_path = (Path(__file__).parent.parent / 'tests_data').resolve()
|
||||
self._pickle_file = (self._example_path / 'city_new.pickle').resolve()
|
||||
self._pickle_file = (self._example_path / 'kelowna_test_case.pickle').resolve()
|
||||
self._kelowna_pickle_file = (self._example_path / 'kelowna_test_case.pickle').resolve()
|
||||
self._output_path = (Path(__file__).parent / 'surface_outputs').resolve()
|
||||
|
||||
|
@ -74,22 +73,6 @@ class TestGeometryFactory(TestCase):
|
|||
def test_surfaces_triangulation(self):
|
||||
"""
|
||||
Test city surfaces triangulation and polygon creation
|
||||
:return:
|
||||
"""
|
||||
city = City.load(self._kelowna_pickle_file)
|
||||
helper = GeometryHelper(delta=0.0, area_delta=0.0)
|
||||
errors = 0
|
||||
for building in city.buildings:
|
||||
print(building.name)
|
||||
building._polyhedron._geometry = helper
|
||||
if str(building.volume) == 'inf':
|
||||
building.stl_export(self._output_path)
|
||||
errors += 1
|
||||
print(f'{errors} buildings aren\'t closed volumes')
|
||||
|
||||
def test_volume(self):
|
||||
"""
|
||||
|
||||
:return:
|
||||
"""
|
||||
print(self._pickle_file)
|
||||
|
@ -242,3 +225,19 @@ class TestGeometryFactory(TestCase):
|
|||
self.assertIsNone(thermal_opening.thickness, 'thermal_opening thickness_m was initialized')
|
||||
self.assertRaises(Exception, lambda: thermal_opening.u_value, 'thermal_opening u_value was initialized')
|
||||
|
||||
def test_stuttgart_gml(self):
|
||||
|
||||
file_path = (self._example_path / '20190815_mitte_out_MC_FloursurfaceADD.gml').resolve()
|
||||
city = GeometryFactory('citygml', file_path).city
|
||||
pickle_file = (self._example_path / '20190815_mitte_out_MC_FloursurfaceADD.pickle').resolve()
|
||||
city.save(pickle_file)
|
||||
|
||||
counter = 0
|
||||
for building in city.buildings:
|
||||
if building.name != 'BLD121958':
|
||||
print('building name', building.name)
|
||||
print('volume', building.name, building.volume)
|
||||
if str(building.volume) == 'inf':
|
||||
counter += 1
|
||||
building.stl_export(self._output_path)
|
||||
print('total number of buildings with volume inf', counter)
|
||||
|
|
634693
tests_data/20190815_mitte_out_MC_FloursurfaceADD.gml
Normal file
634693
tests_data/20190815_mitte_out_MC_FloursurfaceADD.gml
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user