1

I've written code in Java using the Osmosis framework and specifically OsmosisReader for Java, for OSM processing.

To do so I need to convert OSM's ways to edges between the way's source and destination.
for example, take this way:

  <way id='155117788' timestamp='2021-11-04T10:33:53Z' uid='1935374' user='alxm' visible='true' version='16' changeset='113364120'>
    <nd ref='985633394' />
    <nd ref='5329510726' />
    <nd ref='7203635659' />
    <nd ref='5329510348' />
    <nd ref='5329510364' />
    <nd ref='5329510331' />
    <nd ref='5329510322' />
    <nd ref='5329508418' />
    <nd ref='5329510351' />
    <nd ref='5329510360' />
    <nd ref='5329510663' />
    <nd ref='5329510698' />
    <nd ref='5329510730' />
    <nd ref='6453015430' />
    <nd ref='7264736136' />
    <nd ref='5329510752' />
    <nd ref='5329510751' />
    <nd ref='5329510674' />
    <nd ref='5329510688' />
    <nd ref='5329510408' />
    <nd ref='5329510709' />
    <nd ref='5329510414' />
    <nd ref='5329510382' />
    <nd ref='5329510384' />
    <nd ref='5329510795' />
    <nd ref='5329510794' />
    <nd ref='5329510656' />
    <nd ref='5329510358' />
    <nd ref='5329510359' />
    <nd ref='5329510653' />
    <nd ref='5329510381' />
    <nd ref='5329510654' />
    <nd ref='6819115285' />
    <nd ref='992691843' />
    <tag k='highway' v='secondary' />
    <tag k='name:en' v='Ron Nachman' />
    <tag k='name:etymology:wikidata' v='Q361323' />
    <tag k='oneway' v='yes' />
    <tag k='ref' v='4775' />
    <tag k='surface' v='asphalt' />
  </way>

how can I check which node is the source of the way and which is the destination?

enter image description here

Kfir Ettinger
  • 584
  • 4
  • 13
  • 2
    Source and destination? Do you mean start and end? The first referenced node is the start (985633394 in your example) and the last referenced node is the end (992691843). Although most ways don't really have a fixed start and end. Only oneway ways do. – scai May 10 '22 at 11:55
  • thanks! I can see it now. so the nodes of oneway ways are ordered from top (first) to button (last)? and what about two-way ways? does they have any order? north to south? west to east? or is it random where the start node is? – Kfir Ettinger May 10 '22 at 16:41
  • 1
    The order of the nodes of a oneway way depends on the `oneway` tag. For `oneway=yes` the order of the way is from the first to the last node. For `oneway=-1` it is from the last to the first node. See the [documentation of the oneway key](https://wiki.openstreetmap.org/wiki/Key:oneway) in the OSM wiki. For any other ways there is no predefined direction. It depends on how the way has been drawn by the OSM mapper. – scai May 11 '22 at 08:16

1 Answers1

1

All ways in the OpenStreetMap database have a direction. This is defined by the order of the referenced nodes: They are ordered from the start to the end of the way.

By itself, this direction has no meaning – it simply depends on where the mapper has started drawing. But certain tags on ways refer to the way's direction. If those tags appear on a way, you need to take the direction into account.

Examples for these tags appear in the documentation on the OSM wiki:

If you're creating edges for routing, you should also consider ...

  • ... that it's possible to leave a way at any node that are shared with other ways, not just at the first and last node. Therefore, there is no 1:1 relationship between OSM ways and edges in a routing graph.
  • ... that turn restrictions can prevent some turns at shared nodes.
  • ... that the possible travel directions depend on your mode of transport (for example, a road may be oneway for cars, but two-way for bicycles).
  • ... that other factors besides your mode of transport can affect direction of travel, such as the time of day for reversible oneways. However, this is something even many professional routing engines do not fully support.
Tordanik
  • 1,188
  • 11
  • 29