gpt4 book ai didi

python - 使用 Python 附加 geoJSON 功能?

转载 作者:行者123 更新时间:2023-11-30 22:47:17 27 4
gpt4 key购买 nike

我在 geojson 文件中有以下结构:

{"crs": 
{"type": "name",
"properties":
{"name": "urn:ogc:def:crs:EPSG::4326"}
},
"type": "FeatureCollection",
"features": [
{"geometry":
{"type": "Polygon",
"coordinates": [[[10.914622377957983, 45.682007076150505],
[10.927456267537572, 45.68179119797432],
[10.927147329501077, 45.672795442796335],
[10.914315493899755, 45.67301125363092],
[10.914622377957983, 45.682007076150505]]]},
"type": "Feature",
"id": 0,
"properties": {"cellId": 38}
},
{"geometry":
{"type": "Polygon",
"coordinates":
... etc. ...

我想将此 geoJSON 读入 Google map ,并根据我在 Python 中为每个单元格单独计算的属性为每个单元格着色。所以我最大的问题是:如何使用 Python 读取 geoJSON 并向这些多边形添加另一个属性(大约有 12 000 个多边形,因此不能逐个添加它们),然后写入新文件?

我认为我正在寻找的是一个可以处理geoJSON的Python库,所以我不必通过srting操作添加这些功能。

最佳答案

有一种方法是 Python geojson package .

这样,您可以读取 geojson 有一个对象:

import geojson
loaded = geojson.loads("Any geojson file or geojson string")

for feature in loaded.features[0:50]: #[0:50] for the only first 50th.
print feature

Feature、FeatureCollection 和 Custom 类可帮助您添加属性。

关于python - 使用 Python 附加 geoJSON 功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40574727/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com