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

derive_bbd_output_path_from_filepath_shp(→ str)

Derives output file path for modified shape file (.shp) from input file path

read_building_data_from_shp(→ Tuple[str, ...)

Reads shapefile and calculates missing fields (bid, lat, lon, plz)

calculate_plz(→ geopandas.GeoDataFrame)

Reads the PLZ shapefile and adds missing field (plz) to the buildings GeoDataFrame.

calculate_plz_from_centroid(→ geopandas.GeoDataFrame)

Reads the PLZ shapefile and adds missing field (plz) to the buildings GeoDataFrame based on each building's

build_plz_munc_id_db([debug])

Builds the mapping of the BBD shapefiles to post codes (PLZ) as a json file and updates the shapefiles with missing

lookup_plz_in_mapping(→ dict | None)

Make the lookup of the given PLZ in the saved mapping of PLZ -> paths to shape files.

query_bbd_for_plz(→ geopandas.GeoDataFrame)

Query the BBD for the GeoDataFrame containing all buildings with the selected post code (PLZ) and use type.

save_query_result_to_temp_shp(→ str)

Save the BBD query result to a shape file in the /temp directory.

compute_buildings_for_plz_shp(→ str)

Query the BBD for all buildings with the selected post code (PLZ) and use type and save result to a shape file

compute_buildings_for_plz_to_uhp_csv(→ str)

Query the BBD for all buildings with the selected post code (PLZ) and use type and save result to a .csv file

Attributes

VALID_BUILDING_USES

'All', 'Residential', 'Industrial',

NON_RES_BUILDING_USES

'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

Parameters:
  • output_base (str) – base directory path for modified shape files

  • filename (str) – path of input shape file

Returns:

output path of modified shape file

Return type:

str

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:
  • parent_dir (str) – Path to the parent directory of the shapefile

  • filename_buildings (str) – Filename of the shapefile containing the 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:

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:

geopandas.GeoDataFrame

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:

geopandas.GeoDataFrame

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_DIR directory. The modified BBD shapefiles are saved in the acept.acept_constants.BBD_WITH_PLZ_ROOT_PATH directory.

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.

Parameters:

plz (str | int) – PLZ to search.

Returns:

Dictionary with information on the shape files with all buildings in of the PLZ. If there is no mapping to the PLZ None is returned.

Return type:

dict | None

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:
  • 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’.

  • debug (bool) – default=True, give debug messages.

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:

geopandas.GeoDataFrame

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:

str

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:
  • plz (str | int) – 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’.

  • debug (bool) – default=True, give debug messages.

Returns:

Path to combined file of all buildings with PLZ and building use.

Return type:

str

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:
  • plz (str | int) – 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’.

  • debug (bool) – default=True, give debug messages.

Returns:

Path to combined file of all buildings with PLZ and building use

Return type:

str