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

问题描述 投票:1回答:1

例如,我有geojson文件,其功能如下所示。

{“type”:“FeatureCollection”,“working_width”:20,“features”:[{“type”:“Feature”,“geometry”:{“type”:“Point”,“coordinates”:[28.4766,12.5645456 ]}}]

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

{“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 json data-visualization geojson
1个回答
1
投票

数据结构只是一个常规的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'}}
© www.soinside.com 2019 - 2024. All rights reserved.