
Address search API with sf output (structured query)
Source:R/geo_lite_struct_sf.R
geo_lite_struct_sf.RdGeocodes addresses already split into components and returns the
corresponding sf object. The query output is returned as an
sf format. See geo_lite_struct() for retrieving the data in
tibble format.
Corresponds to the structured query search described in the
API endpoint. To
perform a free-form search, use geo_lite_sf().
Usage
geo_lite_struct_sf(
amenity = NULL,
street = NULL,
city = NULL,
county = NULL,
state = NULL,
country = NULL,
postalcode = NULL,
limit = 1,
full_results = FALSE,
return_addresses = TRUE,
verbose = FALSE,
nominatim_server = "https://nominatim.openstreetmap.org/",
custom_query = list(),
points_only = TRUE
)Arguments
- amenity
Name and/or type of POI. See also
geo_amenity().- street
House number and street name.
- city
City.
- county
County.
- state
State.
- country
Country.
- postalcode
Postal code.
- limit
Maximum number of results to return per input address. Note that each query returns a maximum of 50 results.
- full_results
Return all available data from the Nominatim API. If
FALSE(default), only latitude, longitude and address columns are returned. See alsoreturn_addresses.- return_addresses
Return input addresses with results if
TRUE.- verbose
If
TRUE, detailed logs are output to the console.- nominatim_server
URL of the Nominatim server to use. Defaults to
"https://nominatim.openstreetmap.org/".- custom_query
Named list with API-specific parameters, for example
list(countrycodes = "US"). See Details.- points_only
Logical
TRUE/FALSE. Whether to return only point geometries (TRUE, which is the default) or potentially other shapes as returned by the Nominatim API (FALSE). See About geometry types.
Value
An sf object with the results that match the query.
Details
The structured form of the search query allows you to look up an address that is already split into its components. Each parameter represents a field of the address. All parameters are optional. You should only use the ones that are relevant for the address you want to geocode.
See https://nominatim.org/release-docs/latest/api/Search/ for additional
parameters to be passed to custom_query.
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 other geometry types.
Note that when points_only = FALSE, the type of geometry returned depends
on the object being geocoded. Administrative areas, major buildings and the
like will be returned as polygons, rivers, roads and similar features will
be returned as lines, and amenities may still be returned as points.
This function is vectorized, allowing multiple addresses to be geocoded.
With points_only = FALSE, multiple geometry types may be returned.
Examples
# \donttest{
# Map
pl_mayor <- geo_lite_struct_sf(
street = "Plaza Mayor",
county = "Comunidad de Madrid",
country = "Spain", limit = 50,
full_results = TRUE, verbose = TRUE
)
# Outline
ccaa <- geo_lite_sf("Comunidad de Madrid, Spain", points_only = FALSE)
library(ggplot2)
if (any(!sf::st_is_empty(pl_mayor), !sf::st_is_empty(ccaa))) {
ggplot(ccaa) +
geom_sf() +
geom_sf(data = pl_mayor, aes(shape = addresstype, color = addresstype))
}
# }