Skip to contents

Define Helper Functions

write_pretty_json <- function(x, path) {
  jsonlite::write_json(x, path = path, pretty = TRUE)
}

top_filter_datatable <- function(x, caption = NULL) {
  DT::datatable(x, filter = "top", caption = caption)
}

create_title_text <- function(x, ncols) {
  paste0(
    paste0(names(x)[1L], ": ", x[1L], collapse = ", "),
    "<br>",
    "<sup>",
    paste0(names(x)[ncols], ": ", x[ncols], collapse =", "),
    "</sup>"
  )
}

also_available <- function(what, format, filename) {
  cat(paste0(
    what, 
    " is also available ", 
    format, 
    " here: ",
    "[https://kwb-r.github.io/wasserportal/", filename, "]",
    "(../", filename, ")"
  ))
}

ggplot2_date_value <- function(data, col) {
  ggplot2::ggplot(data, mapping = ggplot2::aes(
    x = Datum, 
    y = Messwert, 
    col = col
  ))
}

Stations

General overview

# install.packages("remotes")
# remotes::install_github("kwb-r/wasserportal", upgrade = "never", force = TRUE)
library(wasserportal)

overview_options <- wasserportal::get_overview_options()

str(overview_options)
#> List of 2
#>  $ surface_water:List of 7
#>   ..$ water_level         : chr "ows"
#>   ..$ flow                : chr "odf"
#>   ..$ temperature         : chr "owt"
#>   ..$ conductivity        : chr "olf"
#>   ..$ ph                  : chr "oph"
#>   ..$ oxygen_concentration: chr "oog"
#>   ..$ oxygen_saturation   : chr "oos"
#>  $ groundwater  :List of 2
#>   ..$ level  : chr "gws"
#>   ..$ quality: chr "gwq"

system.time(stations <- wasserportal::get_stations())
#> Importing 9 station overviews from Wasserportal Berlin ... ok. (7.38 secs)
#>    user  system elapsed 
#>   0.024   0.005   7.503

