簡體   English   中英

Python:高效地使用形狀測量區域屬性的方法

[英]Python: efficient way to measure region properties using shapely

首先,我很抱歉張貼這個簡單的問題。 我有一個多邊形

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)])

在此處輸入圖片說明

我的目標是按照下圖示例計算該多邊形的短軸和長軸 在此處輸入圖片說明

我在scikit-image中找到了這個示例,但是在使用第二個模塊之前,我想問一下勻稱模塊中是否存在一種計算這些指數的方法。

提前致謝

這個問題有點老了,但我最近遇到了這個問題,這是我做的:

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變得容易,但是似乎相對的邊沒有完全相等的長度。 因此,上面的方法計算了每側的長度,然后取最小值/最大值。

首先計算多邊形的最小邊界矩形-參見如何找到給定點的最小面積矩形中描述的過程 ,除了您將從凸包開始。 在Shapely中,使用.convex_hull()方法來計算多邊形的凸包。

然后,一旦有了MBR,就可以找到主軸/副軸。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM