Skip to contents

Read

Read Metadata

library(kwb.fisbroker)

dataset_id <- "s_wfs_alkis_bezirk"

berlin_bezirke_metadata <- kwb.fisbroker::read_metadata(
  dataset_id, 
  service_type = "WFS"
)
#> Getting HTML text from 'https://fbinter.stadt-be...ezirk@senstadt&type=WFS' ... ok. (0.53s)

DT::datatable(berlin_bezirke_metadata)

Read WFS

berlin_bezirke <- kwb.fisbroker::read_wfs(dataset_id)
#> Importing WFS dataset_id 's_wfs_alkis_bezirk' from FIS-Broker ... ok. (0.64s)
str(berlin_bezirke)
#> sf [12 × 7] (S3: sf/tbl_df/tbl/data.frame)
#>  $ gml_id: chr [1:12] "s_wfs_alkis_bezirk.1" "s_wfs_alkis_bezirk.2" "s_wfs_alkis_bezirk.3" "s_wfs_alkis_bezirk.4" ...
#>  $ gem   : int [1:12] 3 9 7 2 6 11 4 10 5 12 ...
#>  $ namgem: chr [1:12] "Pankow" "Treptow-Köpenick" "Tempelhof-Schöneberg" "Friedrichshain-Kreuzberg" ...
#>  $ namlan: chr [1:12] "Berlin" "Berlin" "Berlin" "Berlin" ...
#>  $ lan   : int [1:12] 11 11 11 11 11 11 11 11 11 11 ...
#>  $ name  : int [1:12] 11000003 11000009 11000007 11000002 11000006 11000011 11000004 11000010 11000005 11000012 ...
#>  $ geom  :sfc_MULTIPOLYGON of length 12; first list element: List of 4
#>   ..$ :List of 1
#>   .. ..$ : num [1:7, 1:2] 391270 391262 391256 391259 391266 ...
#>   ..$ :List of 1
#>   .. ..$ : num [1:6, 1:2] 391281 391278 391279 391284 391282 ...
#>   ..$ :List of 1
#>   .. ..$ : num [1:18, 1:2] 398780 398783 398819 398825 398824 ...
#>   ..$ :List of 2
#>   .. ..$ : num [1:3251, 1:2] 394902 394885 394883 394867 394854 ...
#>   .. ..$ : num [1:7, 1:2] 394016 394041 394045 394036 394027 ...
#>   ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
#>  - attr(*, "sf_column")= chr "geom"
#>  - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA
#>   ..- attr(*, "names")= chr [1:6] "gml_id" "gem" "namgem" "namlan" ...

DT::datatable(berlin_bezirke)

Plot

Simple Plot

### Define Helper Function
plot_bezirke <- function(layer) {
  
  ## fix as name for "geometry" (sf v1.0-7) seems to be renamed to "geom" in 
  ## sf v1.0-8 (or if not might be different on macos)
  sf_geometry_name <- c("geom", "geometry")
  columns <- names(layer)[names(layer) %in% c("namgem", sf_geometry_name)]
  
  plot(layer[,columns])
}

plot_bezirke(berlin_bezirke)

Leaflet Plot

### Plot to check if Berlin boundaries are plotted correctly.
### Set target CRS
crs_target <- 4326

basemap <- berlin_bezirke %>%
  sf::st_transform(crs = crs_target) %>%
  leaflet::leaflet() %>%
  leaflet::addTiles() %>%
  leaflet::addProviderTiles(leaflet::providers$CartoDB.Positron) %>%
  leaflet::addPolygons(stroke = FALSE, 
                       fillColor = rainbow(n = length(berlin_bezirke$namgem)), 
                       fill = TRUE) %>% 
  leaflet::addLegend(
    position = "topright",
    colors = rainbow(n = length(berlin_bezirke$namgem)),
    labels = berlin_bezirke$namgem,
    title = "Berliner Bezirke")

basemap