1010# ' [critical_events()]
1111# ' @param translation_table Project specific translation dataframe that
1212# ' contains verknet data and project specific IDs. Column names must be
13- # ' * "ID ": Verknet ID or ID of manually added rivers which are also the
13+ # ' * "qsimVis_ID ": Verknet ID or ID of manually added rivers which are also the
1414# ' filnames of the river csv tables
1515# ' * "verknet_BWaStrIdNr": The water body number in verknet. If NA the river
1616# ' information is assumed to be added manually.
1717# ' * "Bezeichnung": The real water body name
18- # ' * "section_name ": The project specific ID of the whole river or a river
18+ # ' * "model_IDs ": The project specific ID of the whole river or a river
1919# ' section. Can be multiple IDs per waterbody, separated by ",", however, must
2020# ' be unique.
21- # ' @param id_source A string defining the part of the site name which is used
22- # ' to find the river name in the database. This must be the ID that is given in
23- # ' the "section_name" column of the translation table. Usually this
24- # ' is "river_name" but it can be changed to "section_name" instead.
21+ # ' @param model_id_column A string defining the column of the aggregated_data
22+ # ' table which contains the model ID in the translation_table.
2523# '
2624# ' @details
2725# ' The Verknet data is available here: https://www.gdws.wsv.bund.de/DE/service/karten/03_VerkNet-BWaStr/VerkNet-BWaStr_node.html
3230# ' @export
3331# '
3432add_qsimVis_id <- function (
35- aggregated_data , translation_table , id_source = " river_name"
33+ aggregated_data , translation_table , model_id_column = " river_name"
3634){
37- separate_project_ids <- strsplit(x = translation_table $ section_name , " ," )
35+ separate_project_ids <- strsplit(x = translation_table $ model_IDs , " ," )
3836 project_ids <- unlist(separate_project_ids )
3937
40- aggregated_data $ qsimVis_source <- aggregated_data $ qsimVis_river <- NA
38+ aggregated_data $ qsimVis_source <- aggregated_data $ qsimVis_ID <- NA
4139
4240 for (project_id in project_ids ){
4341 id_row <- which(sapply(separate_project_ids , function (x ){project_id %in% x }))
@@ -49,19 +47,19 @@ add_qsimVis_id <- function(
4947 stop(" Project ID: " , project_id , " is part of two or more rivers." )
5048 }
5149
52- qsimVis_id <- translation_table [[" ID " ]][id_row ]
50+ qsimVis_ID <- translation_table [[" qsimVis_ID " ]][id_row ]
5351 qsimVis_source <- ifelse(
5452 test = is.na(translation_table [[" verknet_BWaStrIdNr" ]][id_row ]),
5553 yes = " manually_added" ,
5654 no = " verknet"
5755 )
5856
59- section_rows <- grep(
57+ site_rows <- grep(
6058 pattern = paste0(" ^" , project_id , " $" ) ,
61- x = aggregated_data [[id_source ]]
59+ x = aggregated_data [[model_id_column ]]
6260 )
63- aggregated_data $ qsimVis_river [ section_rows ] <- qsimVis_id
64- aggregated_data $ qsimVis_source [section_rows ] <- qsimVis_source
61+ aggregated_data $ qsimVis_ID [ site_rows ] <- qsimVis_ID
62+ aggregated_data $ qsimVis_source [site_rows ] <- qsimVis_source
6563 }
6664 aggregated_data
6765}
0 commit comments