str(stations)
#> List of 3
#>  $ overview_list:List of 9
#>   ..$ surface_water.water_level         : tibble [107 × 10] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ Messstellennummer: int [1:107] 5865900 5827103 5870400 5865300 5819900 5864801 5861101 5800107 5800317 5867003 ...
#>   .. ..$ Messstellenname  : chr [1:107] "Allee der Kosmonauten" "Allendestraße" "Alsenbrücke" "Am Bahndamm" ...
#>   .. ..$ Gewaesser        : chr [1:107] "M.-H.-Grenzgr." "Müggelspree" "Griebnitzkanal" "Wuhle" ...
#>   .. ..$ Betreiber        : chr [1:107] "Land Berlin" "Land Berlin" "Land Berlin" "Land Berlin" ...
#>   .. ..$ Datum            : chr [1:107] "26.04.2024 06:15" "26.04.2024 06:15" "26.04.2024 06:15" "" ...
#>   .. ..$ Wasserstand      : num [1:107] 8 53 53 NA 89 6 29 69 99 78 ...
#>   .. ..$ Einheit          : chr [1:107] "cm" "cm" "cm" "cm" ...
#>   .. ..$ Ganglinien       : chr [1:107] "https://wasserportal.berlin.de/station.php?anzeige=g&thema=ows&station=5865900" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=ows&station=5827103" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=ows&station=5870400" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=ows&station=5865300" ...
#>   .. ..$ Klassifikation   : chr [1:107] "niedrig" "normal" "niedrig" "nicht aktuell" ...
#>   .. ..$ stammdaten_link  : chr [1:107] "https://wasserportal.berlin.de/station.php?anzeige=i&thema=ows&station=5865900" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=ows&station=5827103" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=ows&station=5870400" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=ows&station=5865300" ...
#>   ..$ surface_water.flow                : tibble [39 × 10] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ Messstellennummer: int [1:39] 5827103 5870400 5865300 5864801 5867401 5867900 5827101 5870100 5826701 5862811 ...
#>   .. ..$ Messstellenname  : chr [1:39] "Allendestraße" "Alsenbrücke" "Am Bahndamm" "Am Kienberg" ...
#>   .. ..$ Gewaesser        : chr [1:39] "Müggelspree" "Griebnitzkanal" "Wuhle" "Hellersdorfer Graben" ...
#>   .. ..$ Betreiber        : chr [1:39] "Land Berlin" "Land Berlin" "Land Berlin" "Land Berlin" ...
#>   .. ..$ Datum            : chr [1:39] "" "24.04.2024 00:00" "" "26.04.2024 06:15" ...
#>   .. ..$ Durchfluss       : num [1:39] NA -2.43 NA 0.009 0.76 1.39 3.57 7.71 6.71 11.3 ...
#>   .. ..$ Einheit          : chr [1:39] "m³/s" "m³/s" "m³/s" "m³/s" ...
#>   .. ..$ Ganglinie        : chr [1:39] "https://wasserportal.berlin.de/station.php?anzeige=g&thema=odf&station=5827103" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=odf&station=5870400" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=odf&station=5865300" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=odf&station=5864801" ...
#>   .. ..$ Klassifikation   : chr [1:39] "nicht aktuell" "nicht aktuell" "nicht aktuell" "keine" ...
#>   .. ..$ stammdaten_link  : chr [1:39] "https://wasserportal.berlin.de/station.php?anzeige=i&thema=odf&station=5827103" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=odf&station=5870400" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=odf&station=5865300" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=odf&station=5864801" ...
#>   ..$ surface_water.temperature         : tibble [64 × 10] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ Messstellennummer: chr [1:64] "601" "151" "153" "509" ...
#>   .. ..$ Messstellenname  : chr [1:64] "MPS Berlin-Spandauer-Schifffahrtskanal" "MPS Caprivibrücke" "MPS Charlottenburg" "MPS Landwehrkanal" ...
#>   .. ..$ Gewaesser        : chr [1:64] "Berlin-Spandauer-Schifffahrtskanal" "Spree" "Spree" "Landwehrkanal" ...
#>   .. ..$ Betreiber        : chr [1:64] "Land Berlin" "Land Berlin" "Land Berlin" "Land Berlin" ...
#>   .. ..$ Datum            : chr [1:64] "26.04.2024 06:00" "26.04.2024 06:00" "26.04.2024 06:00" "26.04.2024 06:00" ...
#>   .. ..$ Wassertemperatur : chr [1:64] "11.42" "11.39" "11.27" "11.29" ...
#>   .. ..$ Einheit          : chr [1:64] "°C" "°C" "°C" "°C" ...
#>   .. ..$ Ganglinie        : chr [1:64] "https://wasserportal.berlin.de/station.php?anzeige=g&thema=owt&station=601" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=owt&station=151" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=owt&station=153" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=owt&station=509" ...
#>   .. ..$ Klassifikation   : chr [1:64] ">10 - 15°C" ">10 - 15°C" ">10 - 15°C" ">10 - 15°C" ...
#>   .. ..$ stammdaten_link  : chr [1:64] "https://wasserportal.berlin.de/station.php?anzeige=i&thema=owt&station=601" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=owt&station=151" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=owt&station=153" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=owt&station=509" ...
#>   ..$ surface_water.conductivity        : tibble [17 × 10] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ Messstellennummer: chr [1:17] "601" "151" "153" "509" ...
#>   .. ..$ Messstellenname  : chr [1:17] "MPS Berlin-Spandauer-Schifffahrtskanal" "MPS Caprivibrücke" "MPS Charlottenburg" "MPS Landwehrkanal" ...
#>   .. ..$ Gewaesser        : chr [1:17] "Berlin-Spandauer-Schifffahrtskanal" "Spree" "Spree" "Landwehrkanal" ...
#>   .. ..$ Betreiber        : chr [1:17] "Land Berlin" "Land Berlin" "Land Berlin" "Land Berlin" ...
#>   .. ..$ Datum            : chr [1:17] "26.04.2024 06:00" "26.04.2024 06:00" "26.04.2024 06:00" "26.04.2024 06:00" ...
#>   .. ..$ Leitfaehigkeit   : chr [1:17] "828" "807" "809" "810" ...
#>   .. ..$ Einheit          : chr [1:17] "µS/cm" "µS/cm" "µS/cm" "µS/cm" ...
#>   .. ..$ Ganglinie        : chr [1:17] "https://wasserportal.berlin.de/station.php?anzeige=g&thema=olf&station=601" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=olf&station=151" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=olf&station=153" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=olf&station=509" ...
#>   .. ..$ Klassifikation   : chr [1:17] ">800 - 1000" ">800 - 1000" ">800 - 1000" ">800 - 1000" ...
#>   .. ..$ stammdaten_link  : chr [1:17] "https://wasserportal.berlin.de/station.php?anzeige=i&thema=olf&station=601" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=olf&station=151" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=olf&station=153" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=olf&station=509" ...
#>   ..$ surface_water.ph                  : tibble [17 × 9] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ Messstellennummer: chr [1:17] "601" "151" "153" "509" ...
#>   .. ..$ Messstellenname  : chr [1:17] "MPS Berlin-Spandauer-Schifffahrtskanal" "MPS Caprivibrücke" "MPS Charlottenburg" "MPS Landwehrkanal" ...
#>   .. ..$ Gewaesser        : chr [1:17] "Berlin-Spandauer-Schifffahrtskanal" "Spree" "Spree" "Landwehrkanal" ...
#>   .. ..$ Betreiber        : chr [1:17] "Land Berlin" "Land Berlin" "Land Berlin" "Land Berlin" ...
#>   .. ..$ Datum            : chr [1:17] "26.04.2024 06:00" "26.04.2024 06:00" "26.04.2024 06:00" "26.04.2024 06:00" ...
#>   .. ..$ pHWert           : chr [1:17] "7.75" "7.59" "7.73" "7.63" ...
#>   .. ..$ Ganglinie        : chr [1:17] "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oph&station=601" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oph&station=151" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oph&station=153" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oph&station=509" ...
#>   .. ..$ Klassifikation   : chr [1:17] ">7.5 - 8.0" ">7.5 - 8.0" ">7.5 - 8.0" ">7.5 - 8.0" ...
#>   .. ..$ stammdaten_link  : chr [1:17] "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oph&station=601" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oph&station=151" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oph&station=153" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oph&station=509" ...
#>   ..$ surface_water.oxygen_concentration: tibble [17 × 10] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ Messstellennummer: chr [1:17] "601" "151" "153" "509" ...
#>   .. ..$ Messstellenname  : chr [1:17] "MPS Berlin-Spandauer-Schifffahrtskanal" "MPS Caprivibrücke" "MPS Charlottenburg" "MPS Landwehrkanal" ...
#>   .. ..$ Gewaesser        : chr [1:17] "Berlin-Spandauer-Schifffahrtskanal" "Spree" "Spree" "Landwehrkanal" ...
#>   .. ..$ Betreiber        : chr [1:17] "Land Berlin" "Land Berlin" "Land Berlin" "Land Berlin" ...
#>   .. ..$ Datum            : chr [1:17] "26.04.2024 06:00" "26.04.2024 06:00" "26.04.2024 06:00" "26.04.2024 06:00" ...
#>   .. ..$ Sauerstoffgehalt : chr [1:17] "8.67" "8.47" "8.62" "7.27" ...
#>   .. ..$ Einheit          : chr [1:17] "mg/l" "mg/l" "mg/l" "mg/l" ...
#>   .. ..$ Ganglinie        : chr [1:17] "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oog&station=601" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oog&station=151" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oog&station=153" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oog&station=509" ...
#>   .. ..$ Klassifikation   : chr [1:17] ">5 - 10" ">5 - 10" ">5 - 10" ">5 - 10" ...
#>   .. ..$ stammdaten_link  : chr [1:17] "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oog&station=601" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oog&station=151" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oog&station=153" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oog&station=509" ...
#>   ..$ surface_water.oxygen_saturation   : tibble [17 × 10] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ Messstellennummer: chr [1:17] "601" "151" "153" "509" ...
#>   .. ..$ Messstellenname  : chr [1:17] "MPS Berlin-Spandauer-Schifffahrtskanal" "MPS Caprivibrücke" "MPS Charlottenburg" "MPS Landwehrkanal" ...
#>   .. ..$ Gewaesser        : chr [1:17] "Berlin-Spandauer-Schifffahrtskanal" "Spree" "Spree" "Landwehrkanal" ...
#>   .. ..$ Betreiber        : chr [1:17] "Land Berlin" "Land Berlin" "Land Berlin" "Land Berlin" ...
#>   .. ..$ Datum            : chr [1:17] "25.04.2024 23:00" "25.04.2024 23:00" "25.04.2024 23:00" "25.04.2024 23:00" ...
#>   .. ..$ Parameterwert    : chr [1:17] "79.46" "77.84" "79.44" "65.08" ...
#>   .. ..$ Einheit          : chr [1:17] "%" "%" "%" "%" ...
#>   .. ..$ Ganglinie        : chr [1:17] "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oos&station=601" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oos&station=151" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oos&station=153" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=oos&station=509" ...
#>   .. ..$ Klassifikation   : chr [1:17] ">75 - 100" ">75 - 100" ">75 - 100" ">50 - 75" ...
#>   .. ..$ stammdaten_link  : chr [1:17] "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oos&station=601" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oos&station=151" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oos&station=153" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=oos&station=509" ...
#>   ..$ groundwater.level                 : tibble [902 × 11] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ Messstellennummer        : int [1:902] 1 2 3 4 9 21 24 25 26 30 ...
#>   .. ..$ Bezirk                   : chr [1:902] "Reinickendorf" "Reinickendorf" "Reinickendorf" "Reinickendorf" ...
#>   .. ..$ Auspraegung              : chr [1:902] "GW-Stand" "GW-Stand" "GW-Stand + GW-Güte" "GW-Stand" ...
#>   .. ..$ Grundwasserleiter        : chr [1:902] "Hauptgrundwasserleiter (GWL 1.3 + 2)" "Hauptgrundwasserleiter (GWL 1.3 + 2)" "Hauptgrundwasserleiter (GWL 1.3 + 2)" "Hauptgrundwasserleiter (GWL 1.3 + 2)" ...
#>   .. ..$ Grundwasserspannung      : chr [1:902] "gespannt" "ungespannt" "gespannt" "ungespannt" ...
#>   .. ..$ Datum                    : chr [1:902] "09.04.2024" "05.04.2024" "05.04.2024" "09.04.2024" ...
#>   .. ..$ Grundwasserstand_m_ue_NHN: num [1:902] 33.9 35.5 34.2 32.8 37.5 ...
#>   .. ..$ Flur_abstand_m_u_GOK     : chr [1:902] "keine Angabe" "2.19" "keine Angabe" "7.06" ...
#>   .. ..$ Ganglinie                : chr [1:902] "https://wasserportal.berlin.de/station.php?anzeige=g&thema=gws&station=1" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=gws&station=2" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=gws&station=3" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=gws&station=4" ...
#>   .. ..$ Klassifikation           : chr [1:902] "sehr niedrig" "hoch" "sehr hoch" "normal" ...
#>   .. ..$ stammdaten_link          : chr [1:902] "https://wasserportal.berlin.de/station.php?anzeige=i&thema=gws&station=1" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=gws&station=2" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=gws&station=3" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=gws&station=4" ...
#>   ..$ groundwater.quality               : tibble [213 × 10] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ Messstellennummer: int [1:213] 3 145 149 282 344 358 499 580 604 645 ...
#>   .. ..$ Bezirk           : chr [1:213] "Reinickendorf" "Reinickendorf" "Mitte" "Mitte" ...
#>   .. ..$ Auspraegung      : chr [1:213] "GW-Stand + GW-Güte 5" "GW-Stand + GW-Güte 5" "GW-Stand + GW-Güte 5" "GW-Stand + GW-Güte 5" ...
#>   .. ..$ Grundwasserleiter: chr [1:213] "Hauptgrundwasserleiter (GWL 1.3 + 2)" "Hauptgrundwasserleiter (GWL 1.3 + 2)" "Hauptgrundwasserleiter (GWL 1.3 + 2)" "Hauptgrundwasserleiter (GWL 1.3 + 2)" ...
#>   .. ..$ Datum            : chr [1:213] "14.11.2022" "27.09.2022" "06.12.2022" "10.11.2022" ...
#>   .. ..$ Parameterwert    : num [1:213] 12.2 10.9 13.1 12.2 13 12.3 13 13.1 15.6 11.8 ...
#>   .. ..$ Einheit          : chr [1:213] "°C" "°C" "°C" "°C" ...
#>   .. ..$ Ganglinie        : chr [1:213] "https://wasserportal.berlin.de/station.php?anzeige=g&thema=gwq&station=3&nstoffid=10" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=gwq&station=145&nstoffid=10" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=gwq&station=149&nstoffid=10" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=gwq&station=282&nstoffid=10" ...
#>   .. ..$ Klassifikation   : chr [1:213] "keine" "keine" "keine" "keine" ...
#>   .. ..$ stammdaten_link  : chr [1:213] "https://wasserportal.berlin.de/station.php?anzeige=i&thema=gwq&station=3" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=gwq&station=145" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=gwq&station=149" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=gwq&station=282" ...
#>  $ overview_df  :Classes 'data.table' and 'data.frame':  1393 obs. of  27 variables:
#>   ..$ key                      : chr [1:1393] "surface_water.water_level" "surface_water.water_level" "surface_water.water_level" "surface_water.water_level" ...
#>   ..$ Messstellennummer        : chr [1:1393] "5865900" "5827103" "5870400" "5865300" ...
#>   ..$ Messstellenname          : chr [1:1393] "Allee der Kosmonauten" "Allendestraße" "Alsenbrücke" "Am Bahndamm" ...
#>   ..$ Gewaesser                : chr [1:1393] "M.-H.-Grenzgr." "Müggelspree" "Griebnitzkanal" "Wuhle" ...
#>   ..$ Betreiber                : chr [1:1393] "Land Berlin" "Land Berlin" "Land Berlin" "Land Berlin" ...
#>   ..$ Datum                    : chr [1:1393] "26.04.2024 06:15" "26.04.2024 06:15" "26.04.2024 06:15" "" ...
#>   ..$ Wasserstand              : num [1:1393] 8 53 53 NA 89 6 29 69 99 78 ...
#>   ..$ Einheit                  : chr [1:1393] "cm" "cm" "cm" "cm" ...
#>   ..$ Ganglinien               : chr [1:1393] "https://wasserportal.berlin.de/station.php?anzeige=g&thema=ows&station=5865900" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=ows&station=5827103" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=ows&station=5870400" "https://wasserportal.berlin.de/station.php?anzeige=g&thema=ows&station=5865300" ...
#>   ..$ Klassifikation           : chr [1:1393] "niedrig" "normal" "niedrig" "nicht aktuell" ...
#>   ..$ stammdaten_link          : chr [1:1393] "https://wasserportal.berlin.de/station.php?anzeige=i&thema=ows&station=5865900" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=ows&station=5827103" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=ows&station=5870400" "https://wasserportal.berlin.de/station.php?anzeige=i&thema=ows&station=5865300" ...
#>   ..$ Durchfluss               : num [1:1393] NA NA NA NA NA NA NA NA NA NA ...
#>   ..$ Ganglinie                : chr [1:1393] NA NA NA NA ...
#>   ..$ Wassertemperatur         : chr [1:1393] NA NA NA NA ...
#>   ..$ Leitfaehigkeit           : chr [1:1393] NA NA NA NA ...
#>   ..$ pHWert                   : chr [1:1393] NA NA NA NA ...
#>   ..$ Sauerstoffgehalt         : chr [1:1393] NA NA NA NA ...
#>   ..$ Parameterwert            : chr [1:1393] NA NA NA NA ...
#>   ..$ Bezirk                   : chr [1:1393] NA NA NA NA ...
#>   ..$ Auspraegung              : chr [1:1393] NA NA NA NA ...
#>   ..$ Grundwasserleiter        : chr [1:1393] NA NA NA NA ...
#>   ..$ Grundwasserspannung      : chr [1:1393] NA NA NA NA ...
#>   ..$ Grundwasserstand_m_ue_NHN: num [1:1393] NA NA NA NA NA NA NA NA NA NA ...
#>   ..$ Flur_abstand_m_u_GOK     : chr [1:1393] NA NA NA NA ...
#>   ..$ water_body               : chr [1:1393] "surface_water" "surface_water" "surface_water" "surface_water" ...
#>   ..$ variable                 : chr [1:1393] "water_level" "water_level" "water_level" "water_level" ...
#>   ..$ station_type             : chr [1:1393] "ows" "ows" "ows" "ows" ...
#>   ..- attr(*, ".internal.selfref")=<externalptr> 
#>  $ crosstable   : tibble [1,062 × 11] (S3: tbl_df/tbl/data.frame)
#>   ..$ Messstellennummer: chr [1:1062] "5865900" "5827103" "5870400" "5865300" ...
#>   ..$ Messstellenname  : chr [1:1062] "Allee der Kosmonauten" "Allendestraße" "Alsenbrücke" "Am Bahndamm" ...
#>   ..$ ows              : chr [1:1062] "x" "x" "x" "x" ...
#>   ..$ odf              : chr [1:1062] NA "x" "x" "x" ...
#>   ..$ owt              : chr [1:1062] NA NA NA "x" ...
#>   ..$ olf              : chr [1:1062] NA NA NA NA ...
#>   ..$ oph              : chr [1:1062] NA NA NA NA ...
#>   ..$ oog              : chr [1:1062] NA NA NA NA ...
#>   ..$ oos              : chr [1:1062] NA NA NA NA ...
#>   ..$ gws              : chr [1:1062] NA NA NA NA ...
#>   ..$ gwq              : chr [1:1062] NA NA NA NA ...

