hub/exports/exports_factory.py

95 lines
2.5 KiB
Python
Raw Normal View History

"""
ExportsFactory export a city into several formats
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
from pathlib import Path
2021-03-16 20:14:40 -04:00
from exports.formats.energy_ade import EnergyAde
2021-08-11 10:29:54 -04:00
from exports.formats.idf import Idf
2021-08-26 13:27:43 -04:00
from exports.formats.obj import Obj
from exports.formats.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from exports.formats.stl import Stl
2021-03-16 16:58:52 -04:00
class ExportsFactory:
"""
Exports factory class
"""
def __init__(self, export_type, city, path, target_buildings=None):
self._city = city
self._export_type = '_' + export_type.lower()
self._path = path
self._target_buildings = target_buildings
@property
def _citygml(self):
"""
2021-09-22 07:25:53 -04:00
Export to citygml
:return: None
"""
raise NotImplementedError
@property
def _collada(self):
raise NotImplementedError
2021-03-16 20:14:40 -04:00
@property
def _energy_ade(self):
"""
2021-09-22 07:25:53 -04:00
Export to citygml with application domain extensions
2021-03-16 20:14:40 -04:00
:return: None
"""
return EnergyAde(self._city, self._path)
@property
def _stl(self):
"""
Export the city geometry to stl
:return: None
"""
return Stl(self._city, self._path)
@property
def _obj(self):
"""
Export the city geometry to obj
:return: None
"""
return Obj(self._city, self._path)
@property
def _grounded_obj(self):
"""
2021-09-22 07:25:53 -04:00
Export the city geometry to obj with grounded coordinates
:return: None
"""
2021-03-16 16:58:52 -04:00
return Obj(self._city, self._path).to_ground_points()
@property
def _idf(self):
"""
Export the city to Energy+ idf format
:return: None
"""
idf_data_path = (Path(__file__).parent / './formats/idf_files/').resolve()
# todo: create a get epw file function based on the city
weather_path = (Path(__file__).parent / '../data/weather/epw/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw').resolve()
2021-08-26 13:27:43 -04:00
return Idf(self._city, self._path, (idf_data_path / 'Minimal.idf'), (idf_data_path / 'Energy+.idd'), weather_path)
@property
def _sra(self):
"""
Export the city to Simplified Radiosity Algorithm xml format
:return: None
"""
return SimplifiedRadiosityAlgorithm(self._city, (self._path / f'{self._city.name}_sra.xml'),
target_buildings=self._target_buildings)
def export(self):
"""
2021-09-22 07:25:53 -04:00
Export the city given to the class using the given export type handler
:return: None
"""
return getattr(self, self._export_type, lambda: None)