2020-06-09 14:07:47 -04:00
|
|
|
"""
|
|
|
|
GeometryFactory retrieve the specific geometric module to load the given format
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2022-04-08 09:35:33 -04:00
|
|
|
Copyright © 2022 Concordia CERC group
|
|
|
|
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
2020-06-09 14:07:47 -04:00
|
|
|
"""
|
2023-05-18 12:29:28 -04:00
|
|
|
import geopandas
|
|
|
|
|
2023-01-24 10:51:50 -05:00
|
|
|
from hub.city_model_structure.city import City
|
2023-05-19 16:01:06 -04:00
|
|
|
from hub.helpers.utils import validate_import_export_type
|
2023-01-24 10:51:50 -05:00
|
|
|
from hub.imports.geometry.citygml import CityGml
|
2023-05-19 16:01:06 -04:00
|
|
|
from hub.imports.geometry.geojson import Geojson
|
|
|
|
from hub.imports.geometry.gpandas import GPandas
|
2023-01-24 10:51:50 -05:00
|
|
|
from hub.imports.geometry.obj import Obj
|
|
|
|
from hub.imports.geometry.rhino import Rhino
|
2022-11-23 10:20:33 -05:00
|
|
|
|
2020-05-18 13:25:08 -04:00
|
|
|
|
|
|
|
class GeometryFactory:
|
2020-06-15 11:38:18 -04:00
|
|
|
"""
|
|
|
|
GeometryFactory class
|
|
|
|
"""
|
2022-11-24 17:58:45 -05:00
|
|
|
def __init__(self, file_type,
|
|
|
|
path=None,
|
|
|
|
data_frame=None,
|
2023-05-26 18:21:35 -04:00
|
|
|
aliases_field=None,
|
2022-11-24 17:58:45 -05:00
|
|
|
height_field=None,
|
|
|
|
year_of_construction_field=None,
|
2023-02-02 13:00:58 -05:00
|
|
|
function_field=None,
|
|
|
|
function_to_hub=None):
|
2020-06-11 15:45:11 -04:00
|
|
|
self._file_type = '_' + file_type.lower()
|
2023-05-19 16:01:06 -04:00
|
|
|
validate_import_export_type(GeometryFactory, file_type)
|
2020-05-18 13:25:08 -04:00
|
|
|
self._path = path
|
2022-11-16 16:26:45 -05:00
|
|
|
self._data_frame = data_frame
|
2023-05-26 18:21:35 -04:00
|
|
|
self._aliases_field = aliases_field
|
2022-11-24 17:58:45 -05:00
|
|
|
self._height_field = height_field
|
|
|
|
self._year_of_construction_field = year_of_construction_field
|
|
|
|
self._function_field = function_field
|
2023-02-02 13:00:58 -05:00
|
|
|
self._function_to_hub = function_to_hub
|
2020-05-18 13:25:08 -04:00
|
|
|
|
|
|
|
@property
|
2021-09-22 07:25:53 -04:00
|
|
|
def _citygml(self) -> City:
|
|
|
|
"""
|
|
|
|
Enrich the city by using CityGML information as data source
|
|
|
|
:return: City
|
|
|
|
"""
|
2023-02-02 13:00:58 -05:00
|
|
|
return CityGml(self._path,
|
|
|
|
self._height_field,
|
|
|
|
self._year_of_construction_field,
|
|
|
|
self._function_field,
|
|
|
|
self._function_to_hub).city
|
2020-05-18 13:25:08 -04:00
|
|
|
|
2021-03-16 16:58:52 -04:00
|
|
|
@property
|
2021-09-22 07:25:53 -04:00
|
|
|
def _obj(self) -> City:
|
|
|
|
"""
|
|
|
|
Enrich the city by using OBJ information as data source
|
|
|
|
:return: City
|
|
|
|
"""
|
2021-08-27 12:51:30 -04:00
|
|
|
return Obj(self._path).city
|
2023-05-18 12:29:28 -04:00
|
|
|
|
2022-11-13 21:07:04 -05:00
|
|
|
@property
|
|
|
|
def _gpandas(self) -> City:
|
|
|
|
"""
|
|
|
|
Enrich the city by using GeoPandas information as data source
|
|
|
|
:return: City
|
|
|
|
"""
|
2022-11-16 16:26:45 -05:00
|
|
|
if self._data_frame is None:
|
|
|
|
self._data_frame = geopandas.read_file(self._path)
|
|
|
|
return GPandas(self._data_frame).city
|
2021-03-16 16:58:52 -04:00
|
|
|
|
2022-11-17 15:56:49 -05:00
|
|
|
@property
|
|
|
|
def _geojson(self) -> City:
|
|
|
|
"""
|
|
|
|
Enrich the city by using Geojson information as data source
|
|
|
|
:return: City
|
|
|
|
"""
|
2023-02-02 13:00:58 -05:00
|
|
|
return Geojson(self._path,
|
2023-05-26 18:21:35 -04:00
|
|
|
self._aliases_field,
|
2023-02-02 13:00:58 -05:00
|
|
|
self._height_field,
|
|
|
|
self._year_of_construction_field,
|
|
|
|
self._function_field,
|
|
|
|
self._function_to_hub).city
|
2022-11-17 15:56:49 -05:00
|
|
|
|
2022-02-16 15:08:05 -05:00
|
|
|
@property
|
|
|
|
def _rhino(self) -> City:
|
|
|
|
"""
|
2022-03-22 12:30:05 -04:00
|
|
|
Enrich the city by using Rhino information as data source
|
2022-02-16 15:08:05 -05:00
|
|
|
:return: City
|
|
|
|
"""
|
|
|
|
return Rhino(self._path).city
|
2021-10-25 13:28:43 -04:00
|
|
|
|
2020-05-18 13:25:08 -04:00
|
|
|
@property
|
|
|
|
def city(self) -> City:
|
2020-06-11 15:45:11 -04:00
|
|
|
"""
|
2021-09-22 07:25:53 -04:00
|
|
|
Enrich the city given to the class using the class given handler
|
2020-06-11 15:45:11 -04:00
|
|
|
:return: City
|
|
|
|
"""
|
2023-05-30 17:13:49 -04:00
|
|
|
return getattr(self, self._file_type, lambda: None)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def city_debug(self) -> City:
|
|
|
|
"""
|
|
|
|
Enrich the city given to the class using the class given handler
|
|
|
|
:return: City
|
|
|
|
"""
|
|
|
|
print('rhino')
|
|
|
|
return Rhino(self._path).city
|