【问题标题】:How to divide a complex geometry into n equals subgeometries?如何将复杂几何划分为 n 等于子几何?
【发布时间】: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


【解决方案1】:

最简单、最有效的解决方案之一是取几何的minimum_rotated_rectangle

  1. 首先,将 Polygon 或 MultiPolygon 转换为 LineString,然后得到包含该行的 minimum_rotated_rectangle

  2. 然后你将之前的代码应用到这个矩形。

  3. 最后,您必须在多边形的 LineString 和子几何之间进行第二次拆分。


一个伟大的交钥匙解决方案:https://stackoverflow.com/a/68778560/14864907

【讨论】:

    猜你喜欢
    • 2011-03-22
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多