library("tibble") library("dplyr") library("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) )
geocode()
geocodes a single addressreverse_geocode()
reverse geocodes a single pair of longitude and latitudegeocode_tbl()
geocodes a data framereverse_geocode_tbl()
reverse geocodes a data frameGeocoding is the process of transforming a human readable address into a location (ie a pair of latitude and longitude).
geocode(query = "39 quai André Citroën, Paris") %>% glimpse()
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.
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) %>% glimpse()
geocode_tbl(tbl = table_test, adresse = adress, code_postal = postal_code) %>% glimpse()
data("paris2012") paris2012 %>% slice(1:100) %>% mutate( adresse = paste(numero, voie, nom), code_insee = paste0("751", arrondissement) ) %>% geocode_tbl(adresse = adresse, code_insee = code_insee) %>% glimpse()
Reverse geocoding is the process of back (reverse) coding of a point location (latitude, longitude) to a human readable address.
reverse_geocode()
takes longitude and latitude as arguments and returns a data frame with addresses.
reverse_geocode(long = 2.279092, lat = 48.84683) %>% glimpse()
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) %>% glimpse
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.