GeoJson usage in folium

拟墨画扇 提交于 2020-01-17 08:37:08

问题


I have used GeoJson method in FeatureGroup of folium to add polygon layers to my map. I am getting some error. I have checked the syntax of this method.Everything is correct but still i am getting the error mentioned below in the image.


回答1:


I stumbled upon the same issue.

From the documentation at https://python-visualization.github.io/folium/modules.html#folium.features.GeoJson you can see various examples of opening the geojson file.

>>> # 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())

What worked for me was,

>>> GeoJson(open('foo.json').read())



回答2:


The data parameter in GeoJson() needs string to process, you sending it as a file object, in order to convert it to string, just add read() method at the end of open() to convert it to string.

Like this

fg.add_child(folium.GeoJson(data=(open("world.json", "r", encoding="utf-8-sig")).read()))

That's all, no over will pop up then.



来源:https://stackoverflow.com/questions/46611439/geojson-usage-in-folium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!