osm2po’s “flag” field explained

Posted March 4th, 2016 by Nate Wessel

I don’t do many technical posts here, but this one took me a while to figure out, so I thought I’d just quickly upload my knowledge into the world’s search indexes for all those helpless people out there trying to decypher osm2po‘s config file.

The ‘flag‘ field that osm2po creates in your SQL file is used to indicate the modes of travel that are permissible on an edge. First, you must tell the program what modes you want to consider:

wtr.flagList = car, bike, foot

These modes, in this order, determine the value that will be assigned to an edge’s ‘flag’. In this case, we get car=1, bike=2, foot=4. Note that these are decimal representations of the digits of a binary number! You get up to 5 digits or 32 possible flags because this is a 32bit field.

A value of 1 (given the ordering above) means that only cars can use the edge. A value of 2 means that only bikes can.

The flag field represents the digits of a binary number where each digit is one of five possible modes, which are determined by the ordering given in wtr.flaglist. You can then determine whether some mode can use an edge by a little modular division.

Modal access is the business of much of the rest of the config file and I won’t get into that here.

Happy routing!

Time limit is exhausted. Please reload CAPTCHA.