@@ -22,24 +22,94 @@ load_geo <- function(region, Rdata_file){
2222# ' Add Berlin combined sewer catchments to a map
2323# '
2424# ' Polygons are drawn in different types of gray
25+ # ' @param plot_names If TRUE, names of the districts will be included in the plot
26+ # ' @param highlight_catchments Character vector containing the catchments names
27+ # ' of catchments to be highlighted
28+ # ' @param highlight_style Either "shaded" (default) or a specific color, which
29+ # ' cab also be defined by [rgb()]
2530# '
26- # ' @importFrom graphics polygon
31+ # ' @importFrom graphics polygon abline text
2732# ' @export
2833# '
29- add_catchments <- function (){
30-
34+ Berlin_add_catchments <- function (
35+ plot_names = FALSE , highlight_catchments = NULL , highlight_style = " shaded"
36+ ){
3137 ezg <- NULL
3238 load(file.path(system.file(package = " qsimVis" ),
3339 " extdata/berlin_data/catch_polygon.RData" ))
3440
41+ if (plot_names ){
42+ ezg_namePositions <- lapply(ezg , function (loc_df ) {
43+ data.frame (" x" = mean(loc_df [,1 ]), " y" = mean(loc_df [,2 ]))
44+ })
45+
46+ ezg_namePositions $ `Bln II` $ y <- ezg_namePositions $ `Bln II` $ y - 0.01
47+ ezg_namePositions $ `Bln III` $ x <- ezg_namePositions $ `Bln III` $ x + 0.01
48+ ezg_namePositions $ `Bln III` $ y <- ezg_namePositions $ `Bln III` $ y - 0.003
49+ ezg_namePositions $ `Bln IIIa` $ x <- ezg_namePositions $ `Bln IIIa` $ x - 0.01
50+ ezg_namePositions $ `Bln IIIa` $ y <- ezg_namePositions $ `Bln IIIa` $ y - 0.04
51+ ezg_namePositions $ `Bln VIII` $ x <- ezg_namePositions $ `Bln VIII` $ x + 0.005
52+ ezg_namePositions $ `Bln VIII` $ y <- ezg_namePositions $ `Bln VIII` $ y + 0.005
53+ ezg_namePositions $ `Bln IX` $ x <- ezg_namePositions $ `Bln IX` $ x + 0.005
54+ ezg_namePositions $ `Bln IX` $ y <- ezg_namePositions $ `Bln IX` $ y + 0.005
55+ ezg_namePositions $ `Bln IX` $ y <- ezg_namePositions $ `Bln IX` $ y + 0.005
56+ ezg_namePositions $ `Bln XI` $ x <- ezg_namePositions $ `Bln XI` $ x - 0.013
57+ ezg_namePositions $ `Chb I` $ y <- ezg_namePositions $ `Chb I` $ y - 0.005
58+ ezg_namePositions $ `Chb Ia` $ y <- ezg_namePositions $ `Chb Ia` $ y + 0.02
59+ ezg_namePositions $ `Chb Ia` $ x <- ezg_namePositions $ `Chb Ia` $ x - 0.08
60+ ezg_namePositions $ `Chb III` $ y <- ezg_namePositions $ `Chb III` $ y + 0.002
61+ ezg_namePositions $ `Ruh` $ x <- ezg_namePositions $ `Ruh` $ x + 0.015
62+ ezg_namePositions $ `Spa1` $ x <- ezg_namePositions $ `Spa1` $ x - 0.008
63+ ezg_namePositions $ `Wil` $ y <- ezg_namePositions $ `Wil` $ y + 0.01
64+ }
65+
66+ if (length(highlight_catchments ) > 0L ){
67+ wrong_names <- ! (highlight_catchments %in% names(ezg ))
68+ if (any(wrong_names )){
69+ warning(paste(highlight_catchments [wrong_names ], collapse = " , " ),
70+ " : no defined catchment name(s) -> will not be highlighted" )
71+ }
72+ }
73+
74+ # colCircle <- rep(paste0("gray",c(60,70,80,90)), 10)
75+ # for(i in seq_along(ezg)){
76+ # col <- colCircle[i]
77+ # polygon(
78+ # x = ezg[[i]][,1],
79+ # y = ezg[[i]][,2],
80+ # col = col)
81+ # }
3582 colCircle <- rep(paste0(" gray" ,c(60 ,70 ,80 ,90 )), 10 )
3683 for (i in seq_along(ezg )){
3784 col <- colCircle [i ]
38- polygon(
39- x = ezg [[i ]][,1 ],
40- y = ezg [[i ]][,2 ],
41- col = col )
85+ shading <- NULL
86+ if (names(ezg )[i ] %in% highlight_catchments ){
87+ if (highlight_style == " shaded" ){
88+ shading <- 30
89+ } else {
90+ col <- highlight_style
91+ }
92+ }
93+ polygon(x = ezg [[i ]][,1 ], y = ezg [[i ]][,2 ], col = col , density = shading )
94+ if (plot_names ){
95+ text(x = ezg_namePositions [[i ]]$ x , y = ezg_namePositions [[i ]]$ y ,
96+ labels = names(ezg_namePositions )[i ])
97+
98+ }
99+
42100 }
101+
102+ if (plot_names ){
103+ lines(
104+ x = c(ezg_namePositions $ `Chb Ia` $ x + 0.012 , min(ezg $ `Chb Ia` [,1 ]) + 0.004 ),
105+ y = c(ezg_namePositions $ `Chb Ia` $ y - 0.002 , max(ezg $ `Chb Ia` [,2 ]) - 0.002 ))
106+ lines(
107+ x = c(ezg_namePositions $ `Bln IIIa` $ x , mean(ezg $ `Bln IIIa` [,1 ]) + 0.0005 ),
108+ y = c(ezg_namePositions $ `Bln IIIa` $ y + 0.002 , mean(ezg $ `Bln IIIa` [,2 ])))
109+ }
110+ abline(v = par(" usr" )[1 : 2 ])
111+ abline(h = par(" usr" )[3 : 4 ])
112+
43113}
44114
45115# ' Add Berlin districts to a map
0 commit comments