
Search for addresses with free-form queries and return sf objects
Source:R/geo_lite_sf.R
geo_lite_sf.RdSearches for addresses supplied as a character vector and returns matching
results as an sf object. Use geo_lite() to return a
tibble instead.
This function performs the free-form address search described in the API endpoint.
Usage
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
)Arguments
- address
A character vector of single-line addresses, for example
"1600 Pennsylvania Ave NW, Washington"orc("Madrid", "Barcelona").- limit
A positive integer specifying the maximum number of results to return per query. Nominatim returns at most 50 results per query.
- return_addresses
A logical value indicating whether to include single-line addresses in the results.
- full_results
A logical value indicating whether to return all available fields from the Nominatim API. If
FALSE, only query metadata, geometry and requested address columns are returned.- verbose
A logical value indicating whether to display detailed messages in the console.
- progressbar
A logical value indicating whether to display a progress bar when processing multiple queries.
- nominatim_server
A character string specifying the base URL of the Nominatim server. Defaults to
"https://nominatim.openstreetmap.org/".- custom_query
A named list of additional API parameters, for example
list(countrycodes = "US"). See Details.- points_only
A logical value indicating whether to return only point geometries. If
FALSE, the API may return other geometry types. See About geometry types.
Value
An sf object with the results that match the query.
Details
See https://nominatim.org/release-docs/latest/api/Search/ for additional
parameters to pass to custom_query.
About geometry types
The points_only argument controls whether the results contain only points.
All Nominatim results have at least a point geometry.
When points_only = FALSE, the geometry type depends on the matching
feature. Administrative areas and major buildings are returned as polygons,
rivers and roads are returned as lines and amenities may still be returned
as points.
This function is vectorized, allowing multiple addresses to be searched.
With points_only = FALSE, multiple geometry types may be returned.
See also
Address search functions:
geo_lite(),
geo_lite_struct(),
geo_lite_struct_sf()
Spatial output functions:
bbox_to_poly(),
geo_address_lookup_sf(),
geo_amenity_sf(),
geo_lite_struct_sf(),
reverse_geo_lite_sf()
Examples
# \donttest{
# Return point geometries.
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")
}
# Return multiple matches.
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)
}
# }