Build an Overpass query
Arguments
- bbox
Either (i) four numeric values specifying the maximal and minimal longitudes and latitudes, in the form
c(xmin, ymin, xmax, ymax)
or (ii) a character string in the formxmin,ymin,xmax,ymax
. These will be passed to getbb to be converted to a numerical bounding box. Can also be (iii) a matrix representing a bounding polygon as returned fromgetbb(..., format_out = "polygon")
. To search in an area, (iv) a character string with a relation or a (closed) way id in the format"way(id:1)"
,"relation(id:1, 2)"
or"relation(id:1, 2, 3); way(id:2)"
as returned bygetbb(..., format_out = "osm_type_id")
or bbox_to_string with adata.frame
fromgetbb(..., format_out = "data.frame")
to select all areas combined (relations and ways).- nodes_only
WARNING: this parameter is equivalent to
osm_types = "node"
and will be DEPRECATED. IfTRUE
, query OSM nodes only. Some OSM structures such asplace = "city"
orhighway = "traffic_signals"
are represented by nodes only. Queries are built by default to return all nodes, ways, and relation, but this can be very inefficient for node-only queries. Setting this value toTRUE
for such cases makes queries more efficient, with data returned in theosm_points
list item.- osm_types
A character vector with several OSM types to query:
node
,way
andrelation
is the default.nwr
,nw
,wr
,nr
andrel
are also valid types. Ignored ifnodes_only = TRUE
.osm_types = "node"
is equivalent tonodes_only = TRUE
.- out
The level of verbosity of the overpass result:
body
(geometries and tags, the default),tags
(tags without geometry),meta
(like body + Timestamp, Version, Changeset, User, User ID of the last edition),skel
(geometries only),tags center
(tags without geometry + the coordinates of the center of the bounding box) andids
(type and id of the objects only).- datetime
If specified, a date and time to extract data from the OSM database as it was up to the specified date and time, as described at https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#date. This must be in ISO8601 format ("YYYY-MM-DDThh:mm:ssZ"), where both the "T" and "Z" characters must be present.
- datetime2
If specified, return the difference in the OSM database between
datetime
anddatetime2
, wheredatetime2 > datetime
. See https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Difference_between_two_dates_(diff).- adiff
If
TRUE
, query for augmented difference. The result indicates what happened to the modified and deleted OSM objects. Requiresdatetime(2)*
.- timeout
It may be necessary to increase this value for large queries, because the server may time out before all data are delivered.
- memsize
The default memory size for the 'overpass' server in bytes; may need to be increased in order to handle large queries.
Details
The out
statement for tags
, tags center
and id
, do not return
geometries. Neither out = "meta"
nor adiff = TRUE
options are implemented
for all osmdata_*
functions yet. Use osmdata_xml or osmdata_data_frame
to get the result of these queries. See the documentation of the out statement
and augmented difference
for more details about these options.
Note
See
https://wiki.openstreetmap.org/wiki/Overpass_API#Resource_management_options_.28osm-script.29
for explanation of timeout
and memsize
(or maxsize
in overpass terms).
Note in particular the comment that queries with arbitrarily large memsize
are likely to be rejected.
See also
Other queries:
add_osm_feature()
,
add_osm_features()
,
bbox_to_string()
,
getbb()
,
opq_around()
,
opq_csv()
,
opq_enclosing()
,
opq_osm_id()
,
opq_string()
,
overpass_status()
Examples
if (FALSE) { # \dontrun{
q <- getbb ("portsmouth", display_name_contains = "United States") %>%
opq () %>%
add_osm_feature ("amenity", "restaurant") %>%
add_osm_feature ("amenity", "pub")
osmdata_sf (q) # all objects that are restaurants AND pubs (there are none!)
q1 <- getbb ("portsmouth", display_name_contains = "United States") %>%
opq () %>%
add_osm_feature ("amenity", "restaurant")
q2 <- getbb ("portsmouth", display_name_contains = "United States") %>%
opq () %>%
add_osm_feature ("amenity", "pub")
c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs
# Use nodes_only to retrieve single point data only, such as for central
# locations of cities.
opq <- opq (bbox, nodes_only = TRUE) %>%
add_osm_feature (key = "place", value = "city") %>%
osmdata_sf (quiet = FALSE)
# Filter by a search area
qa1 <- getbb ("Catalan Countries", format_out = "osm_type_id") %>%
opq (nodes_only = TRUE) %>%
add_osm_feature (key = "capital", value = "4")
opqa1 <- osmdata_sf (qa1)
# Filter by a multiple search areas
bb <- getbb ("Vilafranca", format_out = "data.frame")
qa2 <- bbox_to_string (bb [bb$osm_type != "node", ]) %>%
opq (nodes_only = TRUE) %>%
add_osm_feature (key = "place")
opqa2 <- osmdata_sf (qa2)
} # }