apcac.indexes#
{Short module description (1-3 sentences)} todo docstring
Features#
todo docstring
{feature 1}
{feature 2}
{feature 3}
{etc}
Overview#
todo docstring {Overview description}
Examples#
todo docstring {Examples in rST}
Print a message
# print message
print("Hello world!")
# [Output] >> 'Hello world!'
Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Demo for processing data |
|
Samples mean values from multiple raster files over a vector layer (e.g., catchments) and merges the results into a GeoDataFrame. |
|
- apcac.indexes.compute_index_t(input_hand, input_twi, output_folder, hand_w=0.5, hand_max=15, twi_max=15)[source]#
- apcac.indexes.sample_indexes(output_folder, input_db, raster_files, input_layer='apcac_bho5k', raster_multipliers=None)[source]#
Samples mean values from multiple raster files over a vector layer (e.g., catchments) and merges the results into a GeoDataFrame.
- Parameters:
output_folder (str) – Path to the directory where temporary and final output files will be stored.
input_db (str) – Path to the GeoPackage or database file containing the input vector layer.
raster_files (dict) – Dictionary where keys are the desired column names (index names) and values are the full paths to the corresponding raster files.
input_layer (str) – Name of the vector layer within the input database to use for zonal statistics. Default value = “apcac_bho5k”
raster_multipliers (dict) – [optional] Dictionary where keys are the index names (from
raster_files) and values are factors by which the sampled mean values should be divided (e.g., to convert units).
- Returns:
The file path to the final GeoPackage file containing the input layer with the new sampled index columns.
- Return type:
str
Notes
The process uses QGIS’s native zonal statistics algorithm (
native:zonalstatisticsfb) to calculate the mean of each raster within the polygons of the input vector layer.Script example
import importlib.util as iu # define the paths to this module # ---------------------------------------- the_module = "path/to/classes.py" spec = iu.spec_from_file_location("module", the_module) module = iu.module_from_spec(spec) spec.loader.exec_module(module) # define the paths to input and output folders # ---------------------------------------- input_dir = "path/to/input_folder" output_dir = "path/to/output_folder" # define the path to input database # ---------------------------------------- input_db = f"{input_dir}/path/to/data.gpkg" # define the paths to input rasters # ---------------------------------------- raster_files = { # change this paths "t": f"{input_dir}/path/to/raster_t.tif", "s": f"{input_dir}/path/to/raster_s.tif", "g": f"{input_dir}/path/to/raster_g.tif", "c": f"{input_dir}/path/to/raster_c.tif", "n": f"{input_dir}/path/to/raster_n.tif", "v": f"{input_dir}/path/to/raster_v.tif", "slope": f"{input_dir}/path/to/raster_slope.tif", "uslek": f"{input_dir}/path/to/raster_uslek.tif", } # define which index has multipliers (the value is divided) # ---------------------------------------- raster_multipliers = { "t": 1000, "s": 100, "slope": 100, # change and add more if needed } # call the function # ---------------------------------------- module.sample_indexes( input_db=input_db, raster_files=raster_files, output_folder=output_dir, raster_multipliers=raster_multipliers, input_layer="apcac_bho5k", )