用Python获取和解析地图街道数据
如何获得描述街道互连和估计驾驶时间的图表,并使用 Python 对其进行解析?
作为练习,我尝试实现一个基本的 A* 规划器来绘制地图上两点之间导航的路线(即 TomTom、Garmin、Google Nav 等)。我可以模拟一些数据,但如果可能的话我想使用真实的地图数据。
我知道 开放街道地图,虽然它们允许将地图的一小部分导出到 OSM XML 数据中,我无法找到可以轻松解析我可以使用的表单的工具。我发现了 imposm,但没有太多其他的。谁能推荐其他工具吗?
How would you obtain a graph describing street interconnections and estimated driving times, and parse it using Python?
As an exercise, I'm trying to implement a basic A* planner to plot a route for navigating between two points on a map (i.e. TomTom, Garmin, Google Nav, etc). I could mock up some data, but I'd like to use real map data if possible.
I'm aware of Open Street Map, and while they allow exporting of small slices of their map into OSM XML data, I'm having trouble finding tools to easily parse this a form I can use. I've found imposm, but not much else. Can anyone recommend any other tools?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OSMnx Python 包提供了一个方便的接口,用于将 OpenStreetMap 数据下载为多图或定向图图形。只需几行代码,您就可以下载并可视化某个区域或某个地址附近的步行、骑自行车和驾车网络。
这是一个最小的示例:
根据 OpenStreetMap 数据绘制时代广场的步行路线
然后您可以直接使用图开发 A* 规划器,或将图包装在 StateSpaceSearch 抽象类中,以便您的 A* 实现保持与问题无关的状态。要查找边成本,请考虑为每条边定义的字典中的
“length”
键。最后,作为规划器的潜在比较点,OSMnx 提供 Yen 的 和 Dijkstra 的 算法。The OSMnx Python package provides a convenient interface for downloading OpenStreetMap data as a multi-graph or directed graph. In a few lines, you can download and visualize the walking, biking, and driving networks in an area or near an address.
Here's a minimal example:
Plot of the walking routes in Times Square based on OpenStreetMap data
You could then develop an A* planner using the graph directly, or wrap the graph in a
StateSpaceSearch
abstract class so that your A* implementation remains problem-agnostic. To find edge costs, consider the"length"
key in the dictionary defined for each edge. Finally, as a potential comparison point for your planner, OSMnx provides built-in implementations of Yen’s and Dijkstra’s algorithms.