简体   繁体   English

如何使用python从点列表中计算多边形的面积?

[英]How to calculate area of polygon from list of points with python?

I have a list/array of 2D points which form a non-convex non-self-intersecting shape. 我有一个2D点的列表/数组,这些点/数组形成一个非凸的 非自相交的形状。 I want to calculate the area enclosed by that polygon. 我想计算该多边形包围的面积。

First I need to form a polygon with the points that I get provided as a 'curve-walk' (non self intersecting). 首先,我需要以“曲线行进”(非自相交)的形式形成一个多边形。 If I can triangulate that polygon I can calculate the area ( I can tolerate a small relative error). 如果我可以对该多边形进行三角测量,则可以计算出面积(我可以忍受很小的相对误差)。

Using scipy's scipy.spatial.ConvexHull() results in the wrong shape and area , obviously, but I have not found a available algorithm in the big math packages which does this. 显然,使用scipy的scipy.spatial.ConvexHull()导致错误的形状和区域,但是我没有在大型数学软件包中找到可用的算法来做到这一点。

Can anyone tell me how to do that ? 谁能告诉我该怎么做?

use the shapely module available for both Python 2.7 and 3 使用适用于Python 2.7和3的匀称模块

In [41]: from shapely.geometry import Polygon

In [48]: coords  = ((-1, 0), (-1, 1), (0, 0.5), (1, 1), (1, 0), (-1, 0))

In [49]: polygon = Polygon(coords)

In [50]: polygon.area
Out[50]: 1.5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM