0

我正在尝试制作一个 python 程序,该程序生成一个带有一些点数据作为热图以及一些边界数据作为 GeoJson 的传单网络地图。当我在 python 中运行下面的代码时,我得到一些错误如下:

Traceback (most recent call last):
  File "pollingstations.py", line 12, in <module>
    src = json.load(open('pollstations.geojson'))
  File "C:\Python27\ArcGIS10.3\lib\json\__init__.py", line 290, in load
    **kw)
  File "C:\Python27\ArcGIS10.3\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\ArcGIS10.3\lib\json\decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\ArcGIS10.3\lib\json\decoder.py", line 381, in raw_decode
    obj, end = self.scan_once(s, idx)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xcd in position 2: invalid continuation byte

这是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")
4

1 回答 1

0

试试 open('pollstations.geojson', encoding="utf-8")or open('pollstations.geojson', encoding = "ISO-8859-1"),再加上检查标签名称、县或国家?

于 2016-05-27T07:57:58.860 回答