View source: R/geo_amenity_sf.R
geo_amenity_sf | R Documentation |
This function search amenities as defined by OpenStreetMap on a restricted
area defined by a bounding box in the form of
(<min_latitude>, <min_longitude>, <max_latitude>, <max_longitude>)
. This
function returns the sf spatial object associated with the query,
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,
custom_query = list(),
points_only = TRUE,
strict = FALSE
)
bbox |
A numeric vector of latitude and longitude
|
amenity |
A character of a vector of character with the amenities to be
geolocated (i.e. |
limit |
maximum number of results to return per input address. Note that each query returns a maximum of 50 results. |
full_results |
returns all available data from the API service.
If |
return_addresses |
return input addresses with results if |
verbose |
if |
custom_query |
A named list with API-specific parameters to be used
(i.e. |
points_only |
Logical |
strict |
Logical |
Bounding boxes can be located using different online tools, as Bounding Box Tool.
For a full list of valid amenities see https://wiki.openstreetmap.org/wiki/Key:amenity.
A sf
object with the results.
The parameter points_only
specifies whether the function results will be
points (all Nominatim results are guaranteed to have at least point
geometry) or possibly other spatial objects.
Note that the type of geometry returned in case of points_only = FALSE
will depend on the object being geocoded:
administrative areas, major buildings and the like will be returned as polygons
rivers, roads and their like as lines
amenities may be points even in case of a points_only = FALSE
call
The function is vectorized, allowing for multiple addresses to be geocoded;
in case of points_only = FALSE
multiple geometry types may be returned.
geo_amenity()
Search amenities:
bbox_to_poly()
,
geo_amenity()
,
osm_amenities
Geocoding strings:
geo_address_lookup_sf()
,
geo_address_lookup()
,
geo_amenity()
,
geo_lite_sf()
,
geo_lite()
Get spatial (sf
) objects:
bbox_to_poly()
,
geo_address_lookup_sf()
,
geo_lite_sf()
,
reverse_geo_lite_sf()
# Madrid, Spain
library(ggplot2)
bbox <- c(-3.888954, 40.311977, -3.517916, 40.643729)
# Restaurants and pubs
rest_pub <- geo_amenity_sf(bbox, c("restaurant", "pub"), limit = 50)
if (any(!sf::st_is_empty(rest_pub))) {
ggplot(rest_pub) +
geom_sf()
}
# Hospital as polygon
hosp <- geo_amenity_sf(bbox, "hospital", points_only = FALSE)
if (any(!sf::st_is_empty(hosp))) {
ggplot(hosp) +
geom_sf()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.