Skip to contents

Generates an address from a latitude and longitude. Latitudes must be between \(\left[-90, 90 \right]\) and longitudes between \(\left[-180, 180 \right]\). This function returns the spatial object associated with the query using sf, see reverse_geo_lite() for retrieving the data in tibble format.

Usage

reverse_geo_lite_sf(
  lat,
  long,
  address = "address",
  full_results = FALSE,
  return_coords = TRUE,
  verbose = FALSE,
  nominatim_server = "https://nominatim.openstreetmap.org/",
  progressbar = TRUE,
  custom_query = list(),
  points_only = TRUE
)

Arguments

lat

Latitude values in numeric format. Must be in the range \(\left[-90, 90 \right]\).

long

Longitude values in numeric format. Must be in the range \(\left[-180, 180 \right]\).

address

Address column name in the output data (default "address").

full_results

Returns all available data from the API service. If FALSE (default) only latitude, longitude and address columns are returned. See also return_addresses.

return_coords

Return input coordinates with results if TRUE.

verbose

If TRUE then detailed logs are output to the console.

nominatim_server

The URL of the Nominatim server to use. Defaults to "https://nominatim.openstreetmap.org/".

progressbar

Logical. If TRUE displays a progress bar to indicate the progress of the function.

custom_query

API-specific parameters to be used, passed as a named list (ie. list(zoom = 3)). 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.

Value

A sf object with the results.

Details

See https://nominatim.org/release-docs/develop/api/Reverse/ for additional parameters to be passed to custom_query.

About Zooming

Use the option custom_query = list(zoom = 3) to adjust the output. Some equivalences on terms of zoom:

zoomaddress_detail
3country
5state
8county
10city
14suburb
16major streets
17major and minor streets
18building

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

Examples

# \donttest{
library(ggplot2)

# Coliseum coords
col_lon <- 12.49309
col_lat <- 41.89026

# Coliseum as polygon
col_sf <- reverse_geo_lite_sf(
  lat = col_lat,
  lon = col_lon,
  points_only = FALSE
)

dplyr::glimpse(col_sf)
#> Rows: 1
#> Columns: 4
#> $ address  <chr> "Colosseo, Piazza del Colosseo, Celio, Municipio Roma I, Roma…
#> $ lat      <dbl> 41.89026
#> $ lon      <dbl> 12.49309
#> $ geometry <POLYGON [°]> POLYGON ((12.4913 41.89058,...

if (any(!sf::st_is_empty(col_sf))) {
  ggplot(col_sf) +
    geom_sf()
}


# City of Rome - same coords with zoom 10

rome_sf <- reverse_geo_lite_sf(
  lat = col_lat,
  lon = col_lon,
  custom_query = list(zoom = 10),
  points_only = FALSE
)

dplyr::glimpse(rome_sf)
#> Rows: 1
#> Columns: 4
#> $ address  <chr> "Roma, Roma Capitale, Lazio, Italia"
#> $ lat      <dbl> 41.89026
#> $ lon      <dbl> 12.49309
#> $ geometry <MULTIPOLYGON [°]> MULTIPOLYGON (((12.23447 41...

if (any(!sf::st_is_empty(rome_sf))) {
  ggplot(rome_sf) +
    geom_sf()
}

# }