例如,我有具有如下功能的 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/