本文整理汇总了Python中Polygon.area方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.area方法的具体用法?Python Polygon.area怎么用?Python Polygon.area使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon
的用法示例。
在下文中一共展示了Polygon.area方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_some_pts
# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import area [as 别名]
def remove_some_pts(self, prop=.9):
newp = Polygon()
c=-1
for cont in self.poly:
c+=1
cr = reducePoints(cont,int(len(cont)*prop))
ishole = self.poly.isHole(c)
if len(cr)>2:
newp.addContour(cr, ishole)
parea = self.poly.area()
nparea = newp.area()
#areadiff = math.fabs(nparea-parea)
arearatio = parea/nparea
arearatio = math.fabs(arearatio-1)
#print areadiff, arearatio
if arearatio < 0.1:
self.poly = newp
示例2: range
# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import area [as 别名]
stat.close()
lam_list=[]
#print "*** New Country! ***"
fline=f.readline().strip()
flist=fline.split(":")
if flist==[""]:break
country=flist[0].strip()
raw_points=flist[1].strip().split(";")
x_points=[float(raw_point.split(",")[0]) for raw_point in raw_points if raw_point!=""]
y_points=[float(raw_point.split(",")[1]) for raw_point in raw_points if raw_point!=""]
i_poly=Polygon([[x_points[i],y_points[i]] for i in range(len(x_points))])
i_area=i_poly.area()
print ("*** Point loaded for country %s." %(country))
x_points,y_points=pre(x_points,y_points)
if country in i_country_dict.keys():
i_country_dict[country]=i_country_dict[country]+len(x_points)
i_area_dict[country]=i_area_dict[country]+i_area
else:
i_country_dict[country]=len(x_points)
i_area_dict[country]=i_area
if len(x_points)<20:
示例3: range
# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import area [as 别名]
if flist==[""]:
print "*** New Country! ***"
fline=f.readline().strip()
flist=fline.split(":")
country=flist[0].strip()
raw_points=flist[1].strip().split(";")
x_points=[float(raw_point.split(",")[0]) for raw_point in raw_points if raw_point!=""]
y_points=[float(raw_point.split(",")[1]) for raw_point in raw_points if raw_point!=""]
i_area=Polygon([[x_points[i],y_points[i]] for i in range(len(x_points))]).area()
print ("*** Point loaded for country %s. %d points. Area is %f.***" %(country,len(x_points),i_area))
inter_x,inter_y=chi(x_points,y_points,lam)
c_poly=Polygon([[inter_x[i],inter_y[i]] for i in range(len(inter_x))])
c_area=c_poly.area()
c_gain=-(i_area-c_area)*1.0/c_area*100.0
print ("*** Now has %d points after Chi and an area of %f. Increased by %f percent.***" %(len(inter_x),c_area,c_gain))
new_x,new_y=linear(inter_x,inter_y,threshold)
l_poly=Polygon([[new_x[i],new_y[i]] for i in range(len(new_x))])
l_area=l_poly.area()
l_gain=(l_area-c_area)*1.0/c_area*100.0
cut=(c_poly-(c_poly&l_poly)).area()
cut_percent=cut*1.0/c_area*100.0
print ("*** Now has %d points after Linear and an area of %f. Further increased by %f percent. Cut-off is %f percent***" %(len(new_x),l_area,l_gain,cut_percent))
elif instr=="l":
lam_input=raw_input("Enter a lambda value: ")
示例4: dividePolygon
# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import area [as 别名]
def dividePolygon(self,polygon,coveredArea,k,fill,rec=1):
if k == 1:
areas = [polygon]
areaUnion = polygon
self.lAreas += 1
elif k == 2:
areas = self.postDividePolygons([polygon],2)
areaUnion = polygon
self.lAreas += 2
else:
if k*self.pg >= 1:
area = polygon.area()*self.pg
else:
area = polygon.area()*(1/float(k))
ratio = (area/float(numpy.pi))**0.5
scale = ratio/self.mu
areas = []
uncoveredArea = polygon - coveredArea
fillOld = 0
count = 0
oldCovered = -1
areaUnion = Polygon()
newk = k
while uncoveredArea.area()/polygon.area() >= (1-fill): # Mientras se llena al p1%
count += 1
if oldCovered != coveredArea.area():
count = 0
if len(uncoveredArea) > 1:
uncovered2select = [Polygon(x) for x in uncoveredArea]
uncovered2select.sort(key=lambda x: x.area(),reverse=True)
uncovered2select = uncovered2select[0]
else:
uncovered2select = uncoveredArea
oldCovered = coveredArea.area()
if count >= 20:
count += 1
end = False
while end != True:
uncovered2select2 = self.postDividePolygons([uncovered2select],2)
for x in uncovered2select2:
if newk*x.area()/uncoveredArea.area() <= 1.5:
areas.append(x)
uncoveredArea = uncoveredArea - x
coveredArea = coveredArea | x
areaUnion = areaUnion | x
end = True
if uncoveredArea.area() > 0:
if newk*uncovered2select.area()/uncoveredArea.area() <= 1.5:
areas.append(uncovered2select)
uncoveredArea = uncoveredArea - uncovered2select
coveredArea = coveredArea | uncovered2select
areaUnion = areaUnion | uncovered2select
else:
center = uncoveredArea.sample(numpy.random.uniform)
angle = numpy.random.uniform(0,2)*numpy.pi
x = ratio*numpy.cos(angle) + center[0]
y = ratio*numpy.sin(angle) + center[1]
aPoint = (x,y)
alp = numpy.random.uniform(self.alpha[0],self.alpha[1])
sig = numpy.random.uniform(self.sigma[0],self.sigma[1])
a,r,sa,sr,X1,times = mrpolygon(alp,sig,self.mu,self.X_0,self.dt,self.N)
sa,sr = scalePolygon(sa,sr,scale)
polygoni = polarPolygon2cartesian(zip(sa,sr))
polygoni = transportPolygon(polygoni, center, aPoint)
polygoni = Polygon(polygoni)
polygoni = polygoni - coveredArea
polygoni = polygoni & polygon
if len(polygoni) > 1:
pl = [Polygon(x) for x in polygoni]
pl.sort(key=lambda x: x.area())
polygoni = pl[-1]
newN = numpy.round(newk*polygoni.area()/uncoveredArea.area())
rnd = numpy.random.uniform(0,1)
if rnd <= self.pu:
newN += numpy.round(numpy.random.uniform(0,self.su)*newk)
if newN >= 1:
areasi, coveredAreai = self.dividePolygon(polygoni,coveredArea,newN,fill,rec=rec+1)
newk -= newN
coveredArea = coveredArea | coveredAreai
areaUnion = areaUnion | coveredAreai
areas += areasi
uncoveredArea = polygon - coveredArea
areas = self.postCorrectionHoles(areaUnion,areas)
areas.sort(key=lambda x: x.area())
nAreas = []
for nx, x in enumerate(areas):
add = True
for nx2, x2 in enumerate(areas[nx+1:]):
if x2.overlaps(x):
if x2.covers(x):
add = False
break
else:
x = x - x2
if add:
nAreas.append(x)
areas = nAreas
if len(areas) < k:
areas = self.postDividePolygons(areas,k)
if len(areas) > k:
#.........这里部分代码省略.........
示例5: postDividePolygons
# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import area [as 别名]
def postDividePolygons(self,areas,nAreas):
def getPointInFace(face,bbox):
if face == 0:
x = bbox[0]
y = numpy.random.uniform(bbox[2],bbox[3])
elif face == 1:
y = bbox[3]
x = numpy.random.uniform(bbox[0],bbox[1])
elif face == 2:
x = bbox[1]
y = numpy.random.uniform(bbox[2],bbox[3])
elif face == 3:
y = bbox[2]
x = numpy.random.uniform(bbox[0],bbox[1])
return x,y
def getCornersOfFace(face,bbox):
if face == 0:
c1 = (bbox[0],bbox[2])
c2 = (bbox[0],bbox[3])
elif face == 1:
c1 = (bbox[0],bbox[3])
c2 = (bbox[1],bbox[3])
elif face == 2:
c1 = (bbox[1],bbox[3])
c2 = (bbox[1],bbox[2])
elif face == 3:
c1 = (bbox[1],bbox[2])
c2 = (bbox[0],bbox[2])
return c1,c2
while len(areas) < nAreas:
end = False
while not end:
areaOrder = range(0,len(areas))
areaOrder.sort(key=lambda x: areas[x].area(),reverse=True)
na = areaOrder[0]
#na = numpy.random.randint(0,len(areas))
if areas[na][0][0] != areas[na][0][-1]:
areas[na] = Polygon([x for x in areas[na][0]] + [areas[na][0][0]])
area = areas[na]
bbox = area.boundingBox()
bboxp = Polygon([(bbox[0]-1,bbox[2]-1),(bbox[0]-1,bbox[3]+1),
(bbox[1]+1,bbox[3]+1),(bbox[1]+1,bbox[2]-1),
(bbox[0]-1,bbox[2]-1)])
bbox = bboxp.boundingBox()
inside = False
errors = 0
warnings = 0
i = 0
while not inside:
if errors == 20 and na +1 < len(areas):
i += 1
na = areaOrder[i]
if areas[na][0][0] != areas[na][0][-1]:
areas[na] = Polygon([x for x in areas[na][0]] + [areas[na][0][0]])
area = areas[na]
bbox = area.boundingBox()
bboxp = Polygon([(bbox[0]-1,bbox[2]-1),(bbox[0]-1,bbox[3]+1),
(bbox[1]+1,bbox[3]+1),(bbox[1]+1,bbox[2]-1),
(bbox[0]-1,bbox[2]-1)])
bbox = bboxp.boundingBox()
errors = 0
f1 = numpy.random.randint(0,4)
f2 = (f1 + numpy.random.randint(1,4))%4
faces = [f1,f2]
faces.sort()
p1 = getPointInFace(faces[0],bbox)
if f1%2 == 0:
p2 = (p1[0],p1[1]+1)
else:
p2 = (p1[0]+1,p1[1])
p3 = getPointInFace(faces[1],bbox)
if f2%2 == 0:
p4 = (p3[0],p3[1]+1)
else:
p4 = (p3[0]+1,p3[1])
line = Polygon([p1,p2,p3,p4,p1])
inters = area & line
parts = line - area
if len(parts) == 2 and inters.area() >= line.area()*0.2 :
inside = True
else:
errors += 1
divPolygon = [p1]
for i in range(*faces):
c1,c2 = getCornersOfFace(i,bbox)
divPolygon.append(c2)
divPolygon.append(p3)
divPolygon.append(p1)
divPolygon = Polygon(divPolygon)
polygon1 = divPolygon & area
divPolygon = bboxp - divPolygon
polygon2 = area - polygon1
if len(polygon1) == 1 and \
len(polygon2) == 1 and \
polygon1.area() > 0 and \
polygon2.area() > 0 and \
#.........这里部分代码省略.........