Looks up OpenStreetMap amenities within a bounding box of
the form (xmin, ymin, xmax, ymax). Results are returned as an
sf object. Use geo_amenity() to return a
tibble instead.
Usage
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
)Arguments
- bbox
A bounding box (viewbox) used to limit the search. Supply a numeric vector of longitude (
x) and latitude (y) in the form(xmin, ymin, xmax, ymax), ansfobject or ansfcobject. See Details.- amenity
A character vector of amenities to look up, for example
c("pub", "restaurant"). See osm_amenities.- limit
A positive integer giving the maximum number of results to return per query. Nominatim returns at most 50 results per query.
- full_results
If
TRUE, return all available fields from the Nominatim API. IfFALSE, return only query metadata, geometry and requested address columns.- return_addresses
If
TRUE, include single-line addresses in the results.- verbose
If
TRUE, displays detailed messages in the console.- nominatim_server
A string giving the base URL of the Nominatim server. Defaults to
"https://nominatim.openstreetmap.org/".- progressbar
If
TRUE, displays a progress bar when processing multiple queries.- custom_query
A named list of additional API parameters, for example
list(countrycodes = "US"). See Details.- strict
If
TRUE, keeps only results insidebbox. IfFALSE(the default), Nominatim may return results outside the bounding box.- points_only
If
TRUE, return only point geometries. IfFALSE, the API may return other geometry types. See About geometry types.
Value
An sf object with the results that match the query.
Details
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.
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
Amenity lookup functions:
geo_amenity(),
osm_amenities
Address search functions:
geo_address_lookup(),
geo_address_lookup_sf(),
geo_amenity(),
geo_lite(),
geo_lite_sf(),
geo_lite_struct(),
geo_lite_struct_sf()
Spatial output functions:
bbox_to_poly(),
geo_address_lookup_sf(),
geo_lite_sf(),
geo_lite_struct_sf(),
reverse_geo_lite_sf()
Examples
# \donttest{
# 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
)
#>
|
| | 0%
|
|================= | 33%
|
|================================= | 67%
|
|==================================================| 100%
if (!all(sf::st_is_empty(rest_pub))) {
ggplot(mad) +
geom_sf() +
geom_sf(data = rest_pub, aes(color = query, shape = query))
}
# }
