Read WFS Dataset

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.55 secs)

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.74 secs)
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 4 10 2 12 7 11 9 5 6 ...
#>  $ namgem: chr [1:12] "Pankow" "Charlottenburg-Wilmersdorf" "Marzahn-Hellersdorf" "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 11000004 11000010 11000002 11000012 11000007 11000011 11000009 11000005 11000006 ...
#>  $ geom  :sfc_MULTIPOLYGON of length 12; first list element: List of 4
#>   ..$ :List of 2
#>   .. ..$ : num [1:3249, 1:2] 399003 398981 398914 398873 398844 ...
#>   .. ..$ : num [1:7, 1:2] 394016 394041 394045 394036 394027 ...
#>   ..$ :List of 1
#>   .. ..$ : num [1:7, 1:2] 391270 391271 391266 391259 391256 ...
#>   ..$ :List of 1
#>   .. ..$ : num [1:6, 1:2] 391281 391282 391284 391279 391278 ...
#>   ..$ :List of 1
#>   .. ..$ : num [1:18, 1:2] 398824 398825 398819 398783 398780 ...
#>   ..- 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