| Title: | Interface to the 'Nominatim' API |
|---|---|
| Description: | Lightweight interface to the 'OpenStreetMap' 'Nominatim' API <https://nominatim.org/release-docs/latest/>. Extract coordinates from addresses, retrieve addresses from coordinates, look up amenities and addresses, and return results as 'tibble' or 'sf' objects. |
| Authors: | Diego Hernangómez [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-8457-4658>), Jindra Lacko [ctb, rev] (ORCID: <https://orcid.org/0000-0002-0375-5156>), Alex White [ctb], OpenStreetMap [cph] (For the data) |
| Maintainer: | Diego Hernangómez <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.6.0 |
| Built: | 2026-06-08 00:10:27 UTC |
| Source: | https://github.com/dieghernan/nominatimlite |
sfc POLYGON objectCreate a sfc object from the coordinates of a bounding box.
bbox_to_poly(bbox = NA, xmin = NA, ymin = NA, xmax = NA, ymax = NA, crs = 4326)bbox_to_poly(bbox = NA, xmin = NA, ymin = NA, xmax = NA, ymax = NA, crs = 4326)
bbox |
Numeric vector of 4 elements representing the coordinates of the
bounding box. Values should be |
xmin, ymin, xmax, ymax
|
Alternatively, you can use these named parameters
instead of |
crs |
coordinate reference system, something suitable as input to st_crs |
Bounding boxes can be located using online tools such as https://boundingbox.klokantech.com/.
A sfc object of class POLYGON with the corresponding
coordinate reference system crs.
sf::st_as_sfc() and sf::st_sfc().
sf outputs:
geo_address_lookup_sf(),
geo_amenity_sf(),
geo_lite_sf(),
geo_lite_struct_sf(),
reverse_geo_lite_sf()
# Bounding box of Germany bbox_GER <- c(5.86631529, 47.27011137, 15.04193189, 55.09916098) bbox_GER_sf <- bbox_to_poly(bbox_GER) library(ggplot2) ggplot(bbox_GER_sf) + geom_sf() # Extract the bounding box of an sf object sfobj <- geo_lite_sf("seychelles", points_only = FALSE) sfobj # Require at least one non-empty object if (!all(sf::st_is_empty(sfobj))) { bbox <- sf::st_bbox(sfobj) bbox bbox_sfobj <- bbox_to_poly(bbox) ggplot(bbox_sfobj) + geom_sf(fill = "lightblue", alpha = 0.5) + geom_sf(data = sfobj, fill = "wheat") }# Bounding box of Germany bbox_GER <- c(5.86631529, 47.27011137, 15.04193189, 55.09916098) bbox_GER_sf <- bbox_to_poly(bbox_GER) library(ggplot2) ggplot(bbox_GER_sf) + geom_sf() # Extract the bounding box of an sf object sfobj <- geo_lite_sf("seychelles", points_only = FALSE) sfobj # Require at least one non-empty object if (!all(sf::st_is_empty(sfobj))) { bbox <- sf::st_bbox(sfobj) bbox bbox_sfobj <- bbox_to_poly(bbox) ggplot(bbox_sfobj) + geom_sf(fill = "lightblue", alpha = 0.5) + geom_sf(data = sfobj, fill = "wheat") }
The lookup API queries the address and other details of one or more
OSM objects, such as nodes, ways or relations, and returns the
tibble associated with the query. See
geo_address_lookup_sf() for retrieving the data as an sf
object.
geo_address_lookup( osm_ids, type = c("N", "W", "R"), lat = "lat", long = "lon", full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", custom_query = list() )geo_address_lookup( osm_ids, type = c("N", "W", "R"), lat = "lat", long = "lon", full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", custom_query = list() )
osm_ids |
Vector of OSM identifiers as numeric values, for example
|
type |
Character vector of the OSM object type associated with each
|
lat |
Latitude column name in the output data (default |
long |
Longitude column name in the output data (default |
full_results |
Return all available data from the Nominatim API.
If |
return_addresses |
Return input addresses with results if |
verbose |
If |
nominatim_server |
URL of the Nominatim server to use. Defaults to
|
custom_query |
Named list with API-specific parameters, for example
|
See https://nominatim.org/release-docs/latest/api/Lookup/ for additional
parameters to be passed to custom_query.
A tibble with the results that match the query.
Address lookup:
geo_address_lookup_sf()
Geocoding:
geo_address_lookup_sf(),
geo_amenity(),
geo_amenity_sf(),
geo_lite(),
geo_lite_sf(),
geo_lite_struct(),
geo_lite_struct_sf()
ids <- geo_address_lookup(osm_ids = c(46240148, 34633854), type = "W") ids several <- geo_address_lookup(c(146656, 240109189), type = c("R", "N")) severalids <- geo_address_lookup(osm_ids = c(46240148, 34633854), type = "W") ids several <- geo_address_lookup(c(146656, 240109189), type = c("R", "N")) several
The lookup API queries the address and other details of one or more
OSM objects, such as nodes, ways or relations, and returns the
sf object associated with the query using sf. See
geo_address_lookup() for retrieving the data in tibble
format.
geo_address_lookup_sf( osm_ids, type = c("N", "W", "R"), full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", custom_query = list(), points_only = TRUE )geo_address_lookup_sf( osm_ids, type = c("N", "W", "R"), full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", custom_query = list(), points_only = TRUE )
osm_ids |
Vector of OSM identifiers as numeric values, for example
|
type |
Character vector of the OSM object type associated with each
|
full_results |
Return all available data from the Nominatim API.
If |
return_addresses |
Return input addresses with results if |
verbose |
If |
nominatim_server |
URL of the Nominatim server to use. Defaults to
|
custom_query |
Named list with API-specific parameters, for example
|
points_only |
Logical |
See https://nominatim.org/release-docs/latest/api/Lookup/ for additional
parameters to be passed to custom_query.
An sf object with the results that match the query.
The parameter points_only specifies whether the function results will be
points (all Nominatim results are guaranteed to have at least point
geometry) or other geometry types.
Note that when points_only = FALSE, the type of geometry returned depends
on the object being geocoded. Administrative areas, major buildings and the
like will be returned as polygons, rivers, roads and similar features will
be returned as lines, and amenities may still be returned as points.
This function is vectorized, allowing multiple addresses to be geocoded.
With points_only = FALSE, multiple geometry types may be returned.
Address lookup:
geo_address_lookup()
Geocoding:
geo_address_lookup(),
geo_amenity(),
geo_amenity_sf(),
geo_lite(),
geo_lite_sf(),
geo_lite_struct(),
geo_lite_struct_sf()
sf outputs:
bbox_to_poly(),
geo_amenity_sf(),
geo_lite_sf(),
geo_lite_struct_sf(),
reverse_geo_lite_sf()
# Notre Dame Cathedral, Paris NotreDame <- geo_address_lookup_sf(osm_ids = 201611261, type = "W") # Require at least one non-empty object if (!all(sf::st_is_empty(NotreDame))) { library(ggplot2) ggplot(NotreDame) + geom_sf() } NotreDame_poly <- geo_address_lookup_sf(201611261, type = "W", points_only = FALSE ) if (!all(sf::st_is_empty(NotreDame_poly))) { ggplot(NotreDame_poly) + geom_sf() } # Vectorized input several <- geo_address_lookup_sf(c(146656, 240109189), type = c("R", "N")) several# Notre Dame Cathedral, Paris NotreDame <- geo_address_lookup_sf(osm_ids = 201611261, type = "W") # Require at least one non-empty object if (!all(sf::st_is_empty(NotreDame))) { library(ggplot2) ggplot(NotreDame) + geom_sf() } NotreDame_poly <- geo_address_lookup_sf(201611261, type = "W", points_only = FALSE ) if (!all(sf::st_is_empty(NotreDame_poly))) { ggplot(NotreDame_poly) + geom_sf() } # Vectorized input several <- geo_address_lookup_sf(c(146656, 240109189), type = c("R", "N")) several
Searches amenities as defined by OpenStreetMap in a
restricted area defined by a bounding box in the form
(<xmin>, <ymin>, <xmax>, <ymax>) and returns the
tibble associated with the query. See
geo_amenity_sf() for retrieving the data as an sf object.
geo_amenity( bbox, amenity, lat = "lat", long = "lon", limit = 1, full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", progressbar = TRUE, custom_query = list(), strict = FALSE )geo_amenity( bbox, amenity, lat = "lat", long = "lon", limit = 1, full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", progressbar = TRUE, custom_query = list(), strict = FALSE )
bbox |
The bounding box (viewbox) used to limit the search. It can be
a numeric vector of longitude ( |
amenity |
|
lat |
Latitude column name in the output data (default |
long |
Longitude column name in the output data (default |
limit |
Maximum number of results to return per input address. Note that each query returns a maximum of 50 results. |
full_results |
Return all available data from the Nominatim API.
If |
return_addresses |
Return input addresses with results if |
verbose |
If |
nominatim_server |
URL of the Nominatim server to use. Defaults to
|
progressbar |
Logical. If |
custom_query |
Named list with API-specific parameters, for example
|
strict |
Logical |
Bounding boxes can be located using online tools such as https://boundingbox.klokantech.com/.
For a full list of valid amenities, see https://wiki.openstreetmap.org/wiki/Key:amenity and osm_amenities.
See https://nominatim.org/release-docs/latest/api/Search/ for additional
parameters to be passed to custom_query.
A tibble with the results that match the query.
Amenity lookup:
geo_amenity_sf(),
osm_amenities
Geocoding:
geo_address_lookup(),
geo_address_lookup_sf(),
geo_amenity_sf(),
geo_lite(),
geo_lite_sf(),
geo_lite_struct(),
geo_lite_struct_sf()
# Times Square, NY, USA bbox <- c( -73.9894467311, 40.75573629, -73.9830630737, 40.75789245 ) geo_amenity( bbox = bbox, amenity = "restaurant" ) # Several amenities geo_amenity( bbox = bbox, amenity = c("restaurant", "pub") ) # Increase `limit` and use strict filtering geo_amenity( bbox = bbox, amenity = c("restaurant", "pub"), limit = 10, strict = TRUE )# Times Square, NY, USA bbox <- c( -73.9894467311, 40.75573629, -73.9830630737, 40.75789245 ) geo_amenity( bbox = bbox, amenity = "restaurant" ) # Several amenities geo_amenity( bbox = bbox, amenity = c("restaurant", "pub") ) # Increase `limit` and use strict filtering geo_amenity( bbox = bbox, amenity = c("restaurant", "pub"), limit = 10, strict = TRUE )
Searches amenities as defined by OpenStreetMap in a
restricted area defined by a bounding box in the form
(<xmin>, <ymin>, <xmax>, <ymax>) and returns the sf
object associated with the query using sf. See geo_amenity() for
retrieving the data in tibble format.
geo_amenity_sf( bbox, amenity, limit = 1, full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", progressbar = TRUE, custom_query = list(), strict = FALSE, points_only = TRUE )geo_amenity_sf( bbox, amenity, limit = 1, full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", progressbar = TRUE, custom_query = list(), strict = FALSE, points_only = TRUE )
bbox |
The bounding box (viewbox) used to limit the search. It can be
a numeric vector of longitude ( |
amenity |
|
limit |
Maximum number of results to return per input address. Note that each query returns a maximum of 50 results. |
full_results |
Return all available data from the Nominatim API.
If |
return_addresses |
Return input addresses with results if |
verbose |
If |
nominatim_server |
URL of the Nominatim server to use. Defaults to
|
progressbar |
Logical. If |
custom_query |
Named list with API-specific parameters, for example
|
strict |
Logical |
points_only |
Logical |
Bounding boxes can be located using online tools such as https://boundingbox.klokantech.com/.
For a full list of valid amenities, see https://wiki.openstreetmap.org/wiki/Key:amenity and osm_amenities.
See https://nominatim.org/release-docs/latest/api/Search/ for additional
parameters to be passed to custom_query.
An sf object with the results that match the query.
The parameter points_only specifies whether the function results will be
points (all Nominatim results are guaranteed to have at least point
geometry) or other geometry types.
Note that when points_only = FALSE, the type of geometry returned depends
on the object being geocoded. Administrative areas, major buildings and the
like will be returned as polygons, rivers, roads and similar features will
be returned as lines, and amenities may still be returned as points.
This function is vectorized, allowing multiple addresses to be geocoded.
With points_only = FALSE, multiple geometry types may be returned.
Amenity lookup:
geo_amenity(),
osm_amenities
Geocoding:
geo_address_lookup(),
geo_address_lookup_sf(),
geo_amenity(),
geo_lite(),
geo_lite_sf(),
geo_lite_struct(),
geo_lite_struct_sf()
sf outputs:
bbox_to_poly(),
geo_address_lookup_sf(),
geo_lite_sf(),
geo_lite_struct_sf(),
reverse_geo_lite_sf()
# Usera, Madrid library(ggplot2) mad <- geo_lite_sf("Usera, Madrid, Spain", points_only = FALSE) # Restaurants, pubs and schools rest_pub <- geo_amenity_sf(mad, c("restaurant", "pub", "school"), limit = 50 ) if (!all(sf::st_is_empty(rest_pub))) { ggplot(mad) + geom_sf() + geom_sf(data = rest_pub, aes(color = query, shape = query)) }# Usera, Madrid library(ggplot2) mad <- geo_lite_sf("Usera, Madrid, Spain", points_only = FALSE) # Restaurants, pubs and schools rest_pub <- geo_amenity_sf(mad, c("restaurant", "pub", "school"), limit = 50 ) if (!all(sf::st_is_empty(rest_pub))) { ggplot(mad) + geom_sf() + geom_sf(data = rest_pub, aes(color = query, shape = query)) }
Geocodes addresses given as character values and returns the
tibble associated with the query. See geo_lite_sf() for
retrieving the data as an sf object.
Corresponds to the free-form query search described in the API endpoint.
geo_lite( address, lat = "lat", long = "lon", limit = 1, full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", progressbar = TRUE, custom_query = list() )geo_lite( address, lat = "lat", long = "lon", limit = 1, full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", progressbar = TRUE, custom_query = list() )
address |
|
lat |
Latitude column name in the output data (default |
long |
Longitude column name in the output data (default |
limit |
Maximum number of results to return per input address. Note that each query returns a maximum of 50 results. |
full_results |
Return all available data from the Nominatim API.
If |
return_addresses |
Return input addresses with results if |
verbose |
If |
nominatim_server |
URL of the Nominatim server to use. Defaults to
|
progressbar |
Logical. If |
custom_query |
Named list with API-specific parameters, for example
|
See https://nominatim.org/release-docs/latest/api/Search/ for additional
parameters to be passed to custom_query.
A tibble with the results that match the query.
Geocoding:
geo_address_lookup(),
geo_address_lookup_sf(),
geo_amenity(),
geo_amenity_sf(),
geo_lite_sf(),
geo_lite_struct(),
geo_lite_struct_sf()
geo_lite("Madrid, Spain") # Several addresses geo_lite(c("Madrid", "Barcelona")) # With options: restrict search to the United States geo_lite(c("Madrid", "Barcelona"), custom_query = list(countrycodes = "US"), full_results = TRUE )geo_lite("Madrid, Spain") # Several addresses geo_lite(c("Madrid", "Barcelona")) # With options: restrict search to the United States geo_lite(c("Madrid", "Barcelona"), custom_query = list(countrycodes = "US"), full_results = TRUE )
Geocodes addresses and returns the corresponding sf object.
The query output is returned as an sf object. See geo_lite() for
retrieving the data in tibble format.
Corresponds to the free-form query search described in the API endpoint.
geo_lite_sf( address, limit = 1, return_addresses = TRUE, full_results = FALSE, verbose = FALSE, progressbar = TRUE, nominatim_server = "https://nominatim.openstreetmap.org/", custom_query = list(), points_only = TRUE )geo_lite_sf( address, limit = 1, return_addresses = TRUE, full_results = FALSE, verbose = FALSE, progressbar = TRUE, nominatim_server = "https://nominatim.openstreetmap.org/", custom_query = list(), points_only = TRUE )
address |
|
limit |
Maximum number of results to return per input address. Note that each query returns a maximum of 50 results. |
return_addresses |
Return input addresses with results if |
full_results |
Return all available data from the Nominatim API.
If |
verbose |
If |
progressbar |
Logical. If |
nominatim_server |
URL of the Nominatim server to use. Defaults to
|
custom_query |
Named list with API-specific parameters, for example
|
points_only |
Logical |
See https://nominatim.org/release-docs/latest/api/Search/ for additional
parameters to be passed to custom_query.
An sf object with the results that match the query.
The parameter points_only specifies whether the function results will be
points (all Nominatim results are guaranteed to have at least point
geometry) or other geometry types.
Note that when points_only = FALSE, the type of geometry returned depends
on the object being geocoded. Administrative areas, major buildings and the
like will be returned as polygons, rivers, roads and similar features will
be returned as lines, and amenities may still be returned as points.
This function is vectorized, allowing multiple addresses to be geocoded.
With points_only = FALSE, multiple geometry types may be returned.
Geocoding:
geo_address_lookup(),
geo_address_lookup_sf(),
geo_amenity(),
geo_amenity_sf(),
geo_lite(),
geo_lite_struct(),
geo_lite_struct_sf()
sf outputs:
bbox_to_poly(),
geo_address_lookup_sf(),
geo_amenity_sf(),
geo_lite_struct_sf(),
reverse_geo_lite_sf()
# Map: points library(ggplot2) string <- "Statue of Liberty, NY, USA" sol <- geo_lite_sf(string) if (!all(sf::st_is_empty(sol))) { ggplot(sol) + geom_sf() } sol_poly <- geo_lite_sf(string, points_only = FALSE) if (!all(sf::st_is_empty(sol_poly))) { ggplot(sol_poly) + geom_sf() + geom_sf(data = sol, color = "red") } # Several results madrid <- geo_lite_sf("Comunidad de Madrid, Spain", limit = 2, points_only = FALSE, full_results = TRUE ) if (!all(sf::st_is_empty(madrid))) { ggplot(madrid) + geom_sf(fill = NA) }# Map: points library(ggplot2) string <- "Statue of Liberty, NY, USA" sol <- geo_lite_sf(string) if (!all(sf::st_is_empty(sol))) { ggplot(sol) + geom_sf() } sol_poly <- geo_lite_sf(string, points_only = FALSE) if (!all(sf::st_is_empty(sol_poly))) { ggplot(sol_poly) + geom_sf() + geom_sf(data = sol, color = "red") } # Several results madrid <- geo_lite_sf("Comunidad de Madrid, Spain", limit = 2, points_only = FALSE, full_results = TRUE ) if (!all(sf::st_is_empty(madrid))) { ggplot(madrid) + geom_sf(fill = NA) }
Geocodes addresses already split into components and returns the
tibble associated with the query. See
geo_lite_struct_sf() for retrieving the data as an sf
object.
Corresponds to the structured query search described in the
API endpoint. To
perform a free-form search, use geo_lite().
geo_lite_struct( amenity = NULL, street = NULL, city = NULL, county = NULL, state = NULL, country = NULL, postalcode = NULL, lat = "lat", long = "lon", limit = 1, full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", custom_query = list() )geo_lite_struct( amenity = NULL, street = NULL, city = NULL, county = NULL, state = NULL, country = NULL, postalcode = NULL, lat = "lat", long = "lon", limit = 1, full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", custom_query = list() )
amenity |
Name and/or type of POI. See also |
street |
House number and street name. |
city |
City. |
county |
County. |
state |
State. |
country |
Country. |
postalcode |
Postal code. |
lat |
Latitude column name in the output data (default |
long |
Longitude column name in the output data (default |
limit |
Maximum number of results to return per input address. Note that each query returns a maximum of 50 results. |
full_results |
Return all available data from the Nominatim API.
If |
return_addresses |
Return input addresses with results if |
verbose |
If |
nominatim_server |
URL of the Nominatim server to use. Defaults to
|
custom_query |
Named list with API-specific parameters, for example
|
The structured form of the search query allows you to look up an address that is already split into its components. Each parameter represents a field of the address. All parameters are optional. You should only use the ones that are relevant for the address you want to geocode.
See https://nominatim.org/release-docs/latest/api/Search/ for additional
parameters to be passed to custom_query.
A tibble with the results that match the query.
Geocoding:
geo_address_lookup(),
geo_address_lookup_sf(),
geo_amenity(),
geo_amenity_sf(),
geo_lite(),
geo_lite_sf(),
geo_lite_struct_sf()
pl_mayor <- geo_lite_struct( street = "Plaza Mayor", country = "Spain", limit = 50, full_results = TRUE ) dplyr::glimpse(pl_mayor)pl_mayor <- geo_lite_struct( street = "Plaza Mayor", country = "Spain", limit = 50, full_results = TRUE ) dplyr::glimpse(pl_mayor)
Geocodes addresses already split into components and returns the
corresponding sf object. The query output is returned as an
sf format. See geo_lite_struct() for retrieving the data in
tibble format.
Corresponds to the structured query search described in the
API endpoint. To
perform a free-form search, use geo_lite_sf().
geo_lite_struct_sf( amenity = NULL, street = NULL, city = NULL, county = NULL, state = NULL, country = NULL, postalcode = NULL, limit = 1, full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", custom_query = list(), points_only = TRUE )geo_lite_struct_sf( amenity = NULL, street = NULL, city = NULL, county = NULL, state = NULL, country = NULL, postalcode = NULL, limit = 1, full_results = FALSE, return_addresses = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", custom_query = list(), points_only = TRUE )
amenity |
Name and/or type of POI. See also |
street |
House number and street name. |
city |
City. |
county |
County. |
state |
State. |
country |
Country. |
postalcode |
Postal code. |
limit |
Maximum number of results to return per input address. Note that each query returns a maximum of 50 results. |
full_results |
Return all available data from the Nominatim API.
If |
return_addresses |
Return input addresses with results if |
verbose |
If |
nominatim_server |
URL of the Nominatim server to use. Defaults to
|
custom_query |
Named list with API-specific parameters, for example
|
points_only |
Logical |
The structured form of the search query allows you to look up an address that is already split into its components. Each parameter represents a field of the address. All parameters are optional. You should only use the ones that are relevant for the address you want to geocode.
See https://nominatim.org/release-docs/latest/api/Search/ for additional
parameters to be passed to custom_query.
An sf object with the results that match the query.
The parameter points_only specifies whether the function results will be
points (all Nominatim results are guaranteed to have at least point
geometry) or other geometry types.
Note that when points_only = FALSE, the type of geometry returned depends
on the object being geocoded. Administrative areas, major buildings and the
like will be returned as polygons, rivers, roads and similar features will
be returned as lines, and amenities may still be returned as points.
This function is vectorized, allowing multiple addresses to be geocoded.
With points_only = FALSE, multiple geometry types may be returned.
Geocoding:
geo_address_lookup(),
geo_address_lookup_sf(),
geo_amenity(),
geo_amenity_sf(),
geo_lite(),
geo_lite_sf(),
geo_lite_struct()
sf outputs:
bbox_to_poly(),
geo_address_lookup_sf(),
geo_amenity_sf(),
geo_lite_sf(),
reverse_geo_lite_sf()
# Map pl_mayor <- geo_lite_struct_sf( street = "Plaza Mayor", county = "Comunidad de Madrid", country = "Spain", limit = 50, full_results = TRUE, verbose = TRUE ) # Outline ccaa <- geo_lite_sf("Comunidad de Madrid, Spain", points_only = FALSE) library(ggplot2) if (any(!sf::st_is_empty(pl_mayor), !sf::st_is_empty(ccaa))) { ggplot(ccaa) + geom_sf() + geom_sf(data = pl_mayor, aes(shape = addresstype, color = addresstype)) }# Map pl_mayor <- geo_lite_struct_sf( street = "Plaza Mayor", county = "Comunidad de Madrid", country = "Spain", limit = 50, full_results = TRUE, verbose = TRUE ) # Outline ccaa <- geo_lite_sf("Comunidad de Madrid, Spain", points_only = FALSE) library(ggplot2) if (any(!sf::st_is_empty(pl_mayor), !sf::st_is_empty(ccaa))) { ggplot(ccaa) + geom_sf() + geom_sf(data = pl_mayor, aes(shape = addresstype, color = addresstype)) }
Database with the list of amenities available on OpenStreetMap.
A tibble with
136 rows and
fields:
The category of the amenity.
The value of the amenity.
A brief description of the type of amenity.
Data extracted on 03 April 2024.
https://wiki.openstreetmap.org/wiki/Key:amenity
Amenity lookup:
geo_amenity(),
geo_amenity_sf()
data("osm_amenities") osm_amenitiesdata("osm_amenities") osm_amenities
Generates an address from latitude and longitude (latitudes in
and longitudes in ),
and returns the tibble associated with the query. See
reverse_geo_lite_sf() for retrieving the data as an sf
object.
reverse_geo_lite( lat, long, address = "address", full_results = FALSE, return_coords = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", progressbar = TRUE, custom_query = list() )reverse_geo_lite( lat, long, address = "address", full_results = FALSE, return_coords = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", progressbar = TRUE, custom_query = list() )
lat |
Latitude values in numeric format. Must be in the range
|
long |
Longitude values in numeric format. Must be in the range
|
address |
Address column name in the output data (default |
full_results |
Return all available data from the Nominatim API.
If |
return_coords |
Return input coordinates with results if |
verbose |
If |
nominatim_server |
URL of the Nominatim server to use. Defaults to
|
progressbar |
Logical. If |
custom_query |
Named list with API-specific parameters, for example
|
See https://nominatim.org/release-docs/latest/api/Reverse/ for additional
parameters to be passed to custom_query.
A tibble with the results that match the query.
Use the option custom_query = list(zoom = 3) to adjust the output. Some
zoom levels correspond to these address details:
| zoom | address_detail |
3 |
country |
5 |
state |
8 |
county |
10 |
city |
14 |
suburb |
16 |
major streets |
17 |
major and minor streets |
18 |
building |
Reverse geocoding:
reverse_geo_lite_sf()
reverse_geo_lite(lat = 40.75728, long = -73.98586) # Several coordinates reverse_geo_lite(lat = c(40.75728, 55.95335), long = c(-73.98586, -3.188375)) # With options: zoom to country level sev <- reverse_geo_lite( lat = c(40.75728, 55.95335), long = c(-73.98586, -3.188375), custom_query = list(zoom = 0, extratags = TRUE), verbose = TRUE, full_results = TRUE ) dplyr::glimpse(sev)reverse_geo_lite(lat = 40.75728, long = -73.98586) # Several coordinates reverse_geo_lite(lat = c(40.75728, 55.95335), long = c(-73.98586, -3.188375)) # With options: zoom to country level sev <- reverse_geo_lite( lat = c(40.75728, 55.95335), long = c(-73.98586, -3.188375), custom_query = list(zoom = 0, extratags = TRUE), verbose = TRUE, full_results = TRUE ) dplyr::glimpse(sev)
Generates an address from latitude and longitude (latitudes in
and longitudes in ),
and returns the sf object associated with the query using
sf. See reverse_geo_lite() for retrieving the data in
tibble format.
reverse_geo_lite_sf( lat, long, address = "address", full_results = FALSE, return_coords = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", progressbar = TRUE, custom_query = list(), points_only = TRUE )reverse_geo_lite_sf( lat, long, address = "address", full_results = FALSE, return_coords = TRUE, verbose = FALSE, nominatim_server = "https://nominatim.openstreetmap.org/", progressbar = TRUE, custom_query = list(), points_only = TRUE )
lat |
Latitude values in numeric format. Must be in the range
|
long |
Longitude values in numeric format. Must be in the range
|
address |
Address column name in the output data (default |
full_results |
Return all available data from the Nominatim API.
If |
return_coords |
Return input coordinates with results if |
verbose |
If |
nominatim_server |
URL of the Nominatim server to use. Defaults to
|
progressbar |
Logical. If |
custom_query |
Named list with API-specific parameters, for example
|
points_only |
Logical |
See https://nominatim.org/release-docs/latest/api/Reverse/ for additional
parameters to be passed to custom_query.
An sf object with the results that match the query.
Use the option custom_query = list(zoom = 3) to adjust the output. Some
zoom levels correspond to these address details:
| zoom | address_detail |
3 |
country |
5 |
state |
8 |
county |
10 |
city |
14 |
suburb |
16 |
major streets |
17 |
major and minor streets |
18 |
building |
The parameter points_only specifies whether the function results will be
points (all Nominatim results are guaranteed to have at least point
geometry) or other geometry types.
Note that when points_only = FALSE, the type of geometry returned depends
on the object being geocoded. Administrative areas, major buildings and the
like will be returned as polygons, rivers, roads and similar features will
be returned as lines, and amenities may still be returned as points.
This function is vectorized, allowing multiple addresses to be geocoded.
With points_only = FALSE, multiple geometry types may be returned.
Reverse geocoding:
reverse_geo_lite()
sf outputs:
bbox_to_poly(),
geo_address_lookup_sf(),
geo_amenity_sf(),
geo_lite_sf(),
geo_lite_struct_sf()
library(ggplot2) # Colosseum coordinates col_lon <- 12.49309 col_lat <- 41.89026 # Colosseum as polygon col_sf <- reverse_geo_lite_sf( lat = col_lat, lon = col_lon, points_only = FALSE ) dplyr::glimpse(col_sf) if (!all(sf::st_is_empty(col_sf))) { ggplot(col_sf) + geom_sf() } # City of Rome: same coordinates with zoom 10 rome_sf <- reverse_geo_lite_sf( lat = col_lat, lon = col_lon, custom_query = list(zoom = 10), points_only = FALSE ) dplyr::glimpse(rome_sf) if (!all(sf::st_is_empty(rome_sf))) { ggplot(rome_sf) + geom_sf() }library(ggplot2) # Colosseum coordinates col_lon <- 12.49309 col_lat <- 41.89026 # Colosseum as polygon col_sf <- reverse_geo_lite_sf( lat = col_lat, lon = col_lon, points_only = FALSE ) dplyr::glimpse(col_sf) if (!all(sf::st_is_empty(col_sf))) { ggplot(col_sf) + geom_sf() } # City of Rome: same coordinates with zoom 10 rome_sf <- reverse_geo_lite_sf( lat = col_lat, lon = col_lon, custom_query = list(zoom = 10), points_only = FALSE ) dplyr::glimpse(rome_sf) if (!all(sf::st_is_empty(rome_sf))) { ggplot(rome_sf) + geom_sf() }