Geocoding French adresses with BanR

# generate fake data
table_test <- tibble::tibble(
  adress = c("39 quai André Citroën", "64 Allée de Bercy", "20 avenue de Ségur"),
  postal_code = c("75015", "75012", "75007"),
  z = rnorm(3)


Geocoding is the process of transforming a human readable address into a location (ie a pair of latitude and longitude).

A single address

geocode(query = "39 quai André Citroën, Paris") %>%

The BAN API sends back both projected/Cartesian coordinates (x and y columns - they use Lambert 93 projection, aka as EPSG:2154), and lon/lat (i.e. WGS84) coordinates (longitude and latitude columns). It also indicates the degree of confidence it has in each result (column score). The above example only sends back one result, but sometimes the API will send back several suggestion for the same query. They are ordered by descending order of confidence.

A data frame

In addition to the adress, geocode_tbl() can take as argument either the postal code or the French official code (INSEE code) of the commune.

geocode_tbl(tbl = table_test, adresse = adress) %>%
geocode_tbl(tbl = table_test, adresse = adress, code_postal = postal_code) %>%
paris2012 %>%
  slice(1:100) %>%
    adresse = paste(numero, voie, nom),
    code_insee = paste0("751", arrondissement)
    ) %>%
  geocode_tbl(adresse = adresse, code_insee = code_insee) %>%

Reverse geocode

Reverse geocoding is the process of back (reverse) coding of a point location (latitude, longitude) to a human readable address.

A single adress

reverse_geocode() takes longitude and latitude as arguments and returns a data frame with addresses.

reverse_geocode(long =  2.279092, lat = 48.84683)  %>%

A data frame

reverse_geocode_tbl takes the names of the longitude and latitude columns and returns a data frame with adresses.

test_df <- tibble::tibble(
  nom = sample(letters, size = 10, replace = FALSE),
  lon = runif(10, 2.19, 2.47),
  lat = runif(10, 48.8, 48.9)

test_df %>% 
  reverse_geocode_tbl(lon, lat) %>% 

Try the banR package in your browser

Any scripts or data that you put into this service are public.

banR documentation built on July 8, 2020, 6:47 p.m.