相关疑难解决方法(0)

获取位于 Shapely 多边形内的所有格点

我需要找到多边形内部和多边形上的所有格点。

输入:

from shapely.geometry import Polygon, mapping
sh_polygon = Polygon(((0,0), (2,0), (2,2), (0,2)))
Run Code Online (Sandbox Code Playgroud)

输出:

(0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1), (0, 2), (1, 2), (2, 2)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

请建议是否有办法在使用或不使用 Shapely 的情况下获得预期结果。

我编写了这段代码,它给出了多边形内部的点,但它没有给出多边形上的点。还有更好的方法来做同样的事情:

from shapely.geometry import Polygon, Point

def get_random_point_in_polygon(poly):
    (minx, miny, maxx, maxy) = poly.bounds
    minx = int(minx)
    miny = int(miny)
    maxx = int(maxx)
    maxy = int(maxy)
    print("poly.bounds:", poly.bounds)
    a = []
    for x in range(minx, maxx+1):
        for y in range(miny, maxy+1):
            p = Point(x, y) …
Run Code Online (Sandbox Code Playgroud)

python mathematical-lattices shapely

5
推荐指数
2
解决办法
5224
查看次数

标签 统计

mathematical-lattices ×1

python ×1

shapely ×1