6

First of all, I apologize to post this easy question. I have a polygon

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

My goal is compute the minor and the major axis of this polygon, following the Figure example: enter image description here

I find this example in scikit-image but before to use a second module I wish to ask if there is in shapely module a method to calculate these indices.

thanks in advance

4

2 回答 2

4

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

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 使计算 mbr via 变得容易minimum_rotated_rectangle,但似乎相反的边的长度并不完全相同。正因为如此,上面计算了每一边的长度,然后取最小值/最大值。

于 2018-09-04T20:31:34.060 回答
0

首先计算多边形的最小边界矩形 - 请参阅如何找到给定点的最小面积矩形中描述的过程?,除了你将从凸包开始。在 Shapely 中,使用该.convex_hull()方法计算多边形的凸包。

然后,一旦您拥有 MBR,您就可以找到主轴/次轴。

于 2012-12-05T06:04:28.777 回答