Geometry API changed?

I was using this code to request NL geometry which was working really well and saved having to store and copy shapefiles for different projects. However, it seems to have stopped working and I can’t figure out why. The code was:

list_of_geos <- c("landsdeel", "provincie", "coropgebied", "gemeente")

## choose year and geometry

for (geo_nam in list_of_geos){
  
  year <- "2021"
  
  url <- parse_url("https://geodata.nationaalgeoregister.nl/cbsgebiedsindelingen/wfs")
  url$query <- list(service = "WFS",
                    version = "2.0.0",
                    request = "GetFeature",
                    typename = paste0("cbsgebiedsindelingen:cbs_", geo_nam, "_", year, "_gegeneraliseerd"),
                    outputFormat = "application/json")
  request <- build_url(url)
  
  geo_sf <- st_read(request)
  
  assign(geo_nam, geo_sf)
  
}

and an example of the final request was:

https://geodata.nationaalgeoregister.nl/cbsgebiedsindelingen/wfs?service=WFS&version=2.0.0&request=GetFeature&typename=cbsgebiedsindelingen%3Acbs_landsdeel_2020_gegeneraliseerd&outputFormat=application%2Fjson

Any help much appreciated

The Gebiedsindelingen have changed, see Dataset CBS Gebiedsindelingen 2022 nu bij PDOK beschikbaar - PDOK.

You’ll need to change your url, see
https://www.pdok.nl/geo-services/-/article/cbs-gebiedsindelingen

2 likes

Oh, by the way: if you want to stay informed about such changes, you can sign up for an email-list here: https://www.pdok.nl/attenderingsservice

Forgot to mention that, sorry. I’m afraid the emails will be in Dutch, but they will be posted here as well, so you can always ask here if Google Translate messes up too much :wink:

1 like

Still not quite working out:

geo_nam <- 'landsdeel'
  url <- parse_url("https://service.pdok.nl/cbs/gebiedsindelingen/2023/wfs/")
  url$query <- list(service = "WFS",
                    version = "2.0.0",
                    request = "GetFeature",
                    typename = paste0("cbsgebiedsindelingen:cbs_", geo_nam, "_gegeneraliseerd"),
                    outputFormat = "application/json")
  request <- build_url(url)
  
  geo_sf <- st_read(request, quiet = TRUE)
  
  assign(geo_nam, geo_sf)

What is wrong?

You are missing the v1_0 bit at the end of the URL. The full url is

https://service.pdok.nl/cbs/gebiedsindelingen/2023/wfs/v1_0

Also check the featurenames, those have changed as well: in your example the featurename would resolve to
cbsgebiedsindelingen:cbs_landsdeel_gegeneraliseerd,
but that has become
gebiedsindelingen:landsdeel_gegeneraliseerd

(so without the cbs prefix). Make sure to check the WFS Capabilities for these kinds of changes.

HTH,
Stefan

Brilliant - thanks!

For clarity here is the working loop:

list_of_geos <- c("landsdeel", "provincie", "coropgebied", "gemeente")

## loop through main geometries

for (geo_nam in list_of_geos){
  
  ## define url
  url <- parse_url("https://service.pdok.nl/cbs/gebiedsindelingen/2023/wfs/v1_0")
  ## build request
  url$query <- list(service = "WFS",
                    version = "2.0.0",
                    request = "GetFeature",
                    typename = paste0("gebiedsindelingen:", geo_nam,  "_gegeneraliseerd"),
                    outputFormat = "application/json")
  request <- build_url(url)
  ## request shapes
  geo_sf <- st_read(request, quiet = TRUE)
  ## assign environment name
  assign(geo_nam, geo_sf)
  
}

1 like

Dit topic is 180 dagen na het laatste antwoord automatisch gesloten. Nieuwe antwoorden zijn niet meer toegestaan.