Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of all intersections in a city

What is the best source and way to get a list of all intersections in a major city?

like image 670
ChrisAU Avatar asked Oct 18 '12 23:10

ChrisAU


2 Answers

If one doesn't mind a few false positives the following Overpass API script gets road intersections out of OpenStreetMap data pretty easily:

http://overpass-turbo.eu/s/QD

(the script can't detect false intersections – where only two lines meet, though, e.g. when a road is represented by multiple way objects in the OSM data)

In case that the script goes offline a more readable version directly here:

  • Dependent on which kind of ways you are interested in, add the types of ways which should not count as intersection to the regv attribute (at two script sections). The type of ways can be found here: highway tags.
  • The BoundingBox is the part of the map you are viewing on the Overpass-tourbo Website.

Sample Script:

<!-- Only select the type of ways you are interested in -->
<query type="way" into="relevant_ways">
  <has-kv k="highway"/>
  <has-kv k="highway" modv="not" regv="footway|cycleway|path|service|track"/>
  <bbox-query {{bbox}}/>
</query>

<!-- Now find all intersection nodes for each way independently -->
<foreach from="relevant_ways" into="this_way">  

  <!-- Get all ways which are linked to this way -->
  <recurse from="this_way" type="way-node" into="this_ways_nodes"/>
  <recurse from="this_ways_nodes" type="node-way" into="linked_ways"/>
  <!-- Again, only select the ways you are interested in, see beginning -->
  <query type="way" into="linked_ways">
    <item set="linked_ways"/>
    <has-kv k="highway"/>
    <has-kv k="highway" modv="not" regv="footway|cycleway|path|service|track"/>
  </query>

  <!-- Get all linked ways without the current way --> 
  <difference into="linked_ways_only">
    <item set="linked_ways"/>
    <item set="this_way"/>
  </difference>
  <recurse from="linked_ways_only" type="way-node" into="linked_ways_only_nodes"/>

  <!-- Return all intersection nodes -->
  <query type="node">
    <item set="linked_ways_only_nodes"/>
    <item set="this_ways_nodes"/>
  </query>
  <print/>
</foreach>
like image 130
tyr Avatar answered Nov 08 '22 05:11

tyr


You can do it using OpenStreetMap data.

  1. Download the data for the city (use the export link: http://www.openstreetmap.org/export or get the data from here: http://metro.teczno.com/; there are other sources but this isn't the place to list them).

  2. Find all the elements with appropriate values for the 'highway' tag (http://wiki.openstreetmap.org/wiki/Key:highway).

  3. For each such way, get the node IDs that make it up.

  4. Create an array containing entries consisting of the highway information (name, etc.) and a node, one for every node.

  5. Sort the array on node IDs. That groups entries by the node, so that a set of entries with duplicate nodes represents an intersection.

  6. Traverse the array, extracting each group of entries with more than one entry in it and adding a new entry to your list of intersections. At this point you can extract the highway information so that an intersection can be characterised by the highways which meet there.

This is a short summary, I know. But I know it works, because it is the system I use in my map rendering library to identify intersections when creating routing data.

like image 27
Graham Asher Avatar answered Nov 08 '22 03:11

Graham Asher