我正在尝试创建一个函数,该函数从点元组(例如point_list = [(100,2), (32, 22), (70, 10.2)])
或Point对象(例如point_list = [point1, point2, point3]
,其中point1
被定义为point1 = Point(100, 2)
等
我知道Polygon(point_list中p的[[[px,py])将创建一个Polygon对象,这就是为什么我不知道为什么下面的代码给出>“ TypeError:type'object'点'没有len()“
point_list = [point1, point2, point3]
def create_poly_geom(coords):
assert type(coords) == type(list()), "Input should be a list"
#assert len(coords) >= 3, "Polygon object requires at least 3 points"
for element in coords:
assert type(element) == type(Point()) or type(element) == type(tuple()),
"All list values should be Shapely Point objects"
if type(coords) == type(list()):
return Polygon(coords)
else:
return Polygon([[p.x, p.y] for p in coords])
print(create_poly_geom(point_list))
我得到:
TypeError:当我应该获取Polygon对象时,'Point'类型的对象没有len()