Skip to contents

Looks up addresses and other details for one or more OpenStreetMap (OSM) objects, such as nodes, ways or relations. Results are returned as an sf object. Use geo_address_lookup() to return a tibble instead.

Usage

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
)

Arguments

osm_ids

A numeric vector of OSM identifiers, for example c(12345, 67890).

type

A character vector containing the OSM object type associated with each value in osm_ids. Possible values are node ("N"), way ("W") and relation ("R"). A single value is recycled.

full_results

If TRUE, return all available fields from the Nominatim API. If FALSE, 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/".

custom_query

A named list of additional API parameters, for example list(countrycodes = "US"). See Details.

points_only

If TRUE, 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/Lookup/ 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.

Examples

# \donttest{
# 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
#> Simple feature collection with 2 features and 2 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -2.232455 ymin: 52.51739 xmax: 13.39513 ymax: 53.44246
#> Geodetic CRS:  WGS 84
#> # A tibble: 2 × 3
#>   query      address                                               geometry
#> * <chr>      <chr>                                              <POINT [°]>
#> 1 R146656    Manchester, Greater Manchester, England,… (-2.232455 53.44246)
#> 2 N240109189 Berlin, Deutschland                        (13.39513 52.51739)
# }