我有一系列Shapely Polygon(一个MultiPolygon集),并且我想计算整个Multipolygon集上一个圆的相交面积。我可以对单个多边形执行此操作,例如:
from shapely.geometry import Point, Polygon, MultiPolygon
import matplotlib.pyplot as plt
import numpy as np
p = Point(0, 0)
circle = p.buffer(1.) # circle of center p and radius 1.
points = np.array(circle.exterior.coords) # point coords of circle
polygon = Polygon(points) # create polygon
plt.scatter(points[:,0],points[:,1])
p2 = Point(0.4, 0.7)
circle2 = p2.buffer(0.3)
points2 = np.array(circle2.exterior.coords)
polygon2 = Polygon(points2)
plt.scatter(points[:,0],points[:,1])
p3=polygon.intersection(polygon2)
p3_coord=np.array(p3.exterior.coords)
plt.scatter(p3_coord[:,0],p3_coord[:,1])
print(p3.area) # area of the intersection (green poligon)
现在,我尝试使用MultiPolygon进行相同操作:
p3 = Point(0.3, 0.9)
circle3 = p3.buffer(0.3)
points3 = np.array(circle3.exterior.coords)
polygon3 = Polygon(points3)
plt.scatter(points3[:,0],points3[:,1])
p4 = Point(0.85, 0.9)
circle4 = p4.buffer(0.2)
points4 = np.array(circle4.exterior.coords)
polygon4 = Polygon(points4)
plt.scatter(points4[:,0],points4[:,1])
p5 = Point(0.6, 0.9)
circle5 = p5.buffer(0.1)
points5 = np.array(circle5.exterior.coords)
polygon5 = Polygon(points5)
plt.scatter(points5[:,0],points5[:,1])
polygons = MultiPolygon([polygon3, polygon4])
p_intersect=polygons.intersection(polygon5)
p_intersect_coord=np.array(p_intersect.exterior.coords)
plt.scatter(p_intersect_coord[:,0],p_intersect_coord[:,1])
但是我得到了错误
AttributeError: 'MultiPolygon' object has no attribute 'exterior'
我想要的是计算相交区域中的面积,即绿色圆圈和蓝色圆圈之间的面积,以及绿色圆圈和橙色圆圈之间的面积。考虑到MultiPolygon(蓝色加橙色圆圈)和绿色圆圈,我想在一个操作中完成此操作。 有没有办法匀称?