我在我的Python脚本中有一个外形多边形的列表。我想将此列表保存为一个Geojson对象。我尝试循环浏览列表并保存每个列表,但这只是将它们保存为单个Geojson文件(显而易见)。知道该怎么做吗?
import geopandas as gpd
#Create a list of shapely geometries
polygons = [loads(wkt) for wkt in ["POLYGON ((0 15, 0 9, 3 9, 5 11, 5 16, 0 16, 0 15))",
"POLYGON ((5 17, 6 11, 2 8, 2 7, 9 7, 9 17, 5 17))",
"POLYGON ((12 14, 17 14, 15 17, 12 14))",
"POLYGON ((14 9, 18 9, 18 12, 14 12, 14 9))"]]
#Create a geodataframe. Change 4326 to you coordinate system
df = gpd.GeoDataFrame(geometry=polygons, crs=4326)
df.to_file(r"C:\Users\bera\Desktop\gistest\blabla.geojson")