shapely 操作中的 grid_size 参数是做什么的?

问题描述 投票:0回答:1

在实际意义上,

grid_size
参数对你有什么作用?你什么时候/为什么要改变它的默认值?

我从测试中了解到,它对生成的几何图形的坐标进行了离散化,例如对于

grid_size=0.01
,坐标的小数部分将是
0.01
的倍数。这是否影响了算法的逻辑,或者只是为了方便最终用户无论如何都要离散化坐标的应用程序?

python shapely
1个回答
0
投票

我有时使用它的一个实际原因是为了避免在应用叠加层(在非拓扑数据中)后出现碎片。

下面的代码示例说明了这一点:

  • 没有 grid_size 的 2 个多边形之间的交集导致 一个窄多边形作为交叉点。
  • 具有 grid_size 的 2 个多边形之间的交集导致 行,很容易过滤掉。
import shapely
import shapely.plotting
import matplotlib.pyplot as plt

poly1 = shapely.Polygon([(0, 0), (0, 10), (10, 10), (5, 0), (0, 0)])
poly2 = shapely.Polygon([(5, 0), (8, 7), (10, 7), (10, 0), (5, 0)])

intersection_nogridsize = poly1.intersection(poly2)
intersection_gridsize = poly1.intersection(poly2, grid_size=1)

shapely.plotting.plot_polygon(poly1, color="green")
shapely.plotting.plot_polygon(poly2, color="blue")
shapely.plotting.plot_polygon(intersection_nogridsize, color="red")
plt.show()

shapely.plotting.plot_polygon(poly1, color="green")
shapely.plotting.plot_polygon(poly2, color="blue")
shapely.plotting.plot_line(intersection_gridsize, color="red")
plt.show()
  • result without gridsize
  • result with gridsize
© www.soinside.com 2019 - 2024. All rights reserved.