Retrieve objects by type
, id
and version
.
Usage
osm_get_objects(
osm_type,
osm_id,
version,
full_objects = FALSE,
format = c("R", "xml", "json"),
tags_in_columns = FALSE
)
Arguments
- osm_type
A vector with the type of the objects (
"node"
,"way"
or"relation"
). Recycled if it has a different length thanosm_id
.- osm_id
Object ids represented by a numeric or a character vector.
- version
An optional vector with the version number for each object. If missing, the last version will be retrieved. Recycled if it has different length than
osm_id
.- full_objects
If
TRUE
, retrieves all other objects referenced by ways or relations. Not compatible withversion
.- format
Format of the output. Can be
"R"
(default),"xml"
, or"json"
.- tags_in_columns
If
FALSE
(default), the tags of the objects are saved in a single list columntags``` containing a
data.framefor each OSM object with the keys and values. If
TRUE, add a column for each key. Ignored if
format != "R"`.
Value
If format = "R"
, returns a data frame with one OSM object per row. If format = "xml"
, returns a
xml2::xml_document following the
OSM_XML format. If format = "json"
,
returns a list with a json structure following the OSM_JSON format.
Objects are sorted in the same order than osm_id
except for full_objects = TRUE
, where the nodes comes first,
then ways, and relations at the end as specified by
OSM_XML format.
Details
full_objects = TRUE
does not support specifying version
.
For ways, full_objects = TRUE
implies that it will return the way specified plus all nodes referenced by the way.
For a relation, it will return the following:
The relation itself
All nodes, ways, and relations that are members of the relation
Plus all nodes used by ways from the previous step
The same recursive logic is not applied to relations. This means: If relation r1 contains way w1 and relation r2, and w1 contains nodes n1 and n2, and r2 contains node n3, then a "full" request for r1 will give you r1, r2, w1, n1, and n2. Not n3.
Note
For downloading data for purposes other than editing or exploring the history of the objects, perhaps is better to
use the Overpass API. A similar function to download OSM objects by type
and id
using Overpass, is implemented in
the osmdata function opq_osm_id()
.
See also
Other get OSM objects' functions:
osm_bbox_objects()
,
osm_history_object()
,
osm_relations_object()
,
osm_ways_node()
,
osmapi_objects()