dynamic_building_simulation/init.py

54 lines
1.8 KiB
Python
Raw Normal View History

from geometry.geometry_factory import GeometryFactory
from physics.physics_factory import PhysicsFactory
from usage.usage_factory import UsageFactory
2020-05-18 13:56:54 -04:00
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)
return self._city