3

I'm currently looking at using osm2po's java library to build a simple application that builds a shortest path between my favorite bars :)

However, I'd like to start at any location, not at an intersection.

I saw a response that's it's theoretically possible (http://www.rqna.net/qna/nwkrrs-can-i-start-and-end-an-osm2po-route-in-the-middle-of-a-road-segment.html), but not really sure how to do this with the latest java API.

Is this functionality exposed? I've seen findClosestVerexId(lat, lon), but what I really want is something like findEdge(lat, lon), and then a way to get source and target from the edge.

Thanks!

3

Yes. osm2po provides two Router-Families. The DefaultRouter belongs to the first one, which is only able to route from link to link (Vertex-IDs). All Routers with an "Ovl" in their names are not restricted to it. They all base on a second virtual OverlayGraph which extends the static network.

  1. In order to find a virtual point (source and target) on the static graph use TouchPoint.create(Graph graph, float lat, float lon)
  2. Instantiate OverlayGraph(Graph graph)
  3. Register the virtual TouchPoints here overlayGraph.insertTouchPoints(TouchPoint... touchPoints)
  4. Each registered TouchPoint gets a unique Id by the OverlayGraph touchPoint.getId()
  5. Use these Ids to call Section[] ovlRouter.findPath(OverlayGraph overlayGraph, int sourceId, int targetId, float maxCost, Properties params).
  6. The Array of Section[] is your result. A Section encapsulates all infos you need, such as original EdgeIdx (for retrieving streetname and geometry from the static Graph), modified geometries, if present (mostly at source and target) by calling section.getGeometry() and more.

The basic idea behind this approach is to share big data between instances (static Graph) and at the same time being able to route on dynamic data (OverlayGraph) in an isolated instance.

6
  • Thanks, that will do it for me. I will either write a custom router or just go from point to point now that I can get the first edge I'm on. One additional question - are methods in Graph thread-safe, by any chance?
    – kozyr
    Oct 12 '13 at 20:21
  • I've emulated 100 users (Threads) requesting the osm2po-SOAP-Service. Yes it should be safe, if it's not, please report it as bug.
    – Carsten
    Oct 12 '13 at 22:39
  • How did this change with version 5.0? There's no more TouchPoint class...
    – kozyr
    Feb 23 '15 at 5:55
  • Please open a new thread, so I can give an official answer instead of a hidden comment.
    – Carsten
    Feb 24 '15 at 18:31
  • 1
    Ok. Here is quick diff: first call OverlayNode tp = new OverlayNode(lat, lon); and then tp.snap(graph, null)). This replaces TouchPoint.create(...) . Finally insert the snapped point into the graph with overlayGraph.insertNode(tp); which returns an id you can pass to the router.
    – Carsten
    Feb 24 '15 at 18:42

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.