我想绘制一些我从Socrata来源中提取的数据,其中包含一些社区的地理多边形。
我将数据存储在数据框中,并且已经构建了大叶贴图,但是我不知道下一步该怎么做。
我的demo_df.head()
看起来像这样:
name fem_25_34 fem_35_44 fem_35_44 fem_45_54 fem_55_64 the_geom
0 MANCHESTER INDUSTRIAL 0 0 0 0 0 {'type': 'Polygon', 'coordinates': [[[-114.058...
1 EAST FAIRVIEW INDUSTRIAL 3 0 0 1 0 {'type': 'Polygon', 'coordinates': [[[-114.030...
2 CANADA OLYMPIC PARK 0 0 0 0 0 {'type': 'Polygon', 'coordinates': [[[-114.211...
3 FOOTHILLS 12 15 15 0 0 {'type': 'Polygon', 'coordinates': [[[-113.992...
4 SHEPARD INDUSTRIAL 13 8 8 22 32 {'type': 'Polygon', 'coordinates': [[[-113.997...```
构建了我的叶片图:
map_calgary = folium.Map(location=[latitude, longitude], zoom_start=11)
map_calgary
如何在叶片中绘制demo_df['the_geom']
列?
答案 0 :(得分:0)
似乎the_geom
值表示为有效的GeoJSON对象,这意味着可以通过GeoJSON layer在大叶中可视化它,如下所示:
from folium import folium
from folium.features import GeoJson
from pandas import DataFrame
# constructing demo_df DataFrame from Socrata source goes here..
#init map
m = folium.Map(location=[45.137451890638886,-68.13734351262877], zoom_start=5)
#iterate over DataFrame rows and add GeoJson layer
for index, row in demo_df.iterrows():
GeoJson(
row['the_geom'],
name='geojson'
).add_to(m)