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
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:
- Overwrite the
DefaultJoinFilter
- In
open()
load your Polygons and check them invalidate(way)
- 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()
- Dont forget to delegate to super.xxx() before doing special stuff.
- Modify the
osm2po.config
to point to your newly createdJoinFilter
. 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 Node
s 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: