0

My goal is to get a list of all optional routes in certain area. I want to use OSM for achieving this data Route means pair or intersections that it's possible to drive from the first intersection to the second.

In the case at the image: RouteExample: The optional routes are:

  • 1-2 , 1-4
  • 2-1 , 2-3 , 2-5
  • 3-2 , 3-6
  • 4-1 , 4-5
  • 5-4 , 5-2 , 5-6
  • 6-5 , 6-3

So far I have tried this code in overpass-turbo site:

[bbox:{{bbox}}];
way[highway~"^(residential)$"]->.minor;
node(w.minor)(w.minor);
out;

The output is the intersections, but:

  1. List doesn't contain all the intersections
  2. I need the routes = connection of pairs of intersections
erez
  • 399
  • 1
  • 6
  • 17
  • 1
    What have you tried so far? Where are you stuck? – scai Oct 22 '18 at 11:14
  • That's way too much work and code to put into a StackOverflow answer. It's doable of course, but takes some time and coffee or other beverage. – Markus Kauppinen Oct 22 '18 at 11:19
  • I understand, even not the code but the way to do that? – erez Oct 22 '18 at 11:23
  • @MarkusKauppinen, any idea how to progress? – erez Oct 22 '18 at 12:36
  • I haven't used the Overpass API, but some time ago got OSM data as GeoJSON from Mapzen (which closed down) and parsed the street sections from it to my own data model and identified intersections based on shared coordinate points between them. My goal was to describe the user's surroundings as in what kind of and intersection is ahead and what streets branch from it and into what relative directions. – Markus Kauppinen Oct 22 '18 at 18:09
  • I didn't do exactly what you are attempting, but once you have the streets and the intersections, you can start following a street's sections (probably with some recursive code) and see if they lead to any of the intersections. Multi-lane streets that are drawn with several lines will add some complexity as e.g. two streets with two street lines will of course have four intersections, so I had a concept of a "grouped intersection". So, things may get a bit complicated. What I wrote is closed-source proprietary code, so there's nothing to share. – Markus Kauppinen Oct 22 '18 at 18:09
  • Thanks @MarkusKauppinen. This is the way I'm trying now. if anyone have also another advice please add it here – erez Oct 23 '18 at 06:00
  • There might be some brilliant minds at [Geographic Information Systems Stack Exchange](https://gis.stackexchange.com/) dealing with these kinds of things daily. – Markus Kauppinen Oct 23 '18 at 08:03

1 Answers1

1

If you're comfortable using Java, consider taking a look at Atlas. Atlas is an in memory representation of OSM data that will allow you to create a graph representing the street network. There is an Atlas API layer for connectivity, routing and spatial searches. For your specific need - there is the concept of a Route - which maintains the OSM Ways and Nodes specifying a path between two Nodes or Ways. There are ways to get the most optimal Route or obtain all possible Routes.

To get started, I recommend the following:

  1. Set up and familiarize yourself with the Atlas project
  2. Extract an OSM or PBF file with the area of interest
  3. Create an Atlas file from the PBF, run applicable routing algorithm

Sample code to load an OSM file:

public class TestAtlasTestRule extends CoreTestRule 
{
    @TestAtlas(loadFromJosmOsmResource = "yourOsmFile.osm")
    private Atlas yourAtlasFile;

    public Atlas getAtlasFile()
    {
        return this.yourAtlasFile;
    }
}

Sample code to obtain routes:

// To get the shortest route
final Route shortestRoute = AStarRouter.dijkstra(yourAtlasFile, distanceThreshold).route(startNode, endNode);

// To get all the routes
final Set<Route> allRoutes = AllPathsRouter.allRoutes(startEdge, endEdge, comparatorThatEnforcesRouteOrdering);