How to extract intersections in the OpenStreetMap? I need the longitude and latitude of the intersections, thanks!
There has been a similar question here. There is no direct API call to retrieve intersections. But you can query all ways in a given bounding box (for example directly via the API or via the Overpass API) and look for nodes shared by two or more ways as explained in the other answer.
Try the GeoNames findNearestIntersectionOSM
API:
http://api.geonames.org/findNearestIntersectionOSMJSON?lat=37.451&lng=-122.18&username=demo
The input is lng and lat of location and the response contains lng and lat of nearest intersection:
{"intersection":{...,"lng":"-122.1808293","lat":"37.4506505"}}
It is provided by GeoNames, but seems to be based on OpenStreetMap
As @scai perfectly explained, you have to process the raw OSM data yourself to find intersection nodes of ways.
Instead of writing your own program, you can try different algorithms first using the OverpassAPI.
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>