在实际意义上,
grid_size
参数对你有什么作用?你什么时候/为什么要改变它的默认值?
我从测试中了解到,它对生成的几何图形的坐标进行了离散化,例如对于
grid_size=0.01
,坐标的小数部分将是0.01
的倍数。这是否影响了算法的逻辑,或者只是为了方便最终用户无论如何都要离散化坐标的应用程序?
我有时使用它的一个实际原因是为了避免在应用叠加层(在非拓扑数据中)后出现碎片。
下面的代码示例说明了这一点:
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()