在 osmnx 图上生成随机点

Generate random points on osmnx graph

我使用 osmnx 库创建了道路网络图。现在我想在网络上生成一些随机点,但我不知道该怎么做。需要一些帮助 :( 这是我的代码:

import geopandas as gpd
import osmnx  as ox
top=  gpd.GeoDataFrame(columns = ['name', 'geometry'], crs = 4326, geometry = 'geometry')
top.at[0, 'geometry'] = Point(100.40823730180041,14.207021554191956)
top.at[0, 'name'] = 'tl'
top.at[1, 'geometry'] = Point(100.74774714891429, 14.196946042603166)
top.at[1, 'name'] = 'tr'
bottom=  gpd.GeoDataFrame(columns = ['name', 'geometry'], crs = 4326, geometry = 'geometry')
bottom.at[0, 'geometry'] = Point(100.38860578002853,13.612931284522707)
bottom.at[0, 'name'] = 'bl'
bottom.at[1, 'geometry'] = Point(100.7131032869639, 13.581503263247015)
bottom.at[1, 'name'] = 'br'
combined = top.append(bottom)
convex = combined.unary_union.convex_hull
graph_extent = convex.buffer(0.02)
graph = ox.graph_from_polygon(graph_extent, network_type = "drive")

以下是我的操作步骤:

  1. 我创建了两个地理数据框 top 和 bottom top 定义了我的道路网络的范围
  2. 然后我将它们组合起来并使用 ox.graph_from_polygon 创建了一个道路网络。
  3. 我的路网看起来像这样 roadNetwork
  4. 现在我想生成一些随机点,这些点应该在创建的网络的 links/edges 上。

sample_points 函数正是这样做的。请参阅 OSMnx 使用示例和文档了解用法:https://osmnx.readthedocs.io/en/stable/osmnx.html#osmnx.utils_geo.sample_points