简体   繁体   English

Python folium GeoJSON 地图未显示

[英]Python folium GeoJSON map not displaying

I'm trying to use a combination of geopandas, Pandas and Folium to create a polygon map that I can embed incorporate into a web page.我正在尝试使用 geopandas、Pandas 和 Folium 的组合来创建一个多边形地图,我可以将其嵌入到网页中。

For some reason, it's not displaying.出于某种原因,它没有显示。

The steps I've taken:我采取的步骤:

  1. Grabbed a .shp from the UK's OS for Parliamentary boundaries.从英国的操作系统中获取了一个 .shp 用于议会边界。

  2. I've then used geopandas to change the projection to epsg=4326 and then exported as GeoJSON which takes the following format:然后我使用 geopandas 将投影更改为 epsg=4326,然后导出为采用以下格式的 GeoJSON:

    { "type": "Feature", "properties": { "PCON13CD": "E14000532", "PCON13CDO": "A03", "PCON13NM": "Altrincham and Sale West" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -2.313999519326579, 53.357408280545918 ], [ -2.313941776174758, 53.358341455420039 ], [ -2.31519699483377, 53.359035664493433 ], [ -2.317953152796459, 53.359102954309151 ], [ -2.319855973429864, 53.358581917200119 ],... ] ] ] } },...

Then what I'd like to do is mesh this with a dataframe of constituencies in the following format, dty:然后我想做的是将其与以下格式的选区数据框 dty 进行网格化:

constituency        count
0   Burton          667
1   Cannock Chase   595
2   Cheltenham      22
3   Cheshire East   2
4   Congleton       1
5   Derbyshire Dales    1
6   East Staffordshire  4

import folium
mapf = folium.Map(width=700, height=370, tiles = "Stamen Toner", zoom_start=8, location=     ["53.0219392","-2.1597434"])


mapf.geo_json(geo_path="geo_json_shape2.json", 
              data_out="data.json", 
              data=dty, 
              columns=["constituency","count"], 
              key_on="feature.properties.PCON13NM.geometry.type.Polygon",
              fill_color='PuRd',
              fill_opacity=0.7, 
              line_opacity=0.2, 
              reset="True")

The output from mapf looks like: mapf 的输出如下所示:

mapf.json_data mapf.json_data

{'../../Crime_data/staffs_data92.json': [{'Burton': 667,
   'Cannock Chase': 595,
   'Cheltenham': 22,
   'Cheshire East': 2,
   'Congleton': 1,
   'Derbyshire Dales': 1,
   'East Staffordshire': 4,
   'Lichfield': 438,
   'Newcastle-under-Lyme': 543,
   'North Warwickshire': 1,
   'Shropshire': 17,
   'South Staffordshire': 358,
   'Stafford': 623,
   'Staffordshire Moorlands': 359,
   'Stoke-on-Trent Central': 1053,
   'Stoke-on-Trent North': 921,
   'Stoke-on-Trent South': 766,
   'Stone': 270,
   'Tamworth': 600,
   'Walsall': 1}]}

Although the mapf.create_map() function successfully creates a map, the polygons don't render.尽管 mapf.create_map() 函数成功创建了地图,但多边形不会渲染。

What debugging steps should I take?我应该采取哪些调试步骤?

@elksie5000, Try mplleaflet it is extremely straightforward. @elksie5000,试试mplleaflet,它非常简单。

pip install mplleaflet

in Jupyter/Ipython notebook:在 Jupyter/Ipython 笔记本中:

import mplleaflet
ax = geopandas_df.plot(column='variable_to_plot', scheme='QUANTILES', k=9, colormap='YlOrRd')
mplleaflet.show(fig=ax.figure)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM