1

I am trying to create a complex routable graph with osm2po. For this I need to extract relations (restrictions for example) and attach them to my graph. Does anyone know what I need to override/extend in the osm2po java API?

  • For a pgRouting graph? – Carsten Apr 3 '15 at 18:07
  • Nope... I eventually need to get it into my own data structures. But if it initially ends up in the database, this is fine. Basically I need to parse the relations and describe them in terms of the edges/vertices of the routable graph, not in terms of OSM nodes and OSM ways. – Iulian Apr 3 '15 at 23:11
1

Surprisingly osm2po improved a lot between v4.8.8 and 5.0.0 with regards to the relations. Now I use a more common approach. Nevertheless OSM-Relations are a beast. They are totally over-defined, sometimes ambigues and very hard to interpret. osm2po is way centric and in the joining phase relations are added to ways not vice versa. Additionally relations must be filtered in order to meet one special purpose. It doesnt make sense to transport Boundaries e.g. thru the conversion phases if you want to build a road network. Therefore I use relation filters which are hard coded. By default rtr.supportRestrictions is enabled, meaning, everything but restrictions will be ignored. Multi-Restrictions (which is a quite new nuisance in osm) and FromWay-ViaWay-ToWay variants are not NOT supported in the current version. Well, you asked how to retrieve them programmatically: There are two join points in osm2po: Firstly there ist the parser itself. If you need the raw input overwrite or implement another RelationTagResolver. If you want to get closer to the final result, hook into the DefaultJoinFilter. Both are described in the osm2po.config. Following osm2po's concept of assigning clazzes to entities, you'll also notice them here. Currently they are coded as:

public final static byte CLAZZ_MASK = (byte) 0xF0; // (1111xxxx)

public final static byte CLAZZ_RESTRICTION = (byte) 0x80; //-128 (1000xxxx)
public final static byte CLAZZ_ROUTE = (byte) 0x90; //-112 (1001xxxx)
public final static byte CLAZZ_BOUNDARY = (byte) 0xC0; //-64 (1100xxxx)
public final static byte CLAZZ_POLYGON = (byte) 0xD0; //-48 (1101xxxx)

public final static byte CLAZZ_RESTRICTION_NO_LEFT_TURN = CLAZZ_RESTRICTION | 0x1; // -127
public final static byte CLAZZ_RESTRICTION_ONLY_LEFT_TURN = CLAZZ_RESTRICTION | 0x2; // -126
public final static byte CLAZZ_RESTRICTION_NO_RIGHT_TURN = CLAZZ_RESTRICTION | 0x3; // -125
public final static byte CLAZZ_RESTRICTION_ONLY_RIGHT_TURN = CLAZZ_RESTRICTION | 0x4; // -124
public final static byte CLAZZ_RESTRICTION_NO_STRAIGHT_ON = CLAZZ_RESTRICTION | 0x5; // -123
public final static byte CLAZZ_RESTRICTION_ONLY_STRAIGHT_ON = CLAZZ_RESTRICTION | 0x6; // -122
public final static byte CLAZZ_RESTRICTION_NO_U_TURN = CLAZZ_RESTRICTION | 0x7; // -121
public final static byte CLAZZ_RESTRICTION_NO_ENTRY = CLAZZ_RESTRICTION | 0x9; // -119
public final static byte CLAZZ_RESTRICTION_NO_EXIT = CLAZZ_RESTRICTION | 0xB; // -117

public final static byte CLAZZ_ROUTE_ROAD = CLAZZ_ROUTE | 0x1; // -111
public final static byte CLAZZ_ROUTE_HIKING = CLAZZ_ROUTE | 0x2; // -110

...

and the members:

public final static byte MEMBER_TYPE_UNKNOWN = 0;
public final static byte MEMBER_TYPE_NODE = 1; 
public final static byte MEMBER_TYPE_WAY = 2;
public final static byte MEMBER_TYPE_RELATION = 3;

public final static byte MEMBER_ROLE_UNKNOWN = 0;
public final static byte MEMBER_ROLE_FROM = 1;
public final static byte MEMBER_ROLE_TO = 2;
public final static byte MEMBER_ROLE_VIA = 3;
public final static byte MEMBER_ROLE_FORWARD = 4;
public final static byte MEMBER_ROLE_BACKWARD = 5;
public final static byte MEMBER_ROLE_OUTER = 6;
public final static byte MEMBER_ROLE_INNER = 7;

A debug session inside the JoinFilter produces a picture like this:

Debuggin Way inside DefaultJoinFilter

Here, relation[0] (id 1698785) adds MEMBER_ROLE_TO and CLAZZ_RESTRICTION_NO_U_TURN to the current way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.