python - Python3 - 如何连接 GeoJSON 的字典?
问题描述
所以这可能是一个非常明显的答案,但我似乎无法掌握它。
我正在尝试建立我所在城市的等值线地图。我在 XY 坐标中有不同区域的边界。
我必须将它与 GeoJSON 规范匹配才能输入 folium。“特征”应该是 JSON 特征的字典。
geojson = {
"type": "FeatureCollection",
"features": feature
}
为了构建功能字典,我使用了:
for district in range(len(khobar_districts_xy)):
feature = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": khobar_districts_xy[district]["boundaries"]},
"properties": {
"district_id": khobar_districts_xy[district]["district_id"],
"city_id": khobar_districts_xy[district]["city_id"],
"name_en": khobar_districts_xy[district]["name_en"]}
}
对于单个功能,这种安排是有效的,但是一旦我将它循环到许多地区,它就需要采用以下形式:
{{feature1},{feature2},{feature3}}
我尝试了很多东西,包括写入文件和读取文件,但我似乎一直遇到问题。有没有人有好的解决方案?
完整代码在这里
解决方案
“特征”应该是 JSON 特征的字典。
geojson = { "type": "FeatureCollection", "features": feature }
我很确定features
(注意复数)应该是一个字典列表:
[{feature1},{feature2},{feature3}]
这就是它的全部内容。
推荐阅读
- here-api - Here地图中的错误。如何修复它们?
- gitlab - 在 Gitlab CI 中包含 ghostscript 的最简单方法
- python - 代码不与 VS Codium 一起使用,但与 VSCode 一起使用
- asp.net - 分页查询 SQL Server 的超时问题
- java - 如何从单个 Maven 命令运行两个配置文件
- node.js - 使用 Apache 的 Node.js,代理错误:代理服务器无法处理请求原因:与远程服务器进行 SSL 握手期间出错
- reactjs - 何时在带有 react-dom 的开玩笑单元测试中使用 act()
- python - 使用 exec 进行变量赋值 pythonic 吗?
- embedded-linux - TOOLCHAIN_HOST_TASK 与 TOOLCHAIN_TARGET_TASK
- go - 如何在 golang revel 框架下运行 Angular 构建