write_pretty_json(stations$crosstable, "stations_crosstable.json")
top_filter_datatable(
  stations$crosstable, 
  "Data availabilty per monitoring station"
)

The crosstable data for checking data availabilty of the monitoring stations is also available in JSON format here: https://kwb-r.github.io/wasserportal/stations_crosstable.json

GW level

Master data

Overview data of GW level stations can be requested as shown below:

top_filter_datatable(stations$overview_list$groundwater.level)

Master data of GW level stations can be requested as shown below:

stations_gwl_master <- wasserportal::get_wasserportal_masters_data(
  master_urls = stations$overview_list$groundwater.level$stammdaten_link
)
#> Importing 902 station metadata from Wasserportal Berlin ... ok. (10.59 mins)

write_pretty_json(stations_gwl_master, "stations_gwl_master.json")

top_filter_datatable(stations_gwl_master)

The master data of GW level stations is also available in JSON format here: https://kwb-r.github.io/wasserportal/stations_gwl_master.json

Trend Classification

GW level trend classification (provided by SenWeb) is visualized below.

Trend Classification Histogramm
gwl <- stations$overview_list$groundwater.level %>% 
  dplyr::mutate(Datum = as.Date(Datum, format = "%d.%m.%Y"))

text_low_levels <- c("extrem niedrig", "sehr niedrig", "niedrig")
text_high_levels <- c("hoch", "sehr hoch", "extrem hoch")
levels_ordered <- c(text_low_levels, "normal", text_high_levels, "keine")

