Learn R Programming

osmdata (version 0.1.9)

opq: Build an Overpass query

Description

Build an Overpass query

Usage

opq(
  bbox = NULL,
  nodes_only = FALSE,
  datetime = NULL,
  datetime2 = NULL,
  timeout = 25,
  memsize
)

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 form xmin,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 from getbb(..., format_out = "polygon").

nodes_only

If TRUE, query OSM nodes only. Some OSM structures such as place = "city" or highway = "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 to TRUE for such cases makes queries more efficient, with data returned in the osm_points list item.

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 and datetime2, where datetime2 > datetime. See https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Delta_between_two_dates_.28.22diff.22.29.

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.

Value

An overpass_query object

See Also

Other queries: add_osm_features(), add_osm_feature(), bbox_to_string(), getbb(), opq_around(), opq_enclosing(), opq_osm_id(), opq_string(), overpass_status()

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab