Folium程序没有运行

时间:2016-05-26 14:28:35

标签: python leaflet folium

我试图创建一个python程序,生成一个传单Web地图,其中一些点数据作为热图以及一些边界数据作为GeoJson。当我在python中运行下面的代码时,我得到一些错误如下:

#---------------------------------------------------------------------------

    ----
# Name:
# Purpose:
#-------------------------------------------------------------------------------
import json
import folium

from folium.plugins import HeatMap
from folium.plugins import MarkerCluster

# Read the geojson file with mpesa data
src = json.load(open('pollstations.geojson'))

# Loop through the data structure extracting coordinates
# "features": [
# { "properties": {"GPS_Latitu":-0.100300,"GPS_Longit":34.751370,"Other_Busi": null..

coords, popup = [], []
for row in src['features']:
    popup.append(row['properties']['Polling_St'], row['properties']['Ward'], row['properties']['Constituenc'], row['properties']['County'])
    coords.append((row['properties']['Latitude'], row['properties']['Longitude']))

# Create a map instance
mp = folium.Map([0.0236, 37.9062], zoom_start = 6)

# Create feature groups for layer controls
kenH = folium.FeatureGroup("Heatmap")
kenC = folium.FeatureGroup("Cluster")
kenW = folium.FeatureGroup("Wards")
kenA = folium.FeatureGroup("Constituency")
kenB = folium.FeatureGroup("County")

kenC.add_children(MarkerCluster(locations=coords, popups=popup))
kenH.add_children(HeatMap(coords))

folium.GeoJson(open("counties.geojson"), name = "County").add_to(kenB)
folium.GeoJson(open("constituencies.geojson"), name = "Constituency").add_to(kenA)
folium.GeoJson(open("wards.geojson"), name = "Wards").add_to(kenW)

mp.add_children(kenB)
mp.add_children(kenA)
mp.add_children(kenW)
mp.add_children(kenmC)
mp.add_children(kenH)

mp.add_children(folium.LayerControl())

mp.save("pollingstations_kenya.html")

这是python代码。

setTimeout

1 个答案:

答案 0 :(得分:0)

试  open('pollstations.geojson', encoding="utf-8")open('pollstations.geojson', encoding = "ISO-8859-1"),还要检查标记名称,县或国家/地区?