Skip to content

Instantly share code, notes, and snippets.

@FrieseWoudloper
Last active December 22, 2019 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrieseWoudloper/3a29abd0aa753a01402473054c84c504 to your computer and use it in GitHub Desktop.
Save FrieseWoudloper/3a29abd0aa753a01402473054c84c504 to your computer and use it in GitHub Desktop.
Geocoding example - uses PDOK LocationServer
library(httr)
library(dplyr)
library(readr)
library(purrr)
library(magrittr)
f <- "http://www.landelijkregisterkinderopvang.nl/opendata/export_opendata_lrk.csv"
input <- read_delim(f, delim = ";") %>%
mutate(adres = paste(opvanglocatie_adres, opvanglocatie_postcode, opvanglocatie_woonplaats)) %>%
select(lrk_id, adres, bag_id) %>%
head(100) # Ik pak alleen de eerste 100 rijen in de dataset, anders duurt het zo lang ;)
# Er zit een fout in het inputbestand: voor sommige rijen ontbreken de laatste 1-10 kolommen.
geocode <- function(adres){
GET(url = "https://geodata.nationaalgeoregister.nl",
path = "locatieserver/v3/free",
query = list(qf = "exacte_match^1 suggest^0.5 huisnummer^0.5 huisletter^0.5 huisnummertoevoeging^0.5",
fq = "type:adres AND bron:BAG",
fl = "*",
q = adres,
rows = 1)) %>%
content() %>%
pluck('response', 'docs', 1)
}
output <- map_dfr(input$adres, function(x) {
attrs <- c("adresseerbaarobject_id", "weergavenaam", "centroide_ll")
geocode(x) %>% extract(attrs)
})
matched <- bind_cols(input, output)
print(matched)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment