作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个 geopandas 数据框 dfMd
和 centers
。 dfMd
由多边形组成,而 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
的外部边界?
最佳答案
您需要在 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))
关于Python:如何将 Voronoi 单元扩展到几何的边界?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67236419/
我是一名优秀的程序员,十分优秀!