【问题标题】:Python: how to extend Voronoi cells to the boundary of the geometry?Python:如何将 Voronoi 单元扩展到几何边界?
【发布时间】:2021-04-23 20:23:05
【问题描述】:

我有两个 geopandas 数据框 dfMdcentersdfMd 由多边形组成,而centers 由点组成。 Here 文件链接。

f,ax=plt.subplots()
dfMd.plot(ax=ax, column='volume')
centers.plot(ax=ax, color='red')

我想生成扩展到整个几何图形的点的Voronoi 缨子。这就是我正在做的事情:

from shapely.geometry import mapping
g = [i for i in centers.geometry]
coords = []
for i in range(0, len(g)):
    coords.append(mapping(g[i])["coordinates"]) # for first feature/row

from libpysal.cg.voronoi  import voronoi, voronoi_frames

regions, vertices = voronoi(coords)
region_df, point_df = voronoi_frames(coords)


fig, ax = plt.subplots()
region_df.plot(ax=ax, color='white',edgecolor='black', lw=3)
dfMd.plot(ax=ax, column='volume',alpha=0.1)
point_df.plot(ax=ax, color='red')

fig, ax = plt.subplots()
region_df.plot(ax=ax, color='white',edgecolor='black', lw=3)
dfMd.plot(ax=ax, column='volume',alpha=0.1)
point_df.plot(ax=ax, color='red')

如何将Voronoi 区域扩展到我的dfMd 的外部边界?

【问题讨论】:

    标签: python geopandas voronoi


    【解决方案1】:

    您需要voronoi_frames() 中的选项clip=box()。相关代码如下。

    from shapely.geometry import box
    
    region_df, point_df = voronoi_frames(coords, clip=box(-4.2, 40.15, -3.0, 40.85))
    

    【讨论】:

      猜你喜欢
      • 2016-04-30
      • 1970-01-01
      • 2021-12-22
      • 2015-04-24
      • 2015-09-13
      • 1970-01-01
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多