mirror of
https://rs-loy-gitlab.concordia.ca/PMAU/DynamicBuildingSimulation.git
synced 2024-11-14 23:10:28 -05:00
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
from geometry.geometry_factory import GeometryFactory
|
|
from physics.physics_factory import PhysicsFactory
|
|
from usage.usage_factory import UsageFactory
|
|
import pyproj
|
|
import reverse_geocoder as rg
|
|
|
|
|
|
class Init:
|
|
def __init__(self, geometry_path):
|
|
self._geometry_path = geometry_path
|
|
self._city = None
|
|
# todo: right now extracted at city level, in the future should be extracted also at building level if exist
|
|
self._location = None
|
|
|
|
@property
|
|
def location(self):
|
|
if self._location is None:
|
|
gps = pyproj.CRS('EPSG:4326') # LatLon with WGS84 datum used by GPS units and Google Earth
|
|
input_reference = None
|
|
try:
|
|
input_reference = pyproj.CRS(self._city.srs_name) # Projected coordinate system from input data
|
|
except pyproj.exceptions.CRSError:
|
|
print('Invalid projection reference system, please check the input data. (e.g. in CityGML files: srs_name)')
|
|
quit()
|
|
|
|
coordinates = pyproj.transform(input_reference, gps, self._city.lower_corner[0], self._city.lower_corner[1])
|
|
self._location = rg.search(coordinates)
|
|
return self._location
|
|
|
|
@property
|
|
def handler(self):
|
|
if self.city_name == 'New York City':
|
|
handler = '{0}_{1}'
|
|
return handler.format(self.country_code, self.city_name.lower().replace(' ', '_'))
|
|
return self.country_code
|
|
|
|
@property
|
|
def country_code(self):
|
|
return self.location[0]['cc']
|
|
|
|
@property
|
|
def city_name(self):
|
|
if self._city.name is None:
|
|
self._city.name = self.location[0]['name']
|
|
return self._city.name
|
|
|
|
@property
|
|
def city(self):
|
|
if self._city is None:
|
|
self._city = GeometryFactory('citygml', self._geometry_path).city
|
|
PhysicsFactory(self.handler, self._city)
|
|
UsageFactory(self.handler, self._city)
|
|
# todo: not sure if this is the best way
|
|
# todo: up to now, there is only one usage_zone, but this will change in the future
|
|
# and this method must be revised
|
|
for city_object in self._city.city_objects:
|
|
usage_zones_list = [100, city_object.usage_zones[0]]
|
|
for thermal_zone in city_object.thermal_zones:
|
|
thermal_zone.set_usage_zones(usage_zones_list)
|
|
return self._city
|