-1

I would like to plot some data that I pulled from a Socrata source which contains geographic polygons for some neighbourhoods.

I have the data stored in a dataframe and I have built the folium map but I have no idea where to go next.

my demo_df.head() looks like this:

    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...```

and my folium map is built:

map_calgary = folium.Map(location=[latitude, longitude], zoom_start=11)
map_calgary

How do I plot the demo_df['the_geom'] column in folium?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
M A
  • 73
  • 1
  • 2
  • 10

1 Answers1

0

It appears the_geom values are represented as a valid GeoJSON objects meaning it could be visualized in folium via GeoJSON layer like this:

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)
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193