gwl$Klassifikation <- forcats::fct_relevel(gwl$Klassifikation, levels_ordered)

gwl_classified_only <- gwl %>% 
  dplyr::filter(Klassifikation != "keine")

percental_share_low_levels <- kwb.utils::percentage(
  sum(gwl_classified_only$Klassifikation %in% text_low_levels), 
  basis = nrow(gwl_classified_only)
)

percental_share_high_levels <- kwb.utils::percentage(
  sum(gwl_classified_only$Klassifikation %in% text_high_levels), 
  basis = nrow(gwl_classified_only)
)

title_text <- sprintf(
  "GW level classification (n = %d out of %d have 'classification' data)",
  nrow(gwl_classified_only), 
  nrow(gwl)
)

g1 <- gwl_classified_only %>% 
  dplyr::count(Klassifikation, Grundwasserspannung) %>% 
  dplyr::mutate(percental_share = kwb.utils::percentage(n, nrow(gwl))) %>% 
  ggplot2::ggplot(ggplot2::aes(
    x = Klassifikation,
    y = percental_share,
    fill = Grundwasserspannung
  )) +
  ggplot2::geom_bar(stat = "identity") + 
  ggplot2::labs(
    title = title_text,
    x = "Classification",
    y = "Percental share (%)"
  ) +
  ggplot2::theme_bw()

plotly::ggplotly(g1)

12.26 percent of all considered 824 GW level monitoring stations containing classification data (out of 902 provided by SenWeb) indicate below normal (extrem niedrig, sehr niedrig, niedrig) GW levels. However, only 12.26 percent are indicate above normal (hoch, sehr hoch, extrem hoch) GW levels.

Trend Classification Map
level_colors <- data.frame(
  Klassifikation = levels_ordered, 
  classi_color = c(
    "darkred", 
    "red", 
    "orange", 
    "green", 
    "lightblue", 
    "blue", 
    "darkblue", 
    "grey"
  )
)

rechtswert <- "Rechtswert_UTM_33_N"
hochwert <- "Hochwert_UTM_33_N"

gwl_classified_only_with_coords <- gwl_classified_only %>% 
  dplyr::mutate(
    Messstellennummer = as.character(Messstellennummer),
  ) %>% 
  dplyr::left_join(
    stations_gwl_master %>%
      dplyr::select(dplyr::all_of(c("Nummer", rechtswert, hochwert))) %>% 
      dplyr::rename(Messstellennummer = "Nummer"),
    by = "Messstellennummer"
  ) %>% 
  dplyr::left_join(
    level_colors, 
    by = "Klassifikation"
  ) %>% 
  sf::st_as_sf(
    coords = c(rechtswert, hochwert), 
    crs = 25833
  ) %>% 
  sf::st_transform(crs = 4326)

