0

Is it possible to avoid certain areas using osm2po? For example I would like to avoid central London. I can't see anyway to put this as a constraint in Java.

1 Answer 1

1

There is no "user friendly" way for doing such things. However, Java skills open the door and it is not difficult. First you need the polygons of your restricted areas. Ok, I assume they are in place already. osm2po offers many ways to solve such problems. I'll start with the most common approach:

  1. Overwrite the DefaultJoinFilter
  2. In open() load your Polygons and check them in validate(way)
  3. Manipulate the way if it intersects your polygon. e.g. by setting a lower speed or just setting a flag for later or even much more details in setCustom()
  4. Dont forget to delegate to super.xxx() before doing special stuff.
  5. Modify the osm2po.config to point to your newly created JoinFilter. e.g. joinFilter.class=com.to.my.package.MyJoinFilter

Depending on where you have modified defaults, e.g. speed, things should be different after the next conversion. Using modified flags or a modified clazz (both are attributes of the Way) gives you access at runtime and the ability of toggling it on and off. But therefore you'll need an overwritten DefaultRouter or one of its relatives as well.

BTW. You can also modify the Nodes here, but things become more complicated then.

For the polygon-part you can either use external libs or one of the built in classes and funtions such as OsmPolygon which has a simple contains() method or for more complex things the GeoUtils - a static helper class with functions like intersection(), computeGreatCircleLineFraction() and the like.

And there is more. But I'd like to stop my monologue for now and give you a visual example showing sth. similar but more complex - here: multimodal routing with different penalties and many areas:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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