From b0fabf3b7fd0906a55f38bbed6a69350c37af74f Mon Sep 17 00:00:00 2001 From: guille Date: Tue, 24 Oct 2023 15:46:40 +0200 Subject: [PATCH] Add crs to the geometry importer as a parameter --- hub/imports/geometry/citygml.py | 9 ++++++--- hub/imports/geometry/geojson.py | 13 ++++++++----- hub/imports/geometry_factory.py | 10 +++++++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/hub/imports/geometry/citygml.py b/hub/imports/geometry/citygml.py index 9e5d5e8b..0cfe88c5 100644 --- a/hub/imports/geometry/citygml.py +++ b/hub/imports/geometry/citygml.py @@ -26,13 +26,16 @@ class CityGml: extrusion_height_field=None, year_of_construction_field=None, function_field=None, - function_to_hub=None): + function_to_hub=None, + hub_crs=None): self._city = None self._lod = None self._lod1_tags = ['lod1Solid', 'lod1MultiSurface'] self._lod2_tags = ['lod2Solid', 'lod2MultiSurface', 'lod2MultiCurve'] self._extrusion_height_field = extrusion_height_field self._function_to_hub = function_to_hub + if hub_crs is None: + hub_crs = 'EPSG:26911' if function_field is None: function_field = 'function' if year_of_construction_field is None: @@ -80,8 +83,8 @@ class CityGml: self._srs_name = envelope['@srsName'] else: # If not coordinate system given assuming hub standard - logging.warning('gml file contains no coordinate system assuming EPSG:26911 (North america with 4m error)') - self._srs_name = "EPSG:26911" + logging.warning(f'gml file contains no coordinate system assuming {hub_crs}') + self._srs_name = hub_crs else: # get the boundary from the city objects instead for city_object_member in self._gml['CityModel']['cityObjectMember']: diff --git a/hub/imports/geometry/geojson.py b/hub/imports/geometry/geojson.py index c92688ee..20b74534 100644 --- a/hub/imports/geometry/geojson.py +++ b/hub/imports/geometry/geojson.py @@ -34,9 +34,13 @@ class Geojson: extrusion_height_field=None, year_of_construction_field=None, function_field=None, - function_to_hub=None): - # todo: destination epsg should change according actual the location - self._transformer = Transformer.from_crs('epsg:4326', 'epsg:26911') + function_to_hub=None, + hub_crs=None + ): + self._hub_crs = hub_crs + if hub_crs is None : + self._hub_crs = 'epsg:26911' + self._transformer = Transformer.from_crs('epsg:4326', self._hub_crs) self._min_x = cte.MAX_FLOAT self._min_y = cte.MAX_FLOAT self._max_x = cte.MIN_FLOAT @@ -155,7 +159,7 @@ class Geojson: extrusion_height)) else: raise NotImplementedError(f'Geojson geometry type [{geometry["type"]}] unknown') - self._city = City([self._min_x, self._min_y, 0.0], [self._max_x, self._max_y, self._max_z], 'epsg:26911') + self._city = City([self._min_x, self._min_y, 0.0], [self._max_x, self._max_y, self._max_z], self._hub_crs) for building in buildings: # Do not include "small building-like structures" to buildings if building.floor_area >= 25: @@ -166,7 +170,6 @@ class Geojson: if lod > 0: lines_information = GeometryHelper.city_mapping(self._city, plot=False) self._store_shared_percentage_to_walls(self._city, lines_information) - return self._city def _polygon_coordinates_to_3d(self, polygon_coordinates): diff --git a/hub/imports/geometry_factory.py b/hub/imports/geometry_factory.py index 3e6ca0b3..bd3e9a4c 100644 --- a/hub/imports/geometry_factory.py +++ b/hub/imports/geometry_factory.py @@ -23,7 +23,8 @@ class GeometryFactory: height_field=None, year_of_construction_field=None, function_field=None, - function_to_hub=None): + function_to_hub=None, + hub_crs=None): self._file_type = '_' + file_type.lower() validate_import_export_type(GeometryFactory, file_type) self._path = path @@ -33,6 +34,7 @@ class GeometryFactory: self._year_of_construction_field = year_of_construction_field self._function_field = function_field self._function_to_hub = function_to_hub + self._hub_crs = hub_crs @property def _citygml(self) -> City: @@ -44,7 +46,8 @@ class GeometryFactory: self._height_field, self._year_of_construction_field, self._function_field, - self._function_to_hub).city + self._function_to_hub, + self._hub_crs).city @property def _obj(self) -> City: @@ -65,7 +68,8 @@ class GeometryFactory: self._height_field, self._year_of_construction_field, self._function_field, - self._function_to_hub).city + self._function_to_hub, + self._hub_crs).city @property def city(self) -> City: