使用Python将属性添加到GeoJSON Feature Collection中的功能中

时间:2018-10-11 14:13:17

标签: python geojson

我有一个GeoJSON功能集,它只是旅行的线串。我想为每个功能添加列表和字典。每个要素上添加到每个要素的数据不同,但是存储的顺序与路线相同。如何将这些数据作为属性添加到Feature Collection?

type(data)
>>> geojson.feature.FeatureCollection

data[1] #Example of what the data looks like
{'type': 'Feature',
 'geometry': {'type': 'LineString',
  'coordinates': [[-94.579644, 39.102126],
   [-64.579644, 29.102126],
   [-64.52684, 29.112103],
   [-64.52684, 29.112103]]},
 'properties': {'name': 'Route #1'}}

下面是我要添加的数据示例。我希望这次旅行的Trip_ID成为上面的功能集中的一个属性。

type(Trip_ID)
...list

trip_id[1]
'149b16a4-f1ee-40ce-a165-5326196a1307'

谢谢!

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您想将Trip_ID集合中的每个ID添加到FeatureCollection中的每个Feature对象。

我会尝试的:

for i in range(len(Trip_ID)):
    data[i].properties['id'] = Trip_ID[i]

注意:假设两个集合的大小和顺序相同。

相关问题