我有GeoSeries
大约100000个位置,我有一个工作代码,可以计算每个位置为中心的Polygons
的步行可达性。
代码对networkx
图进行计算,该图是从OpenStreeMaps
通过osmnx
到apply
从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))
谢谢!