The goal of
nominatimlite is to provide a light
interface for geocoding addresses, based on the Nominatim API.
Nominatim is a tool to search OpenStreetMap data by name and
address (geocoding) and to generate synthetic addresses of
OSM points (reverse geocoding).
It also allows to load spatial objects using the
Full site with examples and vignettes on https://dieghernan.github.io/nominatimlite/
The main goal of
nominatimlite is to access the
Nominatim API avoiding the dependency on
curl. In some
curl may not be available or accessible, so
nominatimlite uses base functions to overcome this
There are other packages much more complete and mature than
nominatimlite, that presents similar features:
tidygeocoderby Jesse Cambon. Allows to interface with Nominatim, Google, TomTom, Mapbox, etc. for geocoding and reverse geocoding.
osmdataby Mark Padgham. Great for downloading spatial data from OpenStreetMap, via the Overpass API.
nominatimlite you can extract spatial objects
library(nominatimlite) # Extract some points - Pizza Hut in California <- geo_lite_sf("California", points_only = FALSE) CA <- geo_lite_sf("Pizza Hut, California", pizzahut limit = 50, custom_query = list(countrycodes = "us") ) library(ggplot2) ggplot(CA) + geom_sf() + geom_sf(data = pizzahut, col = "red")
You can also extract polygon and line objects (if available) using
points_only = FALSE:
<- geo_lite_sf("Pentagon", points_only = FALSE) pentagon_poly ggplot(pentagon_poly) + geom_sf()
Note: examples adapted from
In this first example we will geocode a few addresses using the
library(tibble) # create a dataframe with addresses <- tribble( some_addresses ~name, ~addr, "White House", "1600 Pennsylvania Ave NW, Washington, DC", "Transamerica Pyramid", "600 Montgomery St, San Francisco, CA 94111", "Willis Tower", "233 S Wacker Dr, Chicago, IL 60606" ) # geocode the addresses <- geo_lite(some_addresses$addr, lat = "latitude", long = "longitude")lat_longs
Only latitude and longitude are returned from the geocoder service in
this example, but
full_results = TRUE can be used to return
all of the data from the geocoder service.
|1600 Pennsylvania Ave NW, Washington, DC||38.89770||-77.03655||White House, 1600, Pennsylvania Avenue Northwest, Washington, District of Columbia, 20500, United States|
|600 Montgomery St, San Francisco, CA 94111||37.79520||-122.40279||Transamerica Pyramid, 600, Montgomery Street, Chinatown, San Francisco, California, 94111, United States|
|233 S Wacker Dr, Chicago, IL 60606||41.87887||-87.63591||Willis Tower, 233, South Wacker Drive, Printer’s Row, Loop, Chicago, Cook County, Illinois, 60606, United States|
To perform reverse geocoding (obtaining addresses from geographic
coordinates), we can use the
The arguments are similar to the
geo_lite() function, but
now we specify the input data columns with the
long arguments. The dataset used here is from the geocoder
query above. The single line address is returned in a column named by
<- reverse_geo_lite( reverse lat = lat_longs$latitude, long = lat_longs$longitude, address = "address_found" )
|White House, 1600, Pennsylvania Avenue Northwest, Washington, District of Columbia, 20500, United States||38.89770||-77.03655|
|Transamerica Pyramid, 600, Montgomery Street, Chinatown, San Francisco, California, 94111, United States||37.79520||-122.40279|
|Willis Tower, 233, South Wacker Drive, Printer’s Row, Loop, Chicago, Cook County, Illinois, 60606, United States||41.87887||-87.63591|
For more advance users, see Nominatim docs to check the parameters available.