add name field to geojson

This commit is contained in:
Guille Gutierrez 2023-04-06 13:26:29 -04:00
parent 4ca8975e18
commit af0e2a7c69
3 changed files with 11 additions and 1 deletions

View File

@ -29,6 +29,7 @@ class Geojson:
def __init__(self, def __init__(self,
path, path,
name_field=None,
extrusion_height_field=None, extrusion_height_field=None,
year_of_construction_field=None, year_of_construction_field=None,
function_field=None, function_field=None,
@ -41,6 +42,7 @@ class Geojson:
self._max_y = cte.MIN_FLOAT self._max_y = cte.MIN_FLOAT
self._max_z = 0 self._max_z = 0
self._city = None self._city = None
self._name_field = name_field
self._extrusion_height_field = extrusion_height_field self._extrusion_height_field = extrusion_height_field
self._year_of_construction_field = year_of_construction_field self._year_of_construction_field = year_of_construction_field
self._function_field = function_field self._function_field = function_field
@ -209,10 +211,12 @@ class Geojson:
else: else:
building_name = f'building_{building_id}' building_name = f'building_{building_id}'
building_id += 1 building_id += 1
if self._name_field is not None:
building_name = feature['properties'][self._name_field]
polygons = [] polygons = []
for part, coordinates in enumerate(geometry['coordinates']): for part, coordinates in enumerate(geometry['coordinates']):
polygons = self._get_polygons(polygons, coordinates) polygons = self._get_polygons(polygons, coordinates)
for zone, polygon in enumerate(polygons): for polygon in polygons:
if extrusion_height == 0: if extrusion_height == 0:
buildings = buildings + Geojson._create_buildings_lod0(f'{building_name}_part_{part}', buildings = buildings + Geojson._create_buildings_lod0(f'{building_name}_part_{part}',
year_of_construction, year_of_construction,

View File

@ -23,6 +23,7 @@ class GeometryFactory:
def __init__(self, file_type, def __init__(self, file_type,
path=None, path=None,
data_frame=None, data_frame=None,
name_field=None,
height_field=None, height_field=None,
year_of_construction_field=None, year_of_construction_field=None,
function_field=None, function_field=None,
@ -35,6 +36,7 @@ class GeometryFactory:
raise Exception(err_msg) raise Exception(err_msg)
self._path = path self._path = path
self._data_frame = data_frame self._data_frame = data_frame
self._name_field = name_field
self._height_field = height_field self._height_field = height_field
self._year_of_construction_field = year_of_construction_field self._year_of_construction_field = year_of_construction_field
self._function_field = function_field self._function_field = function_field
@ -77,6 +79,7 @@ class GeometryFactory:
:return: City :return: City
""" """
return Geojson(self._path, return Geojson(self._path,
self._name_field,
self._height_field, self._height_field,
self._year_of_construction_field, self._year_of_construction_field,
self._function_field, self._function_field,

View File

@ -139,9 +139,12 @@ class TestGeometryFactory(TestCase):
path=(self._example_path / file).resolve(), path=(self._example_path / file).resolve(),
height_field='building_height', height_field='building_height',
year_of_construction_field='ANNEE_CONS', year_of_construction_field='ANNEE_CONS',
name_field='ID_UEV',
function_field='CODE_UTILI', function_field='CODE_UTILI',
function_to_hub=MontrealFunctionToHubFunction().dictionary).city function_to_hub=MontrealFunctionToHubFunction().dictionary).city
# include 25 square meter condition for a building reduces buildings number from 2289 to 2057 # include 25 square meter condition for a building reduces buildings number from 2289 to 2057
for building in city.buildings:
print(building.name)
self.assertEqual(2057, len(city.buildings), 'wrong number of buildings') self.assertEqual(2057, len(city.buildings), 'wrong number of buildings')
def test_map_neighbours(self): def test_map_neighbours(self):