python - 如何在python中将属性附加到geojson文件?

标签 python json data-visualization geojson

例如,我有具有如下功能的 geojson 文件。

{
"type": "FeatureCollection",
“工作宽度”:20,
“特征”: [
{
"type": "功能",
“几何学”: {
"type": "点",
“坐标”:[
28.4766,
12.5645456
]
}
}
]

如何将属性添加到上述文件中,如下所示。

{
"type": "FeatureCollection",
“工作宽度”:20,
“特征”: [
{
"type": "功能",
“几何学”: {
"type": "点",
“坐标”:[
28.4766,
12.5645456
]
},
“特性”: {
"fieldID": "2115145",
"segmentId": "255c2s4c",
“速度”:21.4586954,
“海拔”:52.4586642,
“时间”:“2018-05”
}
}
]
}

最佳答案

数据结构只是一个普通的 python 字典,所以你可以像往常一样更新它:

>>> geojson 
{'type': 'FeatureCollection',
 'working_width': 20,
 'features': [{'type': 'Feature',
               'geometry': {'type': 'Point', 
                            'coordinates': [28.4766, 12.5645456]}}]}

>>> geojson['properties'] =  {'fieldID': '2115145', 
                              'segmentId': '255c2s4c', 
                              'speed': 21.4586954, 
                              'elevation': 52.4586642, 
                              'time': '2018-05'}

>>> geojson
{'type': 'FeatureCollection',
 'working_width': 20,
 'features': [{'type': 'Feature',
               'geometry': {'type': 'Point', 
                            'coordinates': [28.4766, 12.5645456]}}],
 'properties': {'fieldID': '2115145',
                'segmentId': '255c2s4c',
                'speed': 21.4586954,
                'elevation': 52.4586642,
                'time': '2018-05'}}

关于python - 如何在python中将属性附加到geojson文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52587808/

相关文章:

python - 使用 python 和 tkinter 实时绘制串行数据

python - 无法在python中的selenium webdriver中加载firefox

python - 如何使用 PyQt5 的 QWebEngineView 处理 "render"HTML

javascript - 如何在 highcharts 系列中使用 javascript 变量?

java - JSON异常: No Value For

charts - 谷歌图表 : timeline: dynamic height with scalebar position

python - 在 switch 字典中执行函数

json - 我想将查询存储为 JSON 对象。 (错误 : The FOR JSON clause is not allowed in a SELECT INTO statement. )

r - 使用线条和多因子连接 ggplot 箱线图

python - 如何在 seaborn fiddle 情节中为每个组分配不同的位置