Something went wrong. Try again.
R package for downloading OpenStreetMap data
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153% Generated by roxygen2: do not edit by hand% Please edit documentation in R/getbb.R\name{getbb}\alias{getbb}\title{Get bounding box for a given place name}\usage{getbb( place_name, display_name_contains = NULL, viewbox = NULL, format_out = c("matrix", "data.frame", "string", "polygon", "sf_polygon", "osm_type_id"), base_url = "https://nominatim.openstreetmap.org", featuretype = "settlement", limit = 10, key = NULL, silent = TRUE)}\arguments{\item{place_name}{The name of the place you're searching for or a wikidataid. For Wikidata, only \code{format_out}, \code{base_url} and \code{silent} are used; allother parameters are ignored.}
\item{display_name_contains}{Text string to match with display_name fieldreturned by \url{https://wiki.openstreetmap.org/wiki/Nominatim}.}
\item{viewbox}{Focuses the search on the given area defined asa character string \code{"x1,y1,x2,y2"} or \code{c(x1, y1, x2, y2)}. Any two cornerpoints of the box are accepted as long as they make a proper box. \code{x} islongitude, \code{y} is latitude.}
\item{format_out}{Character string indicating output format: \code{matrix}(default), \code{string} (see \code{\link[=bbox_to_string]{bbox_to_string()}}),\code{data.frame} (all 'hits' returned by Nominatim),\code{sf_polygon} (for polygons that work with the sf package),\code{polygon} (full polygonal bounding boxes for each match) or\code{osm_type_id} (string for quering inside deffined OSM areas\code{\link[=bbox_to_string]{bbox_to_string()}}).}
\item{base_url}{Base website from where data is queried.}
\item{featuretype}{The type of OSM feature (settlement is default; see Note).}
\item{limit}{How many results should the API return?}
\item{key}{The API key to use for services that require it.}
\item{silent}{Should the API be printed to screen? \code{TRUE} by default.}}\value{For \code{format_out = "matrix"}, the default, return the bounding box:
\if{html}{\out{<div class="sourceCode">}}\preformatted{ min maxx ... ...y ... ...}\if{html}{\out{</div>}}
If \code{format_out = "polygon"}, a list of polygons and multipolygons with oneitem for each \code{nominatim} result. The items are named with the OSM type andid. Each polygon is formed by one or more two-columns matrices of polygonallongitude-latitude points. The first matrix represents the outer boundary andthe next ones represent holes. See examples below for illustration.
If \code{format_out = "sf_polygon"}, a \code{sf} object. Each row correspond to a\code{place_name} within \code{nominatim} result.
For \code{format_out = "osm_type_id"}, a character string representing an OSMobject in overpass query language. For example:\code{"relation(id:11747082)"} represents the area of the Catalan Countries.If one exact match exists with potentially multiple polygonal boundaries,only the first relation or way is returned. A set of objects can also berepresented for multiple results (e.g.\verb{relation(id:11747082,307833); way(id:22422490)}). See examples below forillustration. The OSM objects that can be used as\href{https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Map_way/relation_to_area_(map_to_area)}{areas in overpass queries}\emph{must be closed rings} (ways or relations).}\description{This function uses the free Nominatim API provided by OpenStreetMap to findthe bounding box (bb) associated with place names.}\details{It was inspired by the functions\code{bbox} from the \pkg{sp} package,\code{bb} from the \pkg{tmaptools} package and\code{bb_lookup} from the github package \pkg{nominatim} package,which can be found at \url{https://github.com/hrbrmstr/nominatim}.
See \url{https://wiki.openstreetmap.org/wiki/Nominatim} for details.}\note{Specific values of \code{featuretype} include "street", "city",\url{https://wiki.openstreetmap.org/wiki/Nominatim} for details). The default\code{featuretype = "settlement"} combines results from all intermediatelevels below "country" and above "streets". If the bounding box or polygon ofa city is desired, better results will usually be obtained with\code{featuretype = "city"}.}\examples{\dontrun{getbb ("Salzburg")# Select based on display_name, print query urlgetbb ("Hereford", display_name_contains = "United States", silent = FALSE)# top 3 matches as data framegetbb ("Hereford", format_out = "data.frame", limit = 3)getbb ("Hereford", format_out = "data.frame", viewbox = getbb ("England"))
# Examples of polygonal boundariesbb <- getbb ("Milano, Italy", format_out = "polygon")# A polygon and a multipolygon:str (bb) # matrices of longitude/latitude pairs
bb_sf <- getbb ("kathmandu", format_out = "sf_polygon")bb_sf# sf:::plot.sf(bb_sf) # can be plotted if sf is installedgetbb ("london", format_out = "sf_polygon")
getbb ("València", format_out = "osm_type_id")# Select multiple areas with format_out = "osm_type_id"areas <- getbb ("València", format_out = "data.frame")bbox_to_string (areas [areas$osm_type != "node", ])
# Search by wikidata id (València)getbb ("Q5720", format_out = "data.frame")
# Using an alternative service (locationiq requires an API key)# add LOCATIONIQ=type_your_api_key_here to .Renviron:key <- Sys.getenv ("LOCATIONIQ")if (nchar (key) == 32) { getbb (place_name, base_url = "https://locationiq.org/v1/search.php", key = key )}}}\seealso{Other queries:\code{\link[=add_osm_feature]{add_osm_feature()}},\code{\link[=add_osm_features]{add_osm_features()}},\code{\link[=bbox_to_string]{bbox_to_string()}},\code{\link[=filter_osm_user]{filter_osm_user()}},\code{\link[=opq]{opq()}},\code{\link[=opq_around]{opq_around()}},\code{\link[=opq_csv]{opq_csv()}},\code{\link[=opq_enclosing]{opq_enclosing()}},\code{\link[=opq_osm_id]{opq_osm_id()}},\code{\link[=opq_string]{opq_string()}},\code{\link[=overpass_status]{overpass_status()}}}\concept{queries}