我有一个从加拿大统计局获得的GEOJSON代码,我正尝试在其中输入一些数据。
这是我的geojson代码
{ "type": "Feature","properties": {"name": "001", "ivl_a": 1.1, "ivl_f": 0.3, "differentiel": 1.5...
{ "type": "Feature","properties": {"name": "002", "ivl_a": 1.1, "ivl_f": 0.3, "differentiel": 0.4...
{ "type": "Feature","properties": {"name": "003", "ivl_a": 1.1, "ivl_f": 0.3, "differentiel": 0.4...
我想用我在Excel列中拥有的数据替换ivl_a,ivl_f和differentiel的数据。
我该怎么做?
答案 0 :(得分:0)
虽然我不确定我是否掌握了所有详细信息,但这也许足以指导您。
由于您没有说明细节,所以我做了一些假设:
我已经设置了一个csv结构(没有标题): 名称,ivl_a,ivl_f,差异
就读/写geojson数据而言,我留给您作为练习(因为上面的示例数据不完整)
import csv
def read_csv(csv_filename):
# assuming csv of (without header)
# name, ivl_a, ivl_f, differentiel
lookup = {}
with open(csv_filename) as csvfile:
reader = csv.reader(csvfile)
for row in reader:
name = row[0]
lookup[name] = {
'lvl_a': row[1],
'lvl_f': row[2],
'differentiel': row[3]
}
return lookup
def main():
lookup = read_csv('data.csv')
# todo: read the data into list of dicts
features = []
for feature in features:
props = feature['properties']
name = props['name']
props['lvl_a'] = lookup[name]['lvl_a']
props['lvl_f'] = lookup[name]['lvl_f']
props['differentiel'] = lookup[name]['differentiel']
# todo: save
if __name__ == '__main__':
main()
希望这会有所帮助。