用Python获取和解析地图街道数据

发布于 2024-12-22 21:45:15 字数 383 浏览 1 评论 0原文

如何获得描述街道互连和估计驾驶时间的图表,并使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身情人 2024-12-29 21:45:15

OSMnx Python 包提供了一个方便的接口,用于将 OpenStreetMap 数据下载为多图或定向图图形。只需几行代码,您就可以下载并可视化某个区域或某个地址附近的步行、骑自行车和驾车网络。

这是一个最小的示例:

import osmnx as ox
import matplotlib.pyplot as plt

# Suppose we want to navigate while walking in Times Square, NYC
place_name = "Times Square, NYC, New York, USA"
graph = ox.graph_from_place(place_name, network_type='walk')

# Visualize the multi-graph using matplotlib (resulting image below)
fig, ax = ox.plot_graph(graph,
                        node_size=10,
                        node_color='blue',
                        edge_color='black',
                        edge_linewidth=1,
                        bgcolor='white')

# Optionally, simplify the multi-graph into a directed graph
directed_graph = ox.convert.to_digraph(graph)

根据 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:

import osmnx as ox
import matplotlib.pyplot as plt

# Suppose we want to navigate while walking in Times Square, NYC
place_name = "Times Square, NYC, New York, USA"
graph = ox.graph_from_place(place_name, network_type='walk')

# Visualize the multi-graph using matplotlib (resulting image below)
fig, ax = ox.plot_graph(graph,
                        node_size=10,
                        node_color='blue',
                        edge_color='black',
                        edge_linewidth=1,
                        bgcolor='white')

# Optionally, simplify the multi-graph into a directed graph
directed_graph = ox.convert.to_digraph(graph)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文