1

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

Waldi
  • 39,242
  • 6
  • 30
  • 78
Andreas
  • 397
  • 4
  • 18
  • 37
  • I get an error `error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version` when using `get_osm`, possibly since migration to R 4.0. Latest update from osmar was feb 2015, perhaps not anymore up to date. – Waldi Aug 19 '20 at 20:58
  • hmm..strange, i use R 4.0 also and it works for me exactly as i noted it in the question. – Andreas Aug 19 '20 at 23:16
  • It seems there is some problem with ssl on your system. get_osm does not do anything special with ssl that could go wrong .. i think – Andreas Aug 20 '20 at 08:30

1 Answers1

1

It seems to me that ...

  • v1 will find ways tagged highway=*.
  • v2 will find ways that contain a node tagged 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.)

Tordanik
  • 1,188
  • 11
  • 29
  • Thank you very much for your reply Tordanik. The question remains whether it makes any difference for finding a path for a car. I would prefer to work on a smaller dataset and I assume roads made for cars have at least one node with a tag highway. So in a sense it could be a filter.. not a bug :) since i assume that at least one crossing or sign is on a road? You say most ways will not have a node with a tag highway? – Andreas Aug 20 '20 at 18:38
  • 1
    It will make a difference. Even roads made for cars will often not have nodes tagged as highway. This can happen for many reasons: Because things like pedestrian crossings aren't mapped (common for smaller roads where there's no marked crossing, or simply where the map isn't complete yet), because they are split into multiple ways (ways are split every time even one attribute changes, even if it's just a change in the road surface or width), or because objects are mapped next to the way rather than as part of it (street lamps, for example, are placed next to the road way). – Tordanik Aug 20 '20 at 19:59
  • 1
    Random example of a road way with 6 nodes, none of which have any tags at all: https://osm.org/way/38332817 If you want to limit your results to highway ways suitable for cars, you'll want to look at the value of highway tags (e.g. path or footway would not be interesting to you, but motorway, primary, residential, ...) would be. – Tordanik Aug 20 '20 at 19:59
  • I already test only toads that are available for a car. So no pedestrian. I run a test and at least on the section i tested there was no difference in routing behaviour between those 2 approaches. Only difference is : if i use a "correct " approach by selecting ways and then finding down all the nodes, path finding is slower since more data. Otherwise no difference in route creation. – Andreas Aug 21 '20 at 07:41
  • Is there a 100% safe approach (A key for example) to identify a node whether it's a node that describes a way? – Andreas Aug 21 '20 at 07:50
  • Sorry, I'm not sure if I understand the question in your most recent comment. Are you asking if it's possible to find nodes which are part of a way? (As opposed to stand-alone nodes?) – Tordanik Aug 21 '20 at 11:22
  • Sorry ill try to explain: you suggested that a lot of nodes that describe a way does not have a tag == higway. And find_down or up from a way will give me all the nodes in proximity of a way. That means streetsigns and so on. How could i filter out just the nodes that describe a way? One approach is to use tag name. But a lot of ways does not have names. So im looking in possibility to reduce the ammount of nodes. – Andreas Aug 21 '20 at 11:26
  • Are you asking if it's possible to find nodes which are part of a way? (As opposed to stand-alone nodes?) -> yes :) – Andreas Aug 21 '20 at 11:28
  • I believe find_down will only find nodes that are directly part of the way, not those in proximity to it. So using it should produce exactly that: The nodes which are part of a way. (If you want nodes that are part of _any_ way, rather than just those from your set, you could presumably drop the highway condition.) – Tordanik Aug 23 '20 at 21:07
  • It's possible that you don't need (all) the nodes for your further processing steps, depending on how you construct that graph. And of course, there's the option of manually implementing any filter logic you need. (But I'm hitting the limits of my knowledge here (I know about OSM, but not much about routing in R). :/ – Tordanik Aug 23 '20 at 21:07