python - 使用 shapely 测量区域属性的有效方法?

标签 python performance geometry computational-geometry

首先,我很抱歉提出这个简单的问题。我有一个多边形

from shapely.geometry import Polygon

polygon = Polygon([(560023.4495758876400000 6362057.3904932579000000),(560023.4495758876400000 6362060.3904932579000000),(560024.4495758876400000 6362063.3904932579000000),(560026.9495758876400000 6362068.3904932579000000),(560028.4495758876400000 6362069.8904932579000000),(560034.9495758876400000 6362071.8904932579000000),(560036.4495758876400000 6362071.8904932579000000),(560037.4495758876400000 6362070.3904932579000000),(560037.4495758876400000 6362064.8904932579000000),(560036.4495758876400000 6362063.3904932579000000),(560034.9495758876400000 6362061.3904932579000000),(560026.9495758876400000 6362057.8904932579000000),(560025.4495758876400000 6362057.3904932579000000),(560023.4495758876400000 6362057.3904932579000000)])

enter image description here

我的目标是计算这个多边形的短轴和长轴,按照图例: enter image description here

我在 scikit-image 中找到了这个例子但在使用第二个模块之前,我想问一下 shapely 模块中是否有计算这些指数的方法。

提前致谢

最佳答案

这个问题有点老了,但我最近自己遇到了这个问题,这是我所做的:

from shapely.geometry import Polygon, LineString

polygon =  Polygon([(560023.4495758876400000, 6362057.3904932579000000),(560023.4495758876400000, 6362060.3904932579000000),(560024.4495758876400000, 6362063.3904932579000000),(560026.9495758876400000, 6362068.3904932579000000),(560028.4495758876400000, 6362069.8904932579000000),(560034.9495758876400000, 6362071.8904932579000000),(560036.4495758876400000, 6362071.8904932579000000),(560037.4495758876400000, 6362070.3904932579000000),(560037.4495758876400000, 6362064.8904932579000000),(560036.4495758876400000, 6362063.3904932579000000),(560034.9495758876400000, 6362061.3904932579000000),(560026.9495758876400000, 6362057.8904932579000000),(560025.4495758876400000, 6362057.3904932579000000),(560023.4495758876400000, 6362057.3904932579000000)])

# get the minimum bounding rectangle and zip coordinates into a list of point-tuples
mbr_points = list(zip(*polygon.minimum_rotated_rectangle.exterior.coords.xy))

# calculate the length of each side of the minimum bounding rectangle
mbr_lengths = [LineString((mbr_points[i], mbr_points[i+1])).length for i in range(len(mbr_points) - 1)]

# get major/minor axis measurements
minor_axis = min(mbr_lengths)
major_axis = max(mbr_lengths)

Shapely 使得通过 minimum_rotated_rectangle 计算 mbr 变得很容易,但似乎对边的长度并不完全相等。因此,上面计算每边的长度,然后取最小值/最大值。

关于python - 使用 shapely 测量区域属性的有效方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13536209/

相关文章:

python - python中跨平台控制台应用程序的类curses库

具有扩展状态对象的 C# A* 算法

python - Pandas 石斑鱼显示类型错误

java - 在 java 中使用 public 的整个方法对性能有什么影响吗?

javascript - 只更新可见的 DOM 元素?

javascript - 使用javascript检查重叠圆形元素的函数?

ios - 使用约束从用户点击计算点坐标

3d - 如何从平面相交的 3D 几何体中提取 2D 切片?

python - 使用 Selenium Python chrome webdriver 发推文

python - 如何使用 Python 挂载文件系统?