geo_amenity_sf: Geocode amenities in Spatial format

View source: R/geo_amenity_sf.R

geo_amenity_sfR Documentation

Geocode amenities in Spatial format

Description

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.

Usage

geo_amenity_sf(
  bbox,
  amenity,
  limit = 1,
  full_results = FALSE,
  return_addresses = TRUE,
  verbose = FALSE,
  custom_query = list(),
  points_only = TRUE,
  strict = FALSE
)

Arguments

bbox

A numeric vector of latitude and longitude ⁠(<min_latitude>, <min_longitude>, <max_latitude>, <max_longitude>)⁠ that restrict the search area. See Details.

amenity

A character of a vector of character with the amenities to be geolocated (i.e. c("pub", "restaurant")). See Details and osm_amenities.

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 FALSE (default) only address columns are returned. See also return_addresses.

return_addresses

return input addresses with results if TRUE.

verbose

if TRUE then detailed logs are output to the console.

custom_query

A named list with API-specific parameters to be used (i.e. list(countrycodes = "US")). See Details.

points_only

Logical TRUE/FALSE. Whether to return only spatial points (TRUE, which is the default) or potentially other shapes as provided by the Nominatim API (FALSE). See About Geometry Types.

strict

Logical TRUE/FALSE. Force the results to be included inside the bbox. Note that Nominatim default behavior may return results located outside the provided bounding box.

Details

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.

Value

A sf object with the results.

About Geometry Types

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.

See Also

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()

Examples



# 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()
}



nominatimlite documentation built on Aug. 15, 2023, 5:08 p.m.