Choropleth地图除了空地图外什么都不显示

时间:2019-08-24 18:08:30

标签: folium choropleth

我试图从大叶植物中绘制出Choropleth贴图,但是它没有显示伦敦不同区的渐变颜色

shapefile链接(用于'statistical-gis-boundaries-london.zip'):https://data.london.gov.uk/dataset/statistical-gis-boundary-files-london

csv数据(使用'london-borough-profiles.csv'):https://data.london.gov.uk/dataset/london-borough-profiles

我使用了上述shapefile中的chropleth geojson数据,并通过我在网上偶然发现的代码将其转换为geojson。

import shapefile
# read the shapefile
fïlepath = "statistical-gis-boundaries-london/ESRI/London_Borough_Excluding_MHW.shp"
reader = shapefile.Reader(fïlepath)
fields = reader.fields[1:]
field_names = [field[0] for field in fields]
buffer = []
for sr in reader.shapeRecords():
   atr = dict(zip(field_names, sr.record))
   geom = sr.shape.__geo_interface__
   buffer.append(dict(type="Feature", \
    geometry=geom, properties=atr)) 

# write the GeoJSON file
from json import dumps
geojson = open("london-borough.json", "w")
geojson.write(dumps({"type": "FeatureCollection",\
"features": buffer}, indent=2) + "\n")
geojson.close()

我确保“ on_key”值和列中的列相同(相同数据)

完成数据清理:

state_data = pd.read_csv("london-borough-profiles.csv")
state_data = state_data[['Area_name', 'Population_density_(per_hectare)_2017']]
state_data['Population_density_(per_hectare)_2017'] = state_data['Population_density_(per_hectare)_2017'].replace(".",np.nan)
state_data['Population_density_(per_hectare)_2017'] = state_data['Population_density_(per_hectare)_2017'].astype(float)
state_data = state_data.dropna()

我认为这可能是因为geojson数据。

任何帮助将不胜感激。

m = folium.Map(location=[51.5074, -0.1278], zoom_start=10)
london_geo = "london-borough.json"
folium.Choropleth(
    geo_data=london_geo,
    name='choropleth',
    data=state_data,
    columns=['Area_name', 'Population_density_(per_hectare)_2017'],
    key_on='feature.properties.NAME',
    fill_color='YlGn',
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name='Population_density_(per_hectare)_2017'
).add_to(m)

folium.LayerControl().add_to(m)

m

没有错误消息,仅显示地图,各行政区没有颜色渐变

0 个答案:

没有答案