当我运行输入 placeQuad(-0.9,-0.4,1.0) 时,我不断收到此错误“NameError: name 'outpt_attr' 未定义”。任何帮助将不胜感激: 代码如下;
pt1= Point(0,0)
circle=pt1.buffer(1)
##collection of point and a circle
circle_pt1=collection([pt1,circle])
circle_pt1
# indentify qaud boundaries
def placeQuad(x,y,r):
circle = Point(0,0).buffer(1)
### creating quadrants
q1 = Polygon([(0,0),(0,1),(1,1),(1,0),(0,0)]).intersection(circle)
q2 = Polygon([(0,0),(0,1),(-1,1),(-1,0),(0,0)]).intersection(circle)
q3 = Polygon([(0,0),(-1,0),(-1,-1),(0,-1),(0,0)]).intersection(circle)
q4 = Polygon([(0,0),(0,-1),(1,-1),(1,0),(0,0)]).intersection(circle)
### storing the quadrants into a dictionary
quadrants = {"Quad1":q1, "Quad2":q2, "Quad3":q3, "Quad4":q4}
pt = Point(x,y)
outQuadrants = dict()
for key, quadrant in quadrants.items():
if pt.intersects(quadrant):
print ("point ({},{}) plots inside Quadrant {}".format(x,y,key))
else:
outQuadrants.update({key:quadrant})
###outer quadrants
if len(outQuadrants) == 4:
global outpt_attr
outpt_attr= dict()
for key, quadrant in outQuadrants.items():
center_dist = pt.distance(quadrant.centroid)
arc_dist = pt.distance(quadrant)
outpt_attr.update({key: [round(center_dist,2), round(arc_dist,2)]})
print ("pt({},{}) plots outside {}. Distance to closest point on arc is {:.2f}, \
while distance to centre of quadrant is {}".format())
##输入值 placeQuad(-0.9,-0.4,1.0)