拥有GeoSeries
大约 100000 个位置,我有一个工作代码,用于计算Polygons
以每个位置为中心的步行可达性。
该代码对networkx
从OpenStreeMaps
via osmnx
by apply
to 获得的图进行计算GeoDataFrame
。
我正在尝试加快计算速度,因为这非常慢。
G
- 是一个networkx
图表
# create graph walking_time edge property
walking_speed = 4.5 #km/h
walking_speed_m_minute = walking_speed * 1000 / 60 #km/h to m/min
for u, v, k, data in G.edges(data=True, keys=True):
data['walking_time'] = data['length'] / walking_speed_m_minute
这是我的apply
功能GeoDataFrame
:
def calculate_time_accessibility_polygon(row, trip_time):
# location x,y
y = row['latitude']
x = row['longitude']
# find nearest node on the graph
center_node = ox.get_nearest_node(G, (y, x))
subgraph = nx.ego_graph(G, center_node, radius=trip_time,
distance='time')
node_points = [Point((data['x'], data['y'])) for node, data in
subgraph.nodes(data=True)]
bounding_poly = gpd.GeoSeries(node_points).unary_union.convex_hull
return(bounding_poly)
我使用以下代码行申请:
gdf.apply(calculate_time_accessibility_polygon, args=(15,), axis=1))
谢谢!!!