【发布时间】:2021-10-03 23:20:41
【问题描述】:
我想将一个复杂的几何体划分为同一区域的n 子几何体。
例如,如果我有一个矩形,我可以这样做
from shapely.geometry import LineString, MultiPolygon, Polygon
from shapely.ops import split
def splitPolygon(polygon, nx, ny):
minx, miny, maxx, maxy = polygon.bounds
dx = (maxx - minx) / nx
dy = (maxy - miny) / ny
minx, miny, maxx, maxy = polygon.bounds
dx = (maxx - minx) / nx # width of a small part
dy = (maxy - miny) / ny # height of a small part
horizontal_splitters = [LineString([(minx, miny + i*dy), (maxx, miny + i*dy)]) for i in range(ny)]
vertical_splitters = [LineString([(minx + i*dx, miny), (minx + i*dx, maxy)]) for i in range(nx)]
splitters = horizontal_splitters + vertical_splitters
result = polygon
for splitter in splitters:
result = MultiPolygon(split(result, splitter))
return result
myPolygons = splitPolygon(polygon, 5, 5)
import geopandas as gpd
gdfR = gpd.GeoDataFrame(columns=['geometry'], data=myPolygons.geoms)
f,ax=plt.subplots()
gdfR.boundary.plot(ax=ax, color='red')
polygon.boundary.plot(ax=ax)
我想将一个复杂的几何体分割成n 同一区域的最小几何体。可以将几何图形下载为 shapefile here。
【问题讨论】:
-
在这里说出我的想法:找到保持从正方形到目标几何的点之间的距离比的同构?你可以把它当作一个有约束的优化问题吗?
-
@MarioViti 我真的不明白你的问题。我想将我的区域划分为最小的区域,类似于 Voronoi 细分
-
像 Voronoi Tesselation 这样的算法是优化问题的精确解决方案。在您的情况下,Voronoi(或其双重 Delaunay)不满足您对等面积的约束。所以我建议将其作为一个优化问题,并根据结果问题的形状使用适当的求解器(迭代几乎总是有效)。查看 Voronoi + Lloyd 迭代方法 semanticscholar.org/paper/…
-
@MarioViti 你知道这方面的任何 python 代码/函数吗?
-
有一些 github repos e.g. github.com/duhaime/lloyd 但我还没有测试过它们:(
标签: python gis shapes geopandas shapely