# Create a vector of labels for each row in gwl_classified_only_with_coords
labs <- wasserportal::columns_to_labels(
  data = gwl_classified_only_with_coords, 
  columns = c(
    "Messstellennummer", 
    "Grundwasserspannung", 
    "Klassifikation", 
    "Datum"
  ),
  fmt = "<p>%s: %s</p>",
  sep = ""
)

# Print Map
gwlmap <- gwl_classified_only_with_coords %>% 
  leaflet::leaflet() %>%
  leaflet::addTiles() %>% 
  leaflet::addProviderTiles(leaflet::providers$CartoDB.Positron) %>%
  leaflet::addCircles(
    color = ~classi_color,
    label = lapply(labs, htmltools::HTML)
  ) %>% 
  leaflet::addLegend(
    position = "topright",
    colors = level_colors$classi_color,
    labels = level_colors$Klassifikation,
    title = sprintf(
      "Classification (latest data: %s)",
      max(gwl_classified_only_with_coords$Datum)
    )
  )

htmlwidgets::saveWidget(
  gwlmap, 
  "./map_gwl-trend.html", 
  title = "GW level trend"
)

gwlmap

GW level trend plot is also available on a full html page here: https://kwb-r.github.io/wasserportal/map_gwl-trend.html

Download and Plotting One Station

for total period available.

station_gwl <- stations$overview_list$groundwater.level[1L, ]

ncols <- 2:ncol(station_gwl)

gw_level <- wasserportal::read_wasserportal_raw_gw(
  station = station_gwl$Messstellennummer, 
  stype = "gwl"
) %>% 
  dplyr::mutate(Label = sprintf("%s (%s)", Parameter, Einheit))

head(gw_level)

g <- gw_level %>% 
  ggplot2_date_value(col = "Label") +
  ggplot2::geom_line() +
  ggplot2::geom_point() +
  ggplot2::theme_bw()

title_subtitle <- create_title_text(x = station_gwl, ncols = ncols)

plotly::ggplotly(g) %>%
  plotly::layout(title = list(text = title_subtitle))

Download and Plotting Multiple Stations

debug <- FALSE

gw_level_multi <- data.table::rbindlist(lapply(
  stations$overview_list$groundwater.level$Messstellennummer, 
  function(id) kwb.utils::catAndRun(
    sprintf("Downloading Messstellennummer == '%s'", id), 
    wasserportal::read_wasserportal_raw_gw(station = id, stype = "gwl"), 
    dbg = debug
  )
))

readr::write_csv(gw_level_multi, file = "groundwater_level.csv")

# Plot 10 GW level
selected_stations <- stations$overview_list$groundwater.level$Messstellennummer[1:10]

g <- gw_level_multi %>% 
  dplyr::filter(Messstellennummer %in% selected_stations) %>% 
  dplyr::mutate(Messstellennummer = as.character(Messstellennummer)) %>% 
  ggplot2_date_value(col = "Messstellennummer") +
  ggplot2::labs(title = "GW level (m above NN)") +
  ggplot2::geom_line() +
  ggplot2::geom_point() +
  ggplot2::theme_bw()

plotly::ggplotly(g)

The data of all GW level stations is also available in CSV format here: https://kwb-r.github.io/wasserportal/groundwater_level.csv

GW quality

Overview data of GW level stations can be requested as shown below:

stations_gwq <- wasserportal::get_wasserportal_stations_table(
  type = overview_options$groundwater$quality
)

top_filter_datatable(stations_gwq)

Master data of GW quality stations can be requested as shown below:

stations_gwq_master <- wasserportal::get_wasserportal_masters_data(
  master_urls = stations_gwq$stammdaten_link
)
#> Importing 213 station metadata from Wasserportal Berlin ... ok. (1.96 mins)

write_pretty_json(stations_gwq_master, "stations_gwq_master.json")

The master data of GW quality stations is also available in JSON format here: https://kwb-r.github.io/wasserportal/stations_gwq_master.json

GW Quality: Download and Plotting One Station

station_gwq <- stations$overview_list$groundwater.quality[1L, ]

ncols <- 2:ncol(station_gwq)

gw_quality <- wasserportal::read_wasserportal_raw_gw(
  station = station_gwq$Messstellennummer, 
  stype = "gwq"
)

head(gw_quality)

unique(gw_quality$Parameter)

g <- gw_quality %>%  
  dplyr::filter(Parameter == "Sulfat") %>% 
  ggplot2_date_value(col = "Parameter") +
  ggplot2::geom_line() +
  ggplot2::geom_point() +
  ggplot2::theme_bw()

title_subtitle <- create_title_text(x = station_gwq, ncols = ncols)

plotly::ggplotly(g) %>%
  plotly::layout(title = list(text = title_subtitle))

GW Quality: Download and Plotting Multiple Stations

debug <- FALSE

gw_quality_multi <- data.table::rbindlist(lapply(
  stations$overview_list$groundwater.quality$Messstellennummer, 
  function(id) kwb.utils::catAndRun(
    sprintf("Downloading Messstellennummer == '%s'", id), 
    wasserportal::read_wasserportal_raw_gw(station = id, stype = "gwq"), 
    dbg = debug
  )
))

readr::write_csv(gw_quality_multi, "groundwater_quality.csv")

# Plot 10 GW quality 
selected_stations <- stations$overview_list$groundwater.quality$Messstellennummer[1:10]

g <- gw_quality_multi %>% 
  dplyr::filter(Messstellennummer %in% selected_stations) %>% 
  dplyr::mutate(Messstellennummer = as.character(Messstellennummer)) %>% 
  dplyr::filter(Parameter == "Sulfat") %>% 
  ggplot2_date_value(col = "Messstellennummer") +
  ggplot2::labs(title = "GW quality (Sulfat)") +
  ggplot2::geom_line() +
  ggplot2::geom_point() +
  ggplot2::theme_bw()

plotly::ggplotly(g)

The data of all GW quality stations is also available in CSV format here: https://kwb-r.github.io/wasserportal/groundwater_quality.csv