获取主要城市所有十字路口列表的最佳来源和方法是什么?
2 回答
If one doesn't mind a few false positives the following Overpass API script gets road intersections out of OpenStreetMap data pretty easily:
(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>
您可以使用 OpenStreetMap 数据来完成。
下载城市的数据(使用导出链接:http ://www.openstreetmap.org/export或从此处获取数据:http: //metro.teczno.com/;还有其他来源,但这不是列出它们的地方)。
为“highway”标签 ( http://wiki.openstreetmap.org/wiki/Key:highway )找到所有具有适当值的元素。
对于每一种这样的方式,获取组成它的节点 ID。
创建一个数组,其中包含由高速公路信息(名称等)和一个节点组成的条目,每个节点一个节点。
根据节点 ID 对数组进行排序。这按节点对条目进行分组,因此具有重复节点的一组条目表示一个交集。
遍历数组,提取其中包含多个条目的每组条目,并将新条目添加到交叉点列表中。此时,您可以提取高速公路信息,以便可以通过在该处相遇的高速公路来表征交叉口。
这是一个简短的总结,我知道。但我知道它有效,因为它是我在地图渲染库中用于在创建路线数据时识别交叉点的系统。