Title: | Import 'OpenStreetMap' Data as Simple Features or Spatial Objects |
---|---|
Description: | Download and import of 'OpenStreetMap' ('OSM') data as 'sf' or 'sp' objects. 'OSM' data are extracted from the 'Overpass' web server (<https://overpass-api.de/>) and processed with very fast 'C++' routines for return to 'R'. |
Authors: | Mark Padgham [aut, cre], Bob Rudis [aut], Robin Lovelace [aut], Maëlle Salmon [aut], Joan Maspons [aut] , Andrew Smith [ctb], James Smith [ctb], Andrea Gilardi [ctb], Enrico Spinielli [ctb], Anthony North [ctb], Martin Machyna [ctb], Marcin Kalicinski [ctb, cph] (Author of included RapidXML code), Eli Pousson [ctb] |
Maintainer: | Mark Padgham <[email protected]> |
License: | GPL-3 |
Version: | 0.2.5.026 |
Built: | 2024-12-12 06:29:45 UTC |
Source: | https://github.com/ropensci/osmdata |
Add a feature to an Overpass query
add_osm_feature( opq, key, value, key_exact = TRUE, value_exact = TRUE, match_case = TRUE, bbox = NULL )
add_osm_feature( opq, key, value, key_exact = TRUE, value_exact = TRUE, match_case = TRUE, bbox = NULL )
opq |
An |
key |
feature key; can be negated with an initial exclamation mark,
|
value |
value for feature key; can be negated with an initial
exclamation mark, |
key_exact |
If FALSE, |
value_exact |
If FALSE, |
match_case |
If FALSE, matching for both |
bbox |
optional bounding box for the feature query; must be set if no opq query bbox has been set |
opq object
add_osm_feature
vs add_osm_features
Features defined within an add_osm_features call are combined with a logical OR.
Chained calls to either add_osm_feature or add_osm_features()
combines
features from these calls in a logical AND; this is analagous to chaining
dplyr::filter()
on a data frame.
add_osm_features()
with only one feature is logically equivalent to
add_osm_feature()
.
key_exact
should generally be TRUE
, because OSM uses a
reasonably well defined set of possible keys, as returned by
available_features. Setting key_exact = FALSE
allows matching
of regular expressions on OSM keys, as described in Section 6.1.5 of
https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL. The actual
query submitted to the overpass API can be obtained from
opq_string.
https://wiki.openstreetmap.org/wiki/Map_Features
Other queries:
add_osm_features()
,
bbox_to_string()
,
getbb()
,
opq()
,
opq_around()
,
opq_csv()
,
opq_enclosing()
,
opq_osm_id()
,
opq_string()
,
overpass_status()
## Not run: q <- opq ("portsmouth usa") %>% add_osm_feature ( key = "amenity", value = "restaurant" ) %>% add_osm_feature (key = "amenity", value = "pub") osmdata_sf (q) # all objects that are restaurants AND pubs (there are none!) q1 <- opq ("portsmouth usa") %>% add_osm_feature ( key = "amenity", value = "restaurant" ) q2 <- opq ("portsmouth usa") %>% add_osm_feature (key = "amenity", value = "pub") c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs # Use of negation to extract all non-primary highways q <- opq ("portsmouth uk") %>% add_osm_feature (key = "highway", value = "!primary") # key negation without warnings q3 <- opq ("Vinçà", osm_type="node") %>% add_osm_feature (key = c("name", "!name:ca")) q4 <- opq ("el Carxe", osm_type="node") %>% add_osm_feature (key = "natural", value = "peak") %>% add_osm_feature (key = "!ele") ## End(Not run)
## Not run: q <- opq ("portsmouth usa") %>% add_osm_feature ( key = "amenity", value = "restaurant" ) %>% add_osm_feature (key = "amenity", value = "pub") osmdata_sf (q) # all objects that are restaurants AND pubs (there are none!) q1 <- opq ("portsmouth usa") %>% add_osm_feature ( key = "amenity", value = "restaurant" ) q2 <- opq ("portsmouth usa") %>% add_osm_feature (key = "amenity", value = "pub") c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs # Use of negation to extract all non-primary highways q <- opq ("portsmouth uk") %>% add_osm_feature (key = "highway", value = "!primary") # key negation without warnings q3 <- opq ("Vinçà", osm_type="node") %>% add_osm_feature (key = c("name", "!name:ca")) q4 <- opq ("el Carxe", osm_type="node") %>% add_osm_feature (key = "natural", value = "peak") %>% add_osm_feature (key = "!ele") ## End(Not run)
Alternative version of add_osm_feature for creating single queries with multiple features. Key-value matching may be controlled by using the filter symbols described in https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#By_tag_.28has-kv.29.
add_osm_features( opq, features, bbox = NULL, key_exact = TRUE, value_exact = TRUE )
add_osm_features( opq, features, bbox = NULL, key_exact = TRUE, value_exact = TRUE )
opq |
An |
features |
A named list or vector with the format |
bbox |
optional bounding box for the feature query; must be set if no opq query bbox has been set. |
key_exact |
If FALSE, |
value_exact |
If FALSE, |
opq object
add_osm_feature
vs add_osm_features
Features defined within an add_osm_features call are combined with a logical OR.
Chained calls to either add_osm_feature or add_osm_features()
combines
features from these calls in a logical AND; this is analagous to chaining
dplyr::filter()
on a data frame.
add_osm_features()
with only one feature is logically equivalent to
add_osm_feature()
.
https://wiki.openstreetmap.org/wiki/Map_Features
Other queries:
add_osm_feature()
,
bbox_to_string()
,
getbb()
,
opq()
,
opq_around()
,
opq_csv()
,
opq_enclosing()
,
opq_osm_id()
,
opq_string()
,
overpass_status()
## Not run: q <- opq ("portsmouth usa") %>% add_osm_features (features = list ( "amenity" = "restaurant", "amenity" = "pub" )) q <- opq ("portsmouth usa") %>% add_osm_features (features = c ( "\"amenity\"=\"restaurant\"", "\"amenity\"=\"pub\"" )) # This extracts in a single query the same result as the following: q1 <- opq ("portsmouth usa") %>% add_osm_feature ( key = "amenity", value = "restaurant" ) q2 <- opq ("portsmouth usa") %>% add_osm_feature (key = "amenity", value = "pub") c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs ## End(Not run)
## Not run: q <- opq ("portsmouth usa") %>% add_osm_features (features = list ( "amenity" = "restaurant", "amenity" = "pub" )) q <- opq ("portsmouth usa") %>% add_osm_features (features = c ( "\"amenity\"=\"restaurant\"", "\"amenity\"=\"pub\"" )) # This extracts in a single query the same result as the following: q1 <- opq ("portsmouth usa") %>% add_osm_feature ( key = "amenity", value = "restaurant" ) q2 <- opq ("portsmouth usa") %>% add_osm_feature (key = "amenity", value = "pub") c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs ## End(Not run)
List recognized features in OSM
available_features()
available_features()
character vector of all known features
requires internet access
https://wiki.openstreetmap.org/wiki/Map_Features
Other osminfo:
available_tags()
## Not run: available_features () ## End(Not run)
## Not run: available_features () ## End(Not run)
List tags associated with a feature
available_tags(feature)
available_tags(feature)
feature |
feature to retrieve |
character vector of all known tags for a feature
requires internet access
https://wiki.openstreetmap.org/wiki/Map_Features
Other osminfo:
available_features()
## Not run: available_tags ("aerialway") ## End(Not run)
## Not run: available_tags ("aerialway") ## End(Not run)
This function converts a bounding box into a string for use in web apis
bbox_to_string(bbox)
bbox_to_string(bbox)
bbox |
bounding box as character, matrix, vector or a data.frame with
|
A character string representing min x, min y, max x, and max y
bounds. For example: "15.3152361,76.4406446,15.3552361,76.4806446"
is
the bounding box for Hampi, India. For data.frames with OSM objects, a
character string representing a set of OSM objects in overpass query
language. For example: "relation(id:11747082)"
represents the area of
the Catalan Countries. A set of objects can also be represented for multirow
data.frames (e.g. "relation(id:11747082,307833); way(id:22422490)"
).
Other queries:
add_osm_feature()
,
add_osm_features()
,
getbb()
,
opq()
,
opq_around()
,
opq_csv()
,
opq_enclosing()
,
opq_osm_id()
,
opq_string()
,
overpass_status()
## Not run: bbox_to_string (getbb ("València")) bbox_to_string (getbb ("València", format_out = "data.frame")) ## End(Not run)
## Not run: bbox_to_string (getbb ("València")) bbox_to_string (getbb ("València", format_out = "data.frame")) ## End(Not run)
Return the URL of the specified overpass API. Default is https://overpass-api.de/api/interpreter/.
get_overpass_url()
get_overpass_url()
The overpass API URL
Other overpass:
set_overpass_url()
This function uses the free Nominatim API provided by OpenStreetMap to find the bounding box (bb) associated with place names.
getbb( place_name, display_name_contains = NULL, viewbox = NULL, format_out = "matrix", base_url = "https://nominatim.openstreetmap.org", featuretype = "settlement", limit = 10, key = NULL, silent = TRUE )
getbb( place_name, display_name_contains = NULL, viewbox = NULL, format_out = "matrix", base_url = "https://nominatim.openstreetmap.org", featuretype = "settlement", limit = 10, key = NULL, silent = TRUE )
place_name |
The name of the place you're searching for |
display_name_contains |
Text string to match with display_name field returned by https://wiki.openstreetmap.org/wiki/Nominatim |
viewbox |
The bounds in which you're searching |
format_out |
Character string indicating output format: |
base_url |
Base website from where data is queried |
featuretype |
The type of OSM feature (settlement is default; see Note) |
limit |
How many results should the API return? |
key |
The API key to use for services that require it |
silent |
Should the API be printed to screen? TRUE by default |
It was inspired by the functions
bbox
from the sp package,
bb
from the tmaptools package and
bb_lookup
from the github package nominatim package,
which can be found at https://github.com/hrbrmstr/nominatim.
See https://wiki.openstreetmap.org/wiki/Nominatim for details.
Defaults to a matrix in the form:
min max
x ... ...
y ... ...
If format_out = "polygon"
, one or more two-columns matrices of polygonal
longitude-latitude points. Where multiple place_name
occurrences are found
within nominatim
, each item of the list of coordinates may itself contain
multiple coordinate matrices where multiple exact matches exist. If one
exact match exists with potentially multiple polygonal boundaries (for
example, "london uk" is an exact match, but can mean either greater London or
the City of London), only the first is returned. See examples below for
illustration.
For format_out = "osm_type_id"
, a character string representing an OSM object in overpass query
language. For example: "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 be represented for multiple results (e.g.
relation(id:11747082,307833); way(id:22422490)
). See examples below for
illustration. The OSM objects that can be used as
areas in overpass queries
must be closed rings (ways or relations).
Specific values of featuretype
include "street", "city",
https://wiki.openstreetmap.org/wiki/Nominatim for details). The default
featuretype = "settlement"
combines results from all intermediate
levels below "country" and above "streets". If the bounding box or polygon of
a city is desired, better results will usually be obtained with
featuretype = "city"
.
Other queries:
add_osm_feature()
,
add_osm_features()
,
bbox_to_string()
,
opq()
,
opq_around()
,
opq_csv()
,
opq_enclosing()
,
opq_osm_id()
,
opq_string()
,
overpass_status()
## Not run: getbb ("Salzburg") # select based on display_name, print query url getbb ("Hereford", display_name_contains = "United States", silent = FALSE) # top 3 matches as data frame getbb ("Hereford", format_out = "data.frame", limit = 3) # Examples of polygonal boundaries bb <- getbb ("london uk", format_out = "polygon") # single match dim (bb [[1]] [[1]]) # matrix of longitude/latitude pairs bb_sf <- getbb ("kathmandu", format_out = "sf_polygon") # sf:::plot.sf(bb_sf) # can be plotted if sf is installed getbb ("london", format_out = "sf_polygon") getbb ("accra", format_out = "sf_polygon") # rectangular bb area <- 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", ]) # 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 ) } ## End(Not run)
## Not run: getbb ("Salzburg") # select based on display_name, print query url getbb ("Hereford", display_name_contains = "United States", silent = FALSE) # top 3 matches as data frame getbb ("Hereford", format_out = "data.frame", limit = 3) # Examples of polygonal boundaries bb <- getbb ("london uk", format_out = "polygon") # single match dim (bb [[1]] [[1]]) # matrix of longitude/latitude pairs bb_sf <- getbb ("kathmandu", format_out = "sf_polygon") # sf:::plot.sf(bb_sf) # can be plotted if sf is installed getbb ("london", format_out = "sf_polygon") getbb ("accra", format_out = "sf_polygon") # rectangular bb area <- 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", ]) # 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 ) } ## End(Not run)
Build an Overpass query
opq( bbox = NULL, nodes_only = FALSE, osm_types = c("node", "way", "relation"), out = c("body", "tags", "meta", "skel", "tags center", "ids"), datetime = NULL, datetime2 = NULL, adiff = FALSE, timeout = 25, memsize )
opq( bbox = NULL, nodes_only = FALSE, osm_types = c("node", "way", "relation"), out = c("body", "tags", "meta", "skel", "tags center", "ids"), datetime = NULL, datetime2 = NULL, adiff = FALSE, timeout = 25, memsize )
bbox |
Either (i) four numeric values specifying the maximal and minimal
longitudes and latitudes, in the form |
nodes_only |
WARNING: this parameter is equivalent to
|
osm_types |
A character vector with several OSM types to query: |
out |
The level of verbosity of the overpass result: |
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 |
adiff |
If |
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. |
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.
An overpass_query
object
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.
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()
## 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) # 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) ## End(Not run)
## 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) # 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) ## End(Not run)
Find all features around a given point, and optionally match specific 'key'-'value' pairs. This function is not intended to be combined with add_osm_feature, rather is only to be used in the sequence opq_around -> osmdata_xml (or other extraction function). See examples for how to use.
opq_around(lon, lat, radius = 15, key = NULL, value = NULL, timeout = 25)
opq_around(lon, lat, radius = 15, key = NULL, value = NULL, timeout = 25)
lon |
Longitude of desired point |
lat |
Latitude of desired point |
radius |
Radius in metres around the point for which data should be extracted. Queries with large values for this parameter may fail. |
key |
(Optional) OSM key of enclosing data |
value |
(Optional) OSM value matching 'key' of enclosing data |
timeout |
It may be necessary to increase this value for large queries, because the server may time out before all data are delivered. |
Other queries:
add_osm_feature()
,
add_osm_features()
,
bbox_to_string()
,
getbb()
,
opq()
,
opq_csv()
,
opq_enclosing()
,
opq_osm_id()
,
opq_string()
,
overpass_status()
## Not run: # Get all benches ("amenity=bench") within 100m of a particular point lat <- 53.94542 lon <- -2.52017 key <- "amenity" value <- "bench" radius <- 100 x <- opq_around (lon, lat, radius, key, value) %>% osmdata_sf () ## End(Not run)
## Not run: # Get all benches ("amenity=bench") within 100m of a particular point lat <- 53.94542 lon <- -2.52017 key <- "amenity" value <- "bench" radius <- 100 x <- opq_around (lon, lat, radius, key, value) %>% osmdata_sf () ## End(Not run)
Transform an Overpass query to return the result in a csv format
opq_csv(q, fields, header = TRUE)
opq_csv(q, fields, header = TRUE)
q |
A opq string or an object of class |
fields |
a character vector with the field names. |
header |
if |
The output format csv
, ask for results in csv. See
CSV output mode
for details. To get the data, use osmdata_data_frame.
The overpass_query
or string with the prefix changed to
return a csv.
csv queries that reach the timeout will return a 0 row data.frame
without any warning. Increase timeout
in q
if you don't see the
expected result.
Other queries:
add_osm_feature()
,
add_osm_features()
,
bbox_to_string()
,
getbb()
,
opq()
,
opq_around()
,
opq_enclosing()
,
opq_osm_id()
,
opq_string()
,
overpass_status()
## Not run: q <- getbb ("Catalan Countries", format_out = "osm_type_id") %>% opq (out = "tags center", osm_type = "relation", timeout = 100) %>% add_osm_feature ("admin_level", "7") %>% add_osm_feature ("boundary", "administrative") %>% opq_csv (fields = c("name", "::type", "::id", "::lat", "::lon")) comarques <- osmdata_data_frame (q) # without timeout parameter, 0 rows qid<- opq_osm_id ( type = "relation", id = c ("341530", "1809102", "1664395", "343124"), out = "tags" ) %>% opq_csv (fields = c ("name", "name:ca")) cities <- osmdata_data_frame (qid) ## End(Not run)
## Not run: q <- getbb ("Catalan Countries", format_out = "osm_type_id") %>% opq (out = "tags center", osm_type = "relation", timeout = 100) %>% add_osm_feature ("admin_level", "7") %>% add_osm_feature ("boundary", "administrative") %>% opq_csv (fields = c("name", "::type", "::id", "::lat", "::lon")) comarques <- osmdata_data_frame (q) # without timeout parameter, 0 rows qid<- opq_osm_id ( type = "relation", id = c ("341530", "1809102", "1664395", "343124"), out = "tags" ) %>% opq_csv (fields = c ("name", "name:ca")) cities <- osmdata_data_frame (qid) ## End(Not run)
Find all features which enclose a given point, and optionally match specific 'key'-'value' pairs. This function is not intended to be combined with add_osm_feature, rather is only to be used in the sequence opq_enclosing -> opq_string -> osmdata_xml (or other extraction function). See examples for how to use.
opq_enclosing( lon = NULL, lat = NULL, key = NULL, value = NULL, enclosing = "relation", timeout = 25 )
opq_enclosing( lon = NULL, lat = NULL, key = NULL, value = NULL, enclosing = "relation", timeout = 25 )
lon |
Longitude of desired point |
lat |
Latitude of desired point |
key |
(Optional) OSM key of enclosing data |
value |
(Optional) OSM value matching 'key' of enclosing data |
enclosing |
Either 'relation' or 'way' for whether to return enclosing objects of those respective types (where generally 'relation' will correspond to multipolygon objects, and 'way' to polygon objects). |
timeout |
It may be necessary to increase this value for large queries, because the server may time out before all data are delivered. |
Other queries:
add_osm_feature()
,
add_osm_features()
,
bbox_to_string()
,
getbb()
,
opq()
,
opq_around()
,
opq_csv()
,
opq_osm_id()
,
opq_string()
,
overpass_status()
## Not run: # Get water body surrounding a particular point: lat <- 54.33601 lon <- -3.07677 key <- "natural" value <- "water" x <- opq_enclosing (lon, lat, key, value) %>% opq_string () %>% osmdata_sf () ## End(Not run)
## Not run: # Get water body surrounding a particular point: lat <- 54.33601 lon <- -3.07677 key <- "natural" value <- "water" x <- opq_enclosing (lon, lat, key, value) %>% opq_string () %>% osmdata_sf () ## End(Not run)
Add a feature specified by OSM ID to an Overpass query
opq_osm_id( id = NULL, type = NULL, open_url = FALSE, out = "body", datetime = NULL, datetime2 = NULL, adiff = FALSE, timeout = 25, memsize )
opq_osm_id( id = NULL, type = NULL, open_url = FALSE, out = "body", datetime = NULL, datetime2 = NULL, adiff = FALSE, timeout = 25, memsize )
id |
One or more official OSM identifiers (long-form integers), which must be entered as either a character or numeric value (because R does not support long-form integers). id can also be a character string prefixed with the id type, e.g. "relation/11158003" |
type |
Type of objects (recycled); must be either |
open_url |
If |
out |
The level of verbosity of the overpass result: |
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 |
adiff |
If |
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. |
opq object
Extracting elements by ID requires explicitly specifying the type of element. Only elements of one of the three given types can be extracted in a single query, but the results of multiple types can nevertheless be combined with the c operation of osmdata.
https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#By_element_id
Other queries:
add_osm_feature()
,
add_osm_features()
,
bbox_to_string()
,
getbb()
,
opq()
,
opq_around()
,
opq_csv()
,
opq_enclosing()
,
opq_string()
,
overpass_status()
## Not run: id <- c (1489221200, 1489221321, 1489221491) dat1 <- opq_osm_id (type = "node", id = id) %>% opq_string () %>% osmdata_sf () dat1$osm_points # the desired nodes id <- c (136190595, 136190596) dat2 <- opq_osm_id (type = "way", id = id) %>% opq_string () %>% osmdata_sf () dat2$osm_lines # the desired ways dat <- c (dat1, dat2) # The node and way data combined # All in one (same result as dat) id <- c (1489221200, 1489221321, 1489221491, 136190595, 136190596) type <- c ("node", "node", "node", "way", "way") datAiO <- opq_osm_id (id = id, type = type) %>% opq_string () %>% osmdata_sf () ## End(Not run)
## Not run: id <- c (1489221200, 1489221321, 1489221491) dat1 <- opq_osm_id (type = "node", id = id) %>% opq_string () %>% osmdata_sf () dat1$osm_points # the desired nodes id <- c (136190595, 136190596) dat2 <- opq_osm_id (type = "way", id = id) %>% opq_string () %>% osmdata_sf () dat2$osm_lines # the desired ways dat <- c (dat1, dat2) # The node and way data combined # All in one (same result as dat) id <- c (1489221200, 1489221321, 1489221491, 136190595, 136190596) type <- c ("node", "node", "node", "way", "way") datAiO <- opq_osm_id (id = id, type = type) %>% opq_string () %>% osmdata_sf () ## End(Not run)
Convert an osmdata query of class opq to a character string query to be submitted to the overpass API.
opq_string(opq)
opq_string(opq)
opq |
An |
Character string to be submitted to the overpass API
Other queries:
add_osm_feature()
,
add_osm_features()
,
bbox_to_string()
,
getbb()
,
opq()
,
opq_around()
,
opq_csv()
,
opq_enclosing()
,
opq_osm_id()
,
overpass_status()
## Not run: q <- opq ("hampi india") opq_string (q) ## End(Not run)
## Not run: q <- opq ("hampi india") opq_string (q) ## End(Not run)
Add elevation data to a previously-extracted OSM data set, using a
pre-downloaded global elevation file from
https://srtm.csi.cgiar.org/srtmdata/. Currently only works for
SC
-class objects returned from osmdata_sc.
osm_elevation(dat, elev_file)
osm_elevation(dat, elev_file)
dat |
An |
elev_file |
A vector of one or more character strings specifying paths
to |
A modified version of the input dat
with an additional z_
column
appended to the vertices.
Other transform:
osm_poly2line()
,
trim_osmdata()
,
unique_osmdata()
,
unname_osmdata_sf()
osm_lines
from an osmdata objectIf id
is of a point object, osm_lines
will return all lines
containing that point. If id
is of a line or polygon object,
osm_lines
will return all lines which intersect the given line or
polygon.
osm_lines(dat, id)
osm_lines(dat, id)
dat |
An object of class osmdata |
id |
OSM identification of one or more objects for which lines are to be extracted |
An sf Simple Features Collection of linestrings
Other search:
osm_multilines()
,
osm_multipolygons()
,
osm_points()
,
osm_polygons()
## Not run: dat <- opq ("hengelo nl") %>% add_osm_feature (key = "highway") %>% osmdata_sf () bus <- dat$osm_points [which (dat$osm_points$highway == "bus_stop"), ] %>% rownames () # all OSM IDs of bus stops osm_lines (dat, bus) # all highways containing bus stops # All lines which intersect with Piccadilly Circus in London, UK dat <- opq ("Fitzrovia London") %>% add_osm_feature (key = "highway") %>% osmdata_sf () i <- which (dat$osm_polygons$name == "Piccadilly Circus") id <- rownames (dat$osm_polygons [i, ]) osm_lines (dat, id) ## End(Not run)
## Not run: dat <- opq ("hengelo nl") %>% add_osm_feature (key = "highway") %>% osmdata_sf () bus <- dat$osm_points [which (dat$osm_points$highway == "bus_stop"), ] %>% rownames () # all OSM IDs of bus stops osm_lines (dat, bus) # all highways containing bus stops # All lines which intersect with Piccadilly Circus in London, UK dat <- opq ("Fitzrovia London") %>% add_osm_feature (key = "highway") %>% osmdata_sf () i <- which (dat$osm_polygons$name == "Piccadilly Circus") id <- rownames (dat$osm_polygons [i, ]) osm_lines (dat, id) ## End(Not run)
osm_multilines
from an osmdata objectid
must be of an osm_points
or osm_lines
object (and can
not be the id
of an osm_polygons
object because multilines by
definition contain no polygons. osm_multilines
returns any multiline
object(s) which contain the object specified by id
.
osm_multilines(dat, id)
osm_multilines(dat, id)
dat |
An object of class osmdata |
id |
OSM identification of one of more objects for which multilines are to be extracted |
An sf Simple Features Collection of multilines
Other search:
osm_lines()
,
osm_multipolygons()
,
osm_points()
,
osm_polygons()
## Not run: dat <- opq ("London UK") %>% add_osm_feature (key = "name", value = "Thames", exact = FALSE) %>% osmdata_sf () # Get ids of lines called "The Thames": id <- rownames (dat$osm_lines [which (dat$osm_lines$name == "The Thames"), ]) # and find all multilinestring objects which include those lines: osm_multilines (dat, id) # Now note that nrow (dat$osm_multilines) # = 24 multiline objects nrow (osm_multilines (dat, id)) # = 1 - the recursive search selects the # single multiline containing "The Thames" ## End(Not run)
## Not run: dat <- opq ("London UK") %>% add_osm_feature (key = "name", value = "Thames", exact = FALSE) %>% osmdata_sf () # Get ids of lines called "The Thames": id <- rownames (dat$osm_lines [which (dat$osm_lines$name == "The Thames"), ]) # and find all multilinestring objects which include those lines: osm_multilines (dat, id) # Now note that nrow (dat$osm_multilines) # = 24 multiline objects nrow (osm_multilines (dat, id)) # = 1 - the recursive search selects the # single multiline containing "The Thames" ## End(Not run)
osm_multipolygons
from an osmdata objectid
must be of an osm_points
, osm_lines
, or
osm_polygons
object. osm_multipolygons
returns any multipolygon
object(s) which contain the object specified by id
.
osm_multipolygons(dat, id)
osm_multipolygons(dat, id)
dat |
An object of class osmdata |
id |
OSM identification of one or more objects for which multipolygons are to be extracted |
An sf Simple Features Collection of multipolygons
Other search:
osm_lines()
,
osm_multilines()
,
osm_points()
,
osm_polygons()
## Not run: # find all multipolygons which contain the single polygon called # "Chiswick Eyot" (which is an island). dat <- opq ("London UK") %>% add_osm_feature (key = "name", value = "Thames", exact = FALSE) %>% osmdata_sf () index <- which (dat$osm_multipolygons$name == "Chiswick Eyot") id <- rownames (dat$osm_polygons [id, ]) osm_multipolygons (dat, id) # That multipolygon is the Thames itself, but note that nrow (dat$osm_multipolygons) # = 14 multipolygon objects nrow (osm_multipolygons (dat, id)) # = 1 - the main Thames multipolygon ## End(Not run)
## Not run: # find all multipolygons which contain the single polygon called # "Chiswick Eyot" (which is an island). dat <- opq ("London UK") %>% add_osm_feature (key = "name", value = "Thames", exact = FALSE) %>% osmdata_sf () index <- which (dat$osm_multipolygons$name == "Chiswick Eyot") id <- rownames (dat$osm_polygons [id, ]) osm_multipolygons (dat, id) # That multipolygon is the Thames itself, but note that nrow (dat$osm_multipolygons) # = 14 multipolygon objects nrow (osm_multipolygons (dat, id)) # = 1 - the main Thames multipolygon ## End(Not run)
osm_points
from an osmdata objectExtract all osm_points
from an osmdata object
osm_points(dat, id)
osm_points(dat, id)
dat |
An object of class osmdata |
id |
OSM identification of one or more objects for which points are to be extracted |
An sf Simple Features Collection of points
Other search:
osm_lines()
,
osm_multilines()
,
osm_multipolygons()
,
osm_polygons()
## Not run: tr <- opq ("trentham australia") %>% osmdata_sf () coliban <- tr$osm_lines [which (tr$osm_lines$name == "Coliban River"), ] pts <- osm_points (tr, rownames (coliban)) # all points of river # the waterfall point: waterfall <- pts [which (pts$waterway == "waterfall"), ] ## End(Not run)
## Not run: tr <- opq ("trentham australia") %>% osmdata_sf () coliban <- tr$osm_lines [which (tr$osm_lines$name == "Coliban River"), ] pts <- osm_points (tr, rownames (coliban)) # all points of river # the waterfall point: waterfall <- pts [which (pts$waterway == "waterfall"), ] ## End(Not run)
Street networks downloaded with add_osm_object(key = "highway")
will
store any circular highways in osm_polygons
. this function combines
those with the osm_lines
component to yield a single sf
data.frame
of all highways, whether polygonal or not.
osm_poly2line(osmdat)
osm_poly2line(osmdat)
osmdat |
An osmdata object. |
Modified version of same object with all osm_polygons
objects merged into osm_lines
.
The osm_polygons
field is retained, with those features also
repeated as LINESTRING
objects in osm_lines
.
Other transform:
osm_elevation()
,
trim_osmdata()
,
unique_osmdata()
,
unname_osmdata_sf()
## Not run: dat <- opq ("colchester uk") %>% add_osm_feature (key = "highway") %>% osmdata_sf () # colchester has lots of roundabouts, and these are stored in 'osm_polygons' # rather than 'osm_lines'. The former can be merged with the latter by: dat2 <- osm_poly2line (dat) # 'dat2' will have more lines than 'dat', but the same number of polygons # (they are left unchanged.) ## End(Not run)
## Not run: dat <- opq ("colchester uk") %>% add_osm_feature (key = "highway") %>% osmdata_sf () # colchester has lots of roundabouts, and these are stored in 'osm_polygons' # rather than 'osm_lines'. The former can be merged with the latter by: dat2 <- osm_poly2line (dat) # 'dat2' will have more lines than 'dat', but the same number of polygons # (they are left unchanged.) ## End(Not run)
osm_polygons
from an osmdata objectIf id
is of a point object, osm_polygons
will return all
polygons containing that point. If id
is of a line or polygon object,
osm_polygons
will return all polygons which intersect the given line
or polygon.
osm_polygons(dat, id)
osm_polygons(dat, id)
dat |
An object of class osmdata |
id |
OSM identification of one or more objects for which polygons are to be extracted |
An sf Simple Features Collection of polygons
Other search:
osm_lines()
,
osm_multilines()
,
osm_multipolygons()
,
osm_points()
## Not run: # Extract polygons which intersect Conway Street in London dat <- opq ("Marylebone London") %>% add_osm_feature (key = "highway") %>% osmdata_sf () conway <- which (dat$osm_lines$name == "Conway Street") id <- rownames (dat$osm_lines [conway, ]) osm_polygons (dat, id) ## End(Not run)
## Not run: # Extract polygons which intersect Conway Street in London dat <- opq ("Marylebone London") %>% add_osm_feature (key = "highway") %>% osmdata_sf () conway <- which (dat$osm_lines$name == "Conway Street") id <- rownames (dat$osm_lines [conway, ]) osm_polygons (dat, id) ## End(Not run)
Imports OpenStreetMap (OSM) data into R as 'sf', 'SC', 'sp', 'data.frame' or 'xml_document' objects. OSM data are extracted from the overpass API and processed with very fast C++ routines for return to R. The package enables simple overpass queries to be constructed without the user necessarily understanding the syntax of the overpass query language, while retaining the ability to handle arbitrarily complex queries. Functions are also provided to enable recursive searching between different kinds of OSM data (for example, to find all lines which intersect a given point).
osmdata( bbox = NULL, overpass_call = NULL, meta = NULL, osm_points = NULL, osm_lines = NULL, osm_polygons = NULL, osm_multilines = NULL, osm_multipolygons = NULL )
osmdata( bbox = NULL, overpass_call = NULL, meta = NULL, osm_points = NULL, osm_lines = NULL, osm_polygons = NULL, osm_multilines = NULL, osm_multipolygons = NULL )
bbox |
bounding box |
overpass_call |
overpass_call |
meta |
metadata of overpass query, including timestamps and version numbers |
osm_points |
OSM nodes as sf Simple Features Collection of points or sp SpatialPointsDataFrame |
osm_lines |
OSM ways sf Simple Features Collection of linestrings or sp SpatialLinesDataFrame |
osm_polygons |
OSM ways as sf Simple Features Collection of polygons or sp SpatialPolygonsDataFrame |
osm_multilines |
OSM relations as sf Simple Features Collection of multilinestrings or sp SpatialLinesDataFrame |
osm_multipolygons |
OSM relations as sf Simple Features Collection of multipolygons or sp SpatialPolygonsDataFrame |
getbb: Get bounding box for a given place name
bbox_to_string: Convert a named matrix or a named vector (or an unnamed vector) return a string
overpass_status: Retrieve status of the overpass API
opq: Build an overpass query
add_osm_feature: Add a feature to an overpass query
opq_string: Convert an osmdata query to overpass API string
available_features: List recognised features in OSM
available_tags: List tags associated with a feature
osmdata_data_frame: Return OSM data in data.frame
format
osmdata_sc: Return OSM data in silicate format
osmdata_sf: Return OSM data in sf format
osmdata_sp: Return OSM data in sp format
osmdata_xml: Return OSM data in xml2 format
osm_points
: Extract all osm_points
objects
osm_lines
: Extract all osm_lines
objects
osm_polygons
: Extract all osm_polygons
objects
osm_multilines
: Extract all osm_multilines
objects
osm_multipolygons
: Extract all osm_multipolygons
objects
Class constructor should never be used directly, and is only exported to provide access to the print method
Mark Padgham, Bob Rudis, Robin Lovelace, Maëlle Salmon, Joan Maspons
Useful links:
https://docs.ropensci.org/osmdata/ (website) https://github.com/ropensci/osmdata/ (devel)
Report bugs at https://github.com/ropensci/osmdata/issues
Return an OSM Overpass query as a data.frame object.
osmdata_data_frame(q, doc, quiet = TRUE, stringsAsFactors = FALSE)
osmdata_data_frame(q, doc, quiet = TRUE, stringsAsFactors = FALSE)
q |
An object of class |
doc |
If missing, |
quiet |
suppress status messages. |
stringsAsFactors |
Should character strings in the 'data.frame' be coerced to factors? |
If you are not interested in the geometries of the results, it's a
good option to query for objects that match the features only and forget
about members of the ways and relations. You can achieve this by passing
the parameter body = "tags"
to opq
.
A data.frame
with id, type and tags of the the objects from the
query.
Other extract:
osmdata_sc()
,
osmdata_sf()
,
osmdata_sp()
,
osmdata_xml()
## Not run: hampi_df <- opq ("hampi india") %>% add_osm_feature (key = "historic", value = "ruins") %>% osmdata_data_frame () attr (hampi_df, "bbox") attr (hampi_df, "overpass_call") attr (hampi_df, "meta") # Complex query as a string (not possible with regular osmdata functions) q <- '[out:csv(::type, ::id, "name:ca", "wikidata")][timeout:50]; area[name="Països Catalans"][boundary=political]->.boundaryarea; rel(area.boundaryarea)[admin_level=8][boundary=administrative]; map_to_area -> .all_level_8_areas; ( nwr(area.boundaryarea)[amenity=townhall]; >; ); is_in; area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall; (.all_level_8_areas; - .level_8_areas_with_townhall;); rel(pivot); out tags;' no_townhall <- osmdata_data_frame (q) no_townhall ## End(Not run)
## Not run: hampi_df <- opq ("hampi india") %>% add_osm_feature (key = "historic", value = "ruins") %>% osmdata_data_frame () attr (hampi_df, "bbox") attr (hampi_df, "overpass_call") attr (hampi_df, "meta") # Complex query as a string (not possible with regular osmdata functions) q <- '[out:csv(::type, ::id, "name:ca", "wikidata")][timeout:50]; area[name="Països Catalans"][boundary=political]->.boundaryarea; rel(area.boundaryarea)[admin_level=8][boundary=administrative]; map_to_area -> .all_level_8_areas; ( nwr(area.boundaryarea)[amenity=townhall]; >; ); is_in; area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall; (.all_level_8_areas; - .level_8_areas_with_townhall;); rel(pivot); out tags;' no_townhall <- osmdata_data_frame (q) no_townhall ## End(Not run)
silicate
(SC
) format.Return an OSM Overpass query as an osmdata object in
silicate
(SC
) format.
osmdata_sc(q, doc, quiet = TRUE)
osmdata_sc(q, doc, quiet = TRUE)
q |
An object of class |
doc |
If missing, |
quiet |
suppress status messages. |
An object of class osmdata_sc
representing the original OSM hierarchy
of nodes, ways, and relations.
The silicate
format is currently highly experimental, and
recommended for use only if you really know what you're doing.
Other extract:
osmdata_data_frame()
,
osmdata_sf()
,
osmdata_sp()
,
osmdata_xml()
## Not run: hampi_sf <- opq ("hampi india") %>% add_osm_feature (key = "historic", value = "ruins") %>% osmdata_sc () # Complex query as a string (not possible with regular osmdata functions) q <- '[out:xml][timeout:50]; area[name="Països Catalans"][boundary=political]->.boundaryarea; rel(area.boundaryarea)[admin_level=8][boundary=administrative]; map_to_area -> .all_level_8_areas; ( nwr(area.boundaryarea)[amenity=townhall]; >; ); is_in; area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall; (.all_level_8_areas; - .level_8_areas_with_townhall;); rel(pivot); (._; >;); out;' no_townhall <- osmdata_sc (q) no_townhall ## End(Not run)
## Not run: hampi_sf <- opq ("hampi india") %>% add_osm_feature (key = "historic", value = "ruins") %>% osmdata_sc () # Complex query as a string (not possible with regular osmdata functions) q <- '[out:xml][timeout:50]; area[name="Països Catalans"][boundary=political]->.boundaryarea; rel(area.boundaryarea)[admin_level=8][boundary=administrative]; map_to_area -> .all_level_8_areas; ( nwr(area.boundaryarea)[amenity=townhall]; >; ); is_in; area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall; (.all_level_8_areas; - .level_8_areas_with_townhall;); rel(pivot); (._; >;); out;' no_townhall <- osmdata_sc (q) no_townhall ## End(Not run)
Return an OSM Overpass query as an osmdata object in sf format.
osmdata_sf(q, doc, quiet = TRUE, stringsAsFactors = FALSE)
osmdata_sf(q, doc, quiet = TRUE, stringsAsFactors = FALSE)
q |
An object of class |
doc |
If missing, |
quiet |
suppress status messages. |
stringsAsFactors |
Should character strings in 'sf' 'data.frame' be coerced to factors? |
An object of class osmdata
with the OSM components (points, lines,
and polygons) represented in sf format.
Other extract:
osmdata_data_frame()
,
osmdata_sc()
,
osmdata_sp()
,
osmdata_xml()
## Not run: hampi_sf <- opq ("hampi india") %>% add_osm_feature (key = "historic", value = "ruins") %>% osmdata_sf () # Complex query as a string (not possible with regular osmdata functions) q <- '[out:xml][timeout:50]; area[name="Països Catalans"][boundary=political]->.boundaryarea; rel(area.boundaryarea)[admin_level=8][boundary=administrative]; map_to_area -> .all_level_8_areas; ( nwr(area.boundaryarea)[amenity=townhall]; >; ); is_in; area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall; (.all_level_8_areas; - .level_8_areas_with_townhall;); rel(pivot); (._; >;); out;' no_townhall <- osmdata_sf (q) no_townhall ## End(Not run)
## Not run: hampi_sf <- opq ("hampi india") %>% add_osm_feature (key = "historic", value = "ruins") %>% osmdata_sf () # Complex query as a string (not possible with regular osmdata functions) q <- '[out:xml][timeout:50]; area[name="Països Catalans"][boundary=political]->.boundaryarea; rel(area.boundaryarea)[admin_level=8][boundary=administrative]; map_to_area -> .all_level_8_areas; ( nwr(area.boundaryarea)[amenity=townhall]; >; ); is_in; area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall; (.all_level_8_areas; - .level_8_areas_with_townhall;); rel(pivot); (._; >;); out;' no_townhall <- osmdata_sf (q) no_townhall ## End(Not run)
Return an OSM Overpass query as an osmdata object in sp format.
osmdata_sp(q, doc, quiet = TRUE)
osmdata_sp(q, doc, quiet = TRUE)
q |
An object of class |
doc |
If missing, |
quiet |
suppress status messages. |
An object of class osmdata
with the OSM components (points, lines,
and polygons) represented in sp format.
Other extract:
osmdata_data_frame()
,
osmdata_sc()
,
osmdata_sf()
,
osmdata_xml()
## Not run: hampi_sp <- opq ("hampi india") %>% add_osm_feature (key = "historic", value = "ruins") %>% osmdata_sp () # Complex query as a string (not possible with regular osmdata functions) q <- '[out:xml][timeout:50]; area[name="Països Catalans"][boundary=political]->.boundaryarea; rel(area.boundaryarea)[admin_level=8][boundary=administrative]; map_to_area -> .all_level_8_areas; ( nwr(area.boundaryarea)[amenity=townhall]; >; ); is_in; area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall; (.all_level_8_areas; - .level_8_areas_with_townhall;); rel(pivot); (._; >;); out;' no_townhall <- osmdata_sp (q) no_townhall ## End(Not run)
## Not run: hampi_sp <- opq ("hampi india") %>% add_osm_feature (key = "historic", value = "ruins") %>% osmdata_sp () # Complex query as a string (not possible with regular osmdata functions) q <- '[out:xml][timeout:50]; area[name="Països Catalans"][boundary=political]->.boundaryarea; rel(area.boundaryarea)[admin_level=8][boundary=administrative]; map_to_area -> .all_level_8_areas; ( nwr(area.boundaryarea)[amenity=townhall]; >; ); is_in; area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall; (.all_level_8_areas; - .level_8_areas_with_townhall;); rel(pivot); (._; >;); out;' no_townhall <- osmdata_sp (q) no_townhall ## End(Not run)
Return an OSM Overpass query in XML format Read an (XML format) OSM Overpass response from a string, a connection, or a raw vector.
osmdata_xml(q, filename, quiet = TRUE, encoding)
osmdata_xml(q, filename, quiet = TRUE, encoding)
q |
An object of class |
filename |
If given, OSM data are saved to the named file |
quiet |
suppress status messages. |
encoding |
Unless otherwise specified XML documents are assumed to be encoded as UTF-8 or UTF-16. If the document is not UTF-8/16, and lacks an explicit encoding directive, this allows you to supply a default. |
An object of class xml2::xml_document
containing the result of the
overpass API query.
Objects of class xml_document
can be saved as .xml
or
.osm
files with xml2::write_xml
.
Other extract:
osmdata_data_frame()
,
osmdata_sc()
,
osmdata_sf()
,
osmdata_sp()
## Not run: q <- opq ("hampi india") q <- add_osm_feature (q, key = "historic", value = "ruins") osmdata_xml (q, filename = "hampi.osm") # Complex query as a string (not possible with regular osmdata functions) q <- '[out:xml][timeout:50]; area[name="Països Catalans"][boundary=political]->.boundaryarea; rel(area.boundaryarea)[admin_level=8][boundary=administrative]; map_to_area -> .all_level_8_areas; ( nwr(area.boundaryarea)[amenity=townhall]; >; ); is_in; area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall; (.all_level_8_areas; - .level_8_areas_with_townhall;); rel(pivot); out tags;' no_townhall <- osmdata_xml (q) no_townhall ## End(Not run)
## Not run: q <- opq ("hampi india") q <- add_osm_feature (q, key = "historic", value = "ruins") osmdata_xml (q, filename = "hampi.osm") # Complex query as a string (not possible with regular osmdata functions) q <- '[out:xml][timeout:50]; area[name="Països Catalans"][boundary=political]->.boundaryarea; rel(area.boundaryarea)[admin_level=8][boundary=administrative]; map_to_area -> .all_level_8_areas; ( nwr(area.boundaryarea)[amenity=townhall]; >; ); is_in; area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall; (.all_level_8_areas; - .level_8_areas_with_townhall;); rel(pivot); out tags;' no_townhall <- osmdata_xml (q) no_townhall ## End(Not run)
Retrieve status of the Overpass API
overpass_status(quiet = FALSE)
overpass_status(quiet = FALSE)
quiet |
if |
an invisible list of whether the API is available along with the text of the message from Overpass and the timestamp of the next available slot
Other queries:
add_osm_feature()
,
add_osm_features()
,
bbox_to_string()
,
getbb()
,
opq()
,
opq_around()
,
opq_csv()
,
opq_enclosing()
,
opq_osm_id()
,
opq_string()
Set the URL of the specified overpass API. Possible APIs with global coverage are:
"https://overpass-api.de/api/interpreter" (default)
"https://overpass.kumi.systems/api/interpreter"
"https://overpass.osm.rambler.ru/cgi/interpreter"
"https://api.openstreetmap.fr/oapi/interpreter"
"https://overpass.osm.vi-di.fr/api/interpreter"
Additional APIs with limited local coverage include:
"https://overpass.osm.ch/api/interpreter" (Switzerland)
"https://overpass.openstreetmap.ie/api/interpreter" (Ireland)
set_overpass_url(overpass_url)
set_overpass_url(overpass_url)
overpass_url |
The desired overpass API URL |
For further details, see https://wiki.openstreetmap.org/wiki/Overpass_API
The overpass API URL
Other overpass:
get_overpass_url()
Trim an osmdata object to within a bounding polygon
trim_osmdata(dat, bb_poly, exclude = TRUE)
trim_osmdata(dat, bb_poly, exclude = TRUE)
dat |
An osmdata object returned from osmdata_sf or osmdata_sp. |
bb_poly |
A matrix representing a bounding polygon obtained with
|
exclude |
If TRUE, objects are trimmed exclusively, only retaining those strictly within the bounding polygon; otherwise all objects which partly extend within the bounding polygon are retained. |
A trimmed version of dat
, reduced only to those components
lying within the bounding polygon.
It will generally be necessary to pre-load the sf package for this function to work correctly.
Caution is advised when using polygons obtained from Nominatim via
getbb(..., format_out = "polygon"|"sf_polygon")
. These shapes can be
outdated and thus could cause the trimming operation to not give results
expected based on the current state of the OSM data.
Other transform:
osm_elevation()
,
osm_poly2line()
,
unique_osmdata()
,
unname_osmdata_sf()
## Not run: dat <- opq ("colchester uk") %>% add_osm_feature (key = "highway") %>% osmdata_sf (quiet = FALSE) bb <- getbb ("colchester uk", format_out = "polygon") library (sf) # required for this function to work dat_tr <- trim_osmdata (dat, bb) bb <- getbb ("colchester uk", format_out = "sf_polygon") class (bb) # sf data.frame dat_tr <- trim_osmdata (dat, bb) bb <- as (bb, "Spatial") class (bb) # SpatialPolygonsDataFrame dat_tr <- trim_osmdata (dat, bb) ## End(Not run)
## Not run: dat <- opq ("colchester uk") %>% add_osm_feature (key = "highway") %>% osmdata_sf (quiet = FALSE) bb <- getbb ("colchester uk", format_out = "polygon") library (sf) # required for this function to work dat_tr <- trim_osmdata (dat, bb) bb <- getbb ("colchester uk", format_out = "sf_polygon") class (bb) # sf data.frame dat_tr <- trim_osmdata (dat, bb) bb <- as (bb, "Spatial") class (bb) # SpatialPolygonsDataFrame dat_tr <- trim_osmdata (dat, bb) ## End(Not run)
Reduce the components of an osmdata object to only unique items of
each type. That is, reduce $osm_points
to only those points not
present in other objects (lines, polygons, etc.); reduce $osm_lines
to
only those lines not present in multiline objects; and reduce
$osm_polygons
to only those polygons not present in multipolygon
objects. This renders an osmdata object more directly compatible with
typical output of sf.
unique_osmdata(dat)
unique_osmdata(dat)
dat |
An osmdata object |
Equivalent object reduced to only unique objects of each type
Other transform:
osm_elevation()
,
osm_poly2line()
,
trim_osmdata()
,
unname_osmdata_sf()
Remove names from osmdata
geometry objects, for cases in which these cause
issues, particularly with plotting, such as
https://github.com/rstudio/leaflet/issues/631, or
https://github.com/r-spatial/sf/issues/1177. Note that removing these
names also removes any ability to inter-relate the different components of an
osmdata
object, so use of this function is only recommended to resolve
issues such as those linked to above.
unname_osmdata_sf(x)
unname_osmdata_sf(x)
x |
An 'osmdata_sf' object returned from function of same name |
Same object, yet with no row names on geometry objects.
Other transform:
osm_elevation()
,
osm_poly2line()
,
trim_osmdata()
,
unique_osmdata()
## Not run: hampi_sf <- opq ("hampi india") %>% add_osm_feature (key = "historic", value = "ruins") %>% osmdata_sf () hampi_clean <- unname_osmdata_sf (hampi_sf) # All coordinate matrices include rownames with OSM ID values: head (as.matrix (hampi_sf$osm_lines$geometry [[1]])) # But 'unname_osmdata_sf' removes both row and column names: head (as.matrix (hampi_clean$osm_lines$geometry [[1]])) ## End(Not run)
## Not run: hampi_sf <- opq ("hampi india") %>% add_osm_feature (key = "historic", value = "ruins") %>% osmdata_sf () hampi_clean <- unname_osmdata_sf (hampi_sf) # All coordinate matrices include rownames with OSM ID values: head (as.matrix (hampi_sf$osm_lines$geometry [[1]])) # But 'unname_osmdata_sf' removes both row and column names: head (as.matrix (hampi_clean$osm_lines$geometry [[1]])) ## End(Not run)