I am attempting to create a function that creates a shapely Polygon object from either a list of point tuples (e.g. point_list = [(100,2), (32, 22), (70, 10.2)])
or Point objects (e.g. point_list = [point1, point2, point3]
, where point1
is defined as point1 = Point(100, 2)
, etc)
I understand that Polygon([[p.x, p.y] for p in point_list])) will create a Polygon object, which is why I can't figure out why the below code is giving >"TypeError: object of type 'Point' has no 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))
I get:
TypeError: object of type 'Point' has no len() when I should be getting a Polygon object