我想动态生成一个包含可变数量多边形的geoJSON。以下是2个多边形的示例:
{
"type": "FeatureCollection",
"features": [
{"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "Polygon",
"coordinates":
[[11.0878902207, 45.1602390564],
[0.8251953125, 41.0986328125],
[7.63671875, 48.96484375],
[15.01953125, 48.1298828125]]
},
{
"type": "Polygon",
"coordinates":
[[11.0878902207, 45.1602390564],
[14.931640625, 40.9228515625],
[11.0878902207, 45.1602390564]]
}
]
},
"type": "Feature",
"properties": {}}
]
}
我有一个函数,可以为每个多边形提供坐标列表,因此我可以创建多边形列表,然后使用for循环迭代以构建geoJSON。
问题在于我不知道如何轻松做到这一点(例如,我考虑将列表作为字符串返回,但是将geoJSON构建为字符串似乎是个不好的想法)。
有人建议我使用这个非常“Pythonic”的想法:
geo_json = [ {"type": "Feature",,
"geometry": {
"type": "Point",
"coordinates": [lon, lat] }}
for lon, lat in zip(ListOfLong,ListOfLat) ]
但是由于我正在添加可变数量的多边形而不是点列表,因此这种解决方案似乎不太适合。或者至少我不知道该如何进行调整。
我可以将其构建为字符串,但我希望以更智能的方式实现。你有什么想法吗?