Why does these 2 approaches produce different amount of ways?
According to definition of a way:
A way is defined:
A way is an ordered list of nodes which normally also has at least one tag or is included within a Relation. A way can have between 2 and 2,000 nodes, although it's possible that faulty ways with zero or a single node exist. A way can be open or closed. A closed way is one whose last node on the way is also the first on that way. A closed way may be interpreted either as a closed polyline, or an area, or both.
Node is defined as:
Nodes can be used to define standalone point features, but are more often used to define the shape or "path" of a way.
<node id="25496583" lat="51.5173639" lon="-0.140043" version="1" changeset="203496" user="80n" uid="1238" visible="true" timestamp="2007-01-28T11:40:26Z">
<tag k="highway" v="traffic_signals"/>
So if i first subset all ways from an osm object based on a key == highway and then use function find_down to find all the nodes connected to the ways:
find_down finds all elements downwards the hierarchy:
node -> node way -> way + node relation -> relation + way + node
highway_subset_v1 and highway_subset_v2 should at least produce the same amount of ways.
Yet the result is different.
library("osmar")
src <- osmsource_api(url = "https://api.openstreetmap.org/api/0.6/")
muc_bbox <- center_bbox(11.575278, 48.137222, 1000, 1000)
muc <- get_osm(muc_bbox, src)
highway_subset_v1 <- subset(muc, way_ids = find(muc, way(tags(k == "highway"))))
highway_subset_v1 <- find(highway_subset_v1, way(tags(k == "name")))
highway_subset_v1 <- find_down(muc, way(highway_subset_v1))
highway_subset_v1 <- subset(muc, ids = highway_subset_v1)
highway_subset_v1 osmar object 2678 nodes, 504 ways, 0 relations
In this approach i select all the nodes with k==higway and find_up all the ways that are connected to these nodes.
highway_ids_v2 <- find(muc, node(tags(k == "highway")))
highway_subset_ids_v2 <- osmar::find_up(muc, osmar::node(highway_ids_v2))
highway_subset_v2 <- subset(muc, ids = highway_subset_ids_v2)
highway_subset_v2 osmar object 136 nodes, 113 ways, 23 relations
find_up finds all elements upwards the hierarchy:
node -> node + way + relation way -> way + relation relation -> relation
Am i missing something?
Thank you very much in advance,
Best regards, Andreas
It seems to me that ...
highway=*
.highway=*
.Most nodes which are used to define the shape of a way tagged highway=*
will not themselves carry a highway=*
tag, and in fact many roads will not contain such a node at all. (Examples of nodes tagged highway=*
are crossings, stop signs, street lights, and a mixed bag of various other features.)
So these are really very different sets, and there's no reason to assume the result will be identical. In particular, find_down will give you all nodes of the ways you're passing in. It's not supposed to remember the key-based filter you applied to the ways and apply it to the nodes as well. (And vice versa for find_up in v2.)