如何在 geojson 弹出窗口中显示信息 - Python
How to display information in geojson popup - Python
我在从 JSON 文件检索信息的 folium 弹出窗口中显示信息时遇到问题。目前,我的代码只从我的 JSON 文件中检索最后一条信息并将其插入所有弹出窗口,因此我的所有弹出窗口都只显示那一条信息。我似乎无法弄清楚每个节点在其弹出窗口中都有自己独特的信息。感谢任何帮助。
# reading JSON file
with open('exportBuilding.geojson') as access_json:
read_content = json.load(access_json)
feature_access = read_content['features']
# Creating Folium Map
m = folium.Map(location=[1.400150, 103.910172], titles="Punggol", zoom_start=17)
nodeData = os.path.join('exportBuilding.geojson')
geo_json = folium.GeoJson(nodeData)
# retrieve all names and store in popup
for feature_data in feature_access:
property_data = feature_data['properties']
geo_json.add_child(folium.Popup(property_data['name'))
geo_json.add_to(m)
对于遇到与我相同问题的任何人,最新的 folium 中有一个名为 "GeoJsonPopup" 的函数,它将从 JSON 文件中检索您指定的所有信息并将其显示在Popup,解决所有节点都会有自己唯一的个体信息的问题。
而不是创建一个 for 循环来循环整个 JSON,
# reading JSON file
with open('exportBuilding.geojson') as access_json:
read_content = json.load(access_json)
feature_access = read_content['features']
# Creating Folium Map
m = folium.Map(location=[1.400150, 103.910172], titles="Punggol", zoom_start=17)
nodeData = os.path.join('exportBuilding.geojson')
# This is retrieve all information, in this case is name from my JSON file
# and display it into my popup, such that all nodes
# will have its own unique information.
geo_json = folium.GeoJson(nodeData, popup=folium.GeoJsonPopup(fields=['name']))
geo_json.add_to(m)
我在从 JSON 文件检索信息的 folium 弹出窗口中显示信息时遇到问题。目前,我的代码只从我的 JSON 文件中检索最后一条信息并将其插入所有弹出窗口,因此我的所有弹出窗口都只显示那一条信息。我似乎无法弄清楚每个节点在其弹出窗口中都有自己独特的信息。感谢任何帮助。
# reading JSON file
with open('exportBuilding.geojson') as access_json:
read_content = json.load(access_json)
feature_access = read_content['features']
# Creating Folium Map
m = folium.Map(location=[1.400150, 103.910172], titles="Punggol", zoom_start=17)
nodeData = os.path.join('exportBuilding.geojson')
geo_json = folium.GeoJson(nodeData)
# retrieve all names and store in popup
for feature_data in feature_access:
property_data = feature_data['properties']
geo_json.add_child(folium.Popup(property_data['name'))
geo_json.add_to(m)
对于遇到与我相同问题的任何人,最新的 folium 中有一个名为 "GeoJsonPopup" 的函数,它将从 JSON 文件中检索您指定的所有信息并将其显示在Popup,解决所有节点都会有自己唯一的个体信息的问题。
而不是创建一个 for 循环来循环整个 JSON,
# reading JSON file
with open('exportBuilding.geojson') as access_json:
read_content = json.load(access_json)
feature_access = read_content['features']
# Creating Folium Map
m = folium.Map(location=[1.400150, 103.910172], titles="Punggol", zoom_start=17)
nodeData = os.path.join('exportBuilding.geojson')
# This is retrieve all information, in this case is name from my JSON file
# and display it into my popup, such that all nodes
# will have its own unique information.
geo_json = folium.GeoJson(nodeData, popup=folium.GeoJsonPopup(fields=['name']))
geo_json.add_to(m)