使用 OSMnx 的等时线

Isochrones with OSMnx

我有大量位置(纬度、经度)数据(10k 行),我想使用 OSMnx 计算从每个点开始的 10 分钟步行等时线。 (我尝试使用 openrouteservice 但有一些限制)。 我试过这个例子:https://github.com/gboeing/osmnx-examples/blob/v0.13.0/notebooks/13-isolines-isochrones.ipynb

import pandas as pd
import geopandas as gpd
from shapely.geometry import Point, Polygon
import networkx as nx
import osmnx as ox
ox.config(log_console=True, use_cache=True)

def get_isochrone(lon, lat, walk_time=10, speed=4.5):
    loc = (lat, lon)
    G = ox.graph_from_point(loc, simplify=True, network_type='walk')
    gdf_nodes = ox.graph_to_gdfs(G, edges=False)
    x, y = gdf_nodes['geometry'].unary_union.centroid.xy
    center_node = ox.get_nearest_node(G, (y[0], x[0]))
    meters_per_minute = speed * 1000 / 60 #km per hour to m per minute
    for u, v, k, data in G.edges(data=True, keys=True):
        data['time'] = data['length'] / meters_per_minute
    subgraph = nx.ego_graph(G, center_node, radius=walk_time, distance='time')
    node_points = [Point(data['x'], data['y']) for node, data in subgraph.nodes(data=True)]
    polys = gpd.GeoSeries(node_points).unary_union.convex_hull
    return polys

然后应用到我的大规模 pandas DataFrame:

df.apply(lambda x: get_isochrone(x.lon, x.lat), axis=1)

但是花了那么多时间。 100 行大约需要 3 分钟 运行 时间。有没有其他方法,包来实现这个目标?用合理的 运行 时间 ?

最后一个问题,OSMnx 请求的限制是什么,特别是对于大数据? 谢谢

这本来就是一个缓慢的过程。如果您有 10,000 个位置,并且它们彼此相距很远,那么您需要下载 10,000 个本地街道网络并为其建模,以计算每个点周围的可达性。这意味着 10,000 次服务器调用和数据下载以及图形构建和拓扑清理等。

因此,在 3 分钟内完成 100 行对我来说似乎相当快,特别是考虑到这意味着您可以在大约 300 分钟(即 5 小时)内完成所有 10,000 行(给定您的估计时间)。就在你睡觉前开始这个过程,当你醒来时它就会完成。这假设这是一次性计算,不需要经常重新计算。

另一种选择是通过将其分成 10 个容器或进程来并行化,每个容器或进程处理 1,000 个位置。根据您的估计时间,这将在大约 30 分钟内完成。

Last question, what are the limitations of OSMnx request, especially for large data ?

使用 OSMnx 处理大量网络模型的限制是您计算机上的 RAM 容量。