acept.bbd_plz_preprocessing
Module for the BBD shapefiles to PLZ mapping
- Use this module to:
read building data from BBD shapefiles (.shp) and calculate missing fields
build the mapping of the BBD shapefiles to post codes (PLZ)
lookup post codes (PLZ) in the mapping
query the BBD for the GeoDataFrame containing all buildings with the selected post code (PLZ)
save the BBD query result to a shape file in the /temp directory
acept.acept_constants.TEMP_PATH
Note
The BBD shapefiles are read from the acept.acept_constants.BBD_ROOT_DIR directory. The modified BBD
shapefiles are saved in the acept.acept_constants.BBD_WITH_PLZ_ROOT_PATH directory.
Module Contents
Functions
Derives output file path for modified shape file (.shp) from input file path |
|
|
Reads shapefile and calculates missing fields (bid, lat, lon, plz) |
|
Reads the PLZ shapefile and adds missing field (plz) to the buildings GeoDataFrame. |
|
Reads the PLZ shapefile and adds missing field (plz) to the buildings GeoDataFrame based on each building's |
|
Builds the mapping of the BBD shapefiles to post codes (PLZ) as a json file and updates the shapefiles with missing |
|
Make the lookup of the given PLZ in the saved mapping of PLZ -> paths to shape files. |
|
Query the BBD for the GeoDataFrame containing all buildings with the selected post code (PLZ) and use type. |
Save the BBD query result to a shape file in the /temp directory. |
|
Query the BBD for all buildings with the selected post code (PLZ) and use type and save result to a shape file |
|
Query the BBD for all buildings with the selected post code (PLZ) and use type and save result to a .csv file |
Attributes
'All', 'Residential', 'Industrial', |
|
'Industrial', 'Commercial', 'Public' |
- acept.bbd_plz_preprocessing.derive_bbd_output_path_from_filepath_shp(output_base: str, filename: str) str[source]
Derives output file path for modified shape file (.shp) from input file path
- acept.bbd_plz_preprocessing.read_building_data_from_shp(parent_dir: str, filename_buildings: str, debug: bool = True) Tuple[str, geopandas.GeoDataFrame][source]
Reads shapefile and calculates missing fields (bid, lat, lon, plz)
Returns the modified shapefile and GeoDataFrame with missing fields added
- Parameters:
- Returns:
Path to the (modified) shapefile and (modified) GeoDataFrame containing the buildings
- Return type:
Tuple[str, geopandas.GeoDataFrame]
- acept.bbd_plz_preprocessing.calculate_plz(buildings: geopandas.GeoDataFrame, debug: bool = True) geopandas.GeoDataFrame[source]
Reads the PLZ shapefile and adds missing field (plz) to the buildings GeoDataFrame.
- Parameters:
buildings (geopandas.GeoDataFrame) – GeoDataFrame containing buildings.
debug (bool) – Whether to print debug messages. Default is
True.
- Returns:
Path to the (modified) shapefile and (modified) GeoDataFrame containing the buildings.
- Return type:
- acept.bbd_plz_preprocessing.calculate_plz_from_centroid(buildings: geopandas.GeoDataFrame, debug: bool = True) geopandas.GeoDataFrame[source]
Reads the PLZ shapefile and adds missing field (plz) to the buildings GeoDataFrame based on each building’s centroid.
- Parameters:
buildings (geopandas.GeoDataFrame) – GeoDataFrame containing buildings.
debug (bool) – Whether to print debug messages. Default is
True.
- Returns:
Path to the (modified) shapefile and (modified) GeoDataFrame containing the buildings.
- Return type:
- acept.bbd_plz_preprocessing.build_plz_munc_id_db(debug: bool = True)[source]
Builds the mapping of the BBD shapefiles to post codes (PLZ) as a json file and updates the shapefiles with missing information. Calculates for all building shapefiles below the BBD root directory missing fields and saves the modified shapefiles.
Note
The BBD shapefiles are read from the
acept.acept_constants.BBD_ROOT_DIRdirectory. The modified BBD shapefiles are saved in theacept.acept_constants.BBD_WITH_PLZ_ROOT_PATHdirectory.- Parameters:
debug (bool) – Whether to print debug messages. Default is
True.
- acept.bbd_plz_preprocessing.VALID_BUILDING_USES = ['All', 'Residential', 'Industrial', 'Commercial', 'Public', 'Non-Residential'][source]
‘All’, ‘Residential’, ‘Industrial’, ‘Commercial’, ‘Public’, ‘Non-Residential’
- Type:
Valid use types for buildings. ‘All’ selects all use types. Possible
- acept.bbd_plz_preprocessing.NON_RES_BUILDING_USES = ['Industrial', 'Commercial', 'Public'][source]
‘Industrial’, ‘Commercial’, ‘Public’
- Type:
Use types for non-residential buildings. Possible
- acept.bbd_plz_preprocessing.lookup_plz_in_mapping(plz: str | int) dict | None[source]
Make the lookup of the given PLZ in the saved mapping of PLZ -> paths to shape files. If there is no mapping to the PLZ None is returned.
- acept.bbd_plz_preprocessing.query_bbd_for_plz(plz: str, building_use: str = 'All', debug: bool = True) geopandas.GeoDataFrame[source]
Query the BBD for the GeoDataFrame containing all buildings with the selected post code (PLZ) and use type. Builds the mapping if is not yet there.
- Parameters:
- Raises:
ValueError – if there is no data for the PLZ in the BBD
- Returns:
GeoDataFrame with the buildings with the selected post code (PLZ).
- Return type:
- acept.bbd_plz_preprocessing.save_query_result_to_temp_shp(plz: str, result_gdf: geopandas.GeoDataFrame, building_use: str = 'All', debug: bool = True) str[source]
Save the BBD query result to a shape file in the /temp directory.
- Parameters:
plz (str) – PLZ to search.
building_use (str) – Use type of the buildings, default: ‘All’ selects all use types. Possible: ‘All’, ‘Residential’, ‘Industrial’, ‘Commercial’, ‘Public’, ‘Non-Residential’.
result_gdf (geopandas.GeoDataFrame) – GeoDataFrame with all buildings with PLZ and buildings use.
debug (bool) – default=True, give debug messages.
- Returns:
File path to the BBD query result.
- Return type:
- acept.bbd_plz_preprocessing.compute_buildings_for_plz_shp(plz: str | int, building_use: str = 'All', debug: bool = True) str[source]
Query the BBD for all buildings with the selected post code (PLZ) and use type and save result to a shape file in the /temp directory.
- Parameters:
- Returns:
Path to combined file of all buildings with PLZ and building use.
- Return type:
- acept.bbd_plz_preprocessing.compute_buildings_for_plz_to_uhp_csv(plz: str | int, building_use: str = 'All', debug: bool = True) str[source]
Query the BBD for all buildings with the selected post code (PLZ) and use type and save result to a .csv file in the format used by UrbanHeatPro in the /temp directory.
- Parameters:
- Returns:
Path to combined file of all buildings with PLZ and building use
- Return type: