如何在python中向geojson文件追加属性?

2024-10-03 04:39:02 发布

您现在位置:Python中文网/ 问答频道 /正文

例如,我有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” } } ] }在


Tags: 文件功能宽度属性geojsontype时间特性
1条回答
网友
1楼 · 发布于 2024-10-03 04:39:02

数据结构只是一个常规的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'}}

相关问题 更多 >