Skip to content

Added preprocessor.py to create an expanded version of exposure files

Tara Evaz Zadeh requested to merge feature/preprocessor into master

The exposure-model file needs to be expanded by the geometries of the tiles and buildings for easier processing in the losscalculator and visualization in QGIS.

The format is supposed to change from:

id,lon,lat,taxonomy,number,structural,night,occupancy,admin_name,admin_ID,origin_id

to

id,lon,lat,taxonomy,number,structural,night,occupancy,admin_name,admin_ID, tile_id, tile_geometry, building_id ,building_geometry

The function preprocess(exposure_out_filepath, exposure_filepath, building_to_cell_id_filepath) creates an augmented exposure file by appending ID and geometry of both buildings and their containing cell for each assets in the given exposure file.

If the asset originates from a cell (Residual; Which is number of buildings in a tile - number of OSM buildings):
tile_id: The origin_id is already the tile_id.
tile_geometry: can be computed using the function (get_geometry_WKT_of_cell(tile_id)) which I copied into my code (along with get_coordinates_from_cell_id(tile_id) because it is called ny the get_geometry_WKT_of_cell(tile_id)) from GDE_TOOLS_world_grid.py. This function returns the geometries in the 4326 projection.
building_id: Set to -1, because there are no buildings in the residual models.
building_geometry: Set to "POINT EMPTY", because there are no buildings in the residual models.

If the asset originates from a building:
building_id: The origin_id is already the building_id.
tile_id: Each building is anyway located in a tile. The file building_to_cell_id maps each building-id to both its geometry and its containing tile_id (with headers as origin_id;geometry;tile_id. As explained above, in this case origin_id is a building_id). Thus the tile_id including the building can be extracted from 3rd column of this file.
building_geometry: The geometry of each building_id can be extracted from 2rd column of the file building_to_cell_id. The geometries in this file are described in the projection 3857. Here the projection is changed to 4326 to match the tile geometries. This is done using the function reproject_and_flip(polygon, epsg_from, epsg_to) and will be discussed below.
tile_geometry: With the tile_id being extracted, the geometry of it is then computed as explained above using the function (get_geometry_WKT_of_cell(tile_id)).

reproject_and_flip(polygon, '3857', '4326'): Using this function the building_geometry is reprojected to 4326. the function flip is also used because we want the resulting WKT geometry as lon,lat instead of lat,lon.

Please note that the input exposure model can be a mixture of assets coming from both cell and building exposure files.
Another issue to consider is that this program is for temporary use in the repository to avoid repeating processing for each computation (We might want to do many different computations using each exposure model) such as each time finding and appending building polygons and the tiles that include the buildings.
This program only works if tiling is used the way Cecilia has gridded the world into tiles (because we use her function to create polygons reading the id of each tile), but this is not a problem, because as said above, this program is with help of Danijel and is meant to work for a short time before the final GDE version is decided and may later be removed from the repository.

\rfc @cnievas @shinde
\approve @fd @marius
\fyi @ds

Edited by Tara Evaz Zadeh

Merge request reports