Commit ff802332 authored by Nicolas Garcia Ospina's avatar Nicolas Garcia Ospina
Browse files

Included optional geometry in dictionary creation

parent 89cf99e9
Pipeline #24917 passed with stage
in 4 minutes and 44 seconds
...@@ -108,6 +108,7 @@ def multiprocess_built_estimation_batch(quadkey_batch): ...@@ -108,6 +108,7 @@ def multiprocess_built_estimation_batch(quadkey_batch):
database_crs_number=roads_database_crs_number, database_crs_number=roads_database_crs_number,
table_config=db_config["roads_table"], table_config=db_config["roads_table"],
buffer_magnitude=db_config["process_buffer_magnitude"], buffer_magnitude=db_config["process_buffer_magnitude"],
get_geometry=get_geometry,
) )
if result is not None: if result is not None:
built_up_areas.append(result) built_up_areas.append(result)
......
...@@ -272,7 +272,7 @@ class TileProcessor: ...@@ -272,7 +272,7 @@ class TileProcessor:
return polygon.area return polygon.area
@staticmethod @staticmethod
def build_dictionary(tile, datasource, built_polygon): def build_dictionary(tile, datasource, built_polygon, get_geometry=False):
"""Returns a dictionary with the built-up area related attributes """Returns a dictionary with the built-up area related attributes
associated to the Tile and a given DataSource. associated to the Tile and a given DataSource.
Contains: Contains:
...@@ -298,22 +298,40 @@ class TileProcessor: ...@@ -298,22 +298,40 @@ class TileProcessor:
if built_polygon.is_empty: if built_polygon.is_empty:
logging.info("No built area found in {}".format(tile.quadkey)) logging.info("No built area found in {}".format(tile.quadkey))
return return
if get_geometry is False:
results = { results = {
"quadkey": tile.quadkey, "quadkey": tile.quadkey,
"source_id": datasource.source_id, "source_id": datasource.source_id,
"built_area": TileProcessor.reproject_polygon(built_polygon, tile.crs, "epsg:4326"), "built_area_size": TileProcessor.albers_area_calculation(
"built_area_size": TileProcessor.albers_area_calculation(built_polygon, tile.crs), built_polygon, tile.crs
"last_update": str(date.today()), ),
} "last_update": str(date.today()),
}
else:
results = {
"quadkey": tile.quadkey,
"source_id": datasource.source_id,
"built_area": TileProcessor.reproject_polygon(
built_polygon, tile.crs, "epsg:4326"
),
"built_area_size": TileProcessor.albers_area_calculation(
built_polygon, tile.crs
),
"last_update": str(date.today()),
}
if not results["source_id"]: if not results["source_id"]:
del results["source_id"] del results["source_id"]
return results return results
@staticmethod @staticmethod
def get_built_up_area( def get_built_up_area(
quadkey, datasource, database, database_crs_number, table_config, buffer_magnitude quadkey,
datasource,
database,
database_crs_number,
table_config,
buffer_magnitude,
get_geometry=False,
): ):
"""Run the complete processing of a quadkey and returns a dictionary """Run the complete processing of a quadkey and returns a dictionary
created with TileProcessor.build_dictionary. created with TileProcessor.build_dictionary.
...@@ -362,7 +380,9 @@ class TileProcessor: ...@@ -362,7 +380,9 @@ class TileProcessor:
refined_built_area = TileProcessor.polygon_difference( refined_built_area = TileProcessor.polygon_difference(
clip_built_geometry, roads_processed clip_built_geometry, roads_processed
) )
result = TileProcessor.build_dictionary(tile, datasource, refined_built_area) result = TileProcessor.build_dictionary(
tile, datasource, refined_built_area, get_geometry=get_geometry
)
return result return result
@staticmethod @staticmethod
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment