Geographic Information Systems Asked by FJ_Abbasi on January 24, 2021
I have a creating a list of shapely polygons. While I am trying to create a geodataframe from that list it gives an error:
intersec_ls = [poly1, poly2, poly3]
cu = cascaded_union(intersec_ls)
differ = buffer.difference(cu)
fin_ls.append(differ)
fin_ls.append(intersec_ls)
geom = gpd.GeoSeries(fin_ls)
gdf = gdf( geometry= geom)
TypeError: Input must be valid geometry objects: [<shapely.geometry.polygon.Polygon object at 0x00000213702BEDA0>]
How can I deal with invalid geometry in the list?
There are two mistakes in your script.
Since intersect_ls
is a list, use extend
instead of append
. The reason of getting error is that. Because the first item in fin_ls
is a geometry, the other is a list, but it should have been a geometry too.
fin_ls.append(differ)
fin_ls.extend(intersec_ls)
Since gdf
is a GeoDataFrame
instance, you cannot use parenthesis with gdf
as in gdf( geometry= geom)
. Instead, use
gdf = gpd.GeoDataFrame(gdf, geometry=geom)
Or just use gdf = gpd.GeoDataFrame(geometry=geom)
if you didn't define gdf
before. In this case gdf
includes only geometries.
Correct answer by Kadir Şahbaz on January 24, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP