1

The project graphhopper (Open Source Routing for OpenStreetMap) imports specific railway elements to be later used in the road network graph.

In File CarFlagEncoder.java some specific railway types, which are stored in acceptedRailways, are allowed to be added to the graph:

   // do not drive cars over railways (sometimes incorrectly mapped!)
   if (way.hasTag("railway") && !way.hasTag("railway", acceptedRailways))
        return 0;

The acceptedRailways are defined in AbstractFlagEncoder:

    acceptedRailways.add("tram");
    acceptedRailways.add("abandoned");
    acceptedRailways.add("abandoned_tram");
    acceptedRailways.add("disused");

    acceptedRailways.add("dismantled");
    acceptedRailways.add("razed");
    acceptedRailways.add("historic");
    acceptedRailways.add("obliterated");

While I can understnad why "tram" is used (cars and trams sometimes share a road, so cars can drive on it), I do not understand the other railway types.

Why are they needed? Who want to route via an historic non existing railway? as seen here http://wiki.openstreetmap.org/wiki/Demolished_Railway

AlexWien
  • 28,470
  • 6
  • 53
  • 83

2 Answers2

1

I'm not familiar with the exact project, and I think I can answer your specific question from design/code review perspective.

Why are they needed? Who want to route via an historic non existing railway?

I think we need to focus on the source of the routes.

The graphhopper project ex-ante uses all routes in the OpenStreetMap data-source. This project appears to contain all types of routes. That means that ex-ante all routes are valid; highway / ferry / railroad.

It is then parsed down when building the map. You can see this in the function, acceptWay, you mentioned. Here various tags are required or restricted.

Note the first few lines: We have already required the highway tag. (Or handled the other cases).

String highwayValue = way.getTag("highway");
if (highwayValue == null)
{
      if (way.hasTag("route", ferries))
      {
           String motorcarTag = way.getTag("motorcar");
           if (motorcarTag == null)
               motorcarTag = way.getTag("motor_vehicle");

           if (motorcarTag == null && !way.hasTag("foot") && !way.hasTag("bicycle") || "yes".equals(motorcarTag))
               return acceptBit | ferryBit;
       }
       return 0;
 }

Once we pass the main highway tag check, other checks are performed. The railway check is one of those checks.


Now: Why would we want to allow those other sub-types of railways?

Because, those types of railways might be currently passable.

acceptedRailways.add("tram");
acceptedRailways.add("abandoned");
acceptedRailways.add("abandoned_tram");
acceptedRailways.add("disused");

acceptedRailways.add("dismantled");
acceptedRailways.add("razed");
acceptedRailways.add("historic");
acceptedRailways.add("obliterated");

Further Support: Apart from tram, all those words connote some form of current non-existence.

Sometimes, the map/route will contain old markings. So, my educated guess would be that the designers of the program, made a tradeoff.

If an acceptedRailways is a highway and meets all the criteria of a valid highway, then allow it. Else, it will fail like any other.

(It can also be looked at as a loosening on the restrictions of the no railway tag check; where the designers were not willing to take the risk allowing a route with the railway tag, that does not have a special, non-existent like, tag. Even though it may have highway tag!)

SH-
  • 1,642
  • 10
  • 13
1

This was introduced due to strange tagging in OSM and lead to railways used for cars, which was not acceptable.

Now with our 'OSM market power' we are thinking to completely remove this workaround and fix the data instead. That is not only the better approach but also causes the current behaviour trouble at other places, see here for the more detailed discussion.

Karussell
  • 17,085
  • 16
  • 97
  • 197
  • "lead to railways used for cars". Does it mean: Graphhopper used railways for car routing, because non car-useable railways roads had an highway tag listed in the speedLimits defined road types? And that the fix was to block all railways except that listed in the railway exceptions (tram, abandonded, historical). In the link in the discussion the problem was that a legal route was not found, due legal highways had an addional railway tag (which at that time probably lead to an ignore of that way - so the railway exceptions have been introduced) ? – AlexWien Feb 11 '16 at 15:11
  • GraphHopper just uses the highway types it should, but there were wrongly mapped cases where railways included highway=primary and so we tried to workaround these via excluding certain railways even though they were tagged highway=primary. Again, we will in the near future remove this special railway handling for motor vehicles entirely. – Karussell Feb 11 '16 at 19:34
  • 1
    Thanks, it is clear now. My question was not a critic to the src code, I just wanted to understand how the import of OpenStreetMap Data works. – AlexWien Feb 11 '16 at 21:11