Dutch placename mapper

2024-04-28

Inspired by https://placenames.rtwilson.com, I thought I’d try to make such place name visualizations of the Netherlands myself.

The Dutch platform PDOK provides open geo-information datasets through webservices and downloads. Here, we use the location API to search for residence locations using Solr-syntax. We also use the gray background map from PDOK, and use leaflet to create interactive maps.

library(tidyverse)
library(leaflet)
library(sf)

pdok_query_url <- "https://api.pdok.nl/bzk/locatieserver/search/v3_1/free?q={location}&fq=type:woonplaats&fq=bron:BAG&fl=id woonplaatsnaam weergavenaam centroide_ll&df=woonplaatsnaam&rows=100"
pdok_map_url <- "https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/grijs/EPSG:3857/{z}/{x}/{y}.png"

addLocationMarkers <- function(map, location, fillColor) {
  url <- URLencode(str_glue(pdok_query_url))
  res <- jsonlite::read_json(url, simplifyVector = TRUE)
  
  df <- bind_rows(res$response$docs) %>% 
    mutate(lng = as.numeric(str_extract(centroide_ll, "[\\d\\.]+\\s")),
           lat = as.numeric(str_extract(centroide_ll, "\\s[\\d\\.]+")))
  
  map <- addCircleMarkers(map, lng=df$lng, lat=df$lat, popup = df$woonplaatsnaam,
                          stroke = F, radius = 5, fillOpacity = 1, fillColor = fillColor, color = fillColor)
  
  return(map)
}

create_map <- function(markers) {
  
  map <- leaflet() %>% 
    setView(zoom=7, lng=5.4, lat=52.2) %>%
    addTiles(urlTemplate = pdok_map_url,
             attribution = "<a href='https://www.pdok.nl/'>PDOK</a>",
             options = tileOptions(minZoom = 6, maxZoom = 18)
    )
  
  for (location in names(markers)) {
    map <- addLocationMarkers(map, location, markers[[location]])
  }
  map <- addLegend(map, position = "bottomright",
                   colors = unname(unlist(markers)),
                   labels = names(markers),
                   opacity = 1)
  return(map)
}

This allows us to create maps of common Dutch toponym patterns, such as “loo” (Germanic), “recht” (Roman) or “ga” (Frisian).

create_map(list(
  "*loo OR *lo OR *le" = "blue",
  "*recht OR *richt" = "green",
  "*ga" = "red",
  "*wolde" = "orange",
  "*schot" = "black",
  "*wijk" = "magenta"
))

Or places which contain river names:

create_map(list(
  "*rijn*" = "red",
  "*maas*" = "green",
  "*lek*" = "orange",
  "*ijssel*" = "blue",
  "*zaan*" = "black",
  "*waal*" = "magenta"
))