【发布时间】:2018-03-18 14:19:07
【问题描述】:
【问题讨论】:
标签: python json geojson folium
【问题讨论】:
标签: python json geojson folium
我偶然发现了同样的问题。
从https://python-visualization.github.io/folium/modules.html#folium.features.GeoJson 的文档中,您可以看到打开geojson 文件的各种示例。
>>> # Providing file that shall be embedded.
>>> GeoJson(open('foo.json'))
>>> # Providing filename that shall not be embedded.
>>> GeoJson('foo.json')
>>> # Providing dict.
>>> GeoJson(json.load(open('foo.json')))
>>> # Providing string.
>>> GeoJson(open('foo.json').read())
对我有用的是,
>>> GeoJson(open('foo.json').read())
【讨论】:
GeoJson()中的data参数需要string处理,你把它作为文件发送object,为了转换成string,只需在open()末尾添加read()方法即可将其转换为string。
这样
fg.add_child(folium.GeoJson(data=(open("world.json", "r", encoding="utf-8-sig")).read()))
就是这样,然后不会弹出。
【讨论】: