Skip to content

Instantly share code, notes, and snippets.

@drcjar
Last active December 23, 2015 10:19
Show Gist options
  • Save drcjar/6621154 to your computer and use it in GitHub Desktop.
Save drcjar/6621154 to your computer and use it in GitHub Desktop.
Asthma Choropleth

Let's make an Asthma Choropleth using open data, ogr2ogr, folium and pandas (and indirectly leaflet.js, d3.js, GeoJSON, open street maps and moar) and talk about using gist and blocks..

  1. get UK Asthma data http://customer.instantatlas.com/INHALE/dataviews/ for this example I use dataView12_17.csv

  2. get some CCG map boundaries

    wget 'https://geoportal.statistics.gov.uk/Docs/Boundaries/Clinical_commissioning_groups_(Eng)_Apr_2013_Boundaries_(Generalised_Clipped).zip'
    
  3. make CCG map boundaries into GeoJSON format

    ogr2ogr -f 'ESRI Shapefile' -t_srs 'EPSG:4326' ccgs_4326.shp CCG_APR_2013_EN_BFE.shp
    ogr2ogr -f GeoJSON ccgs.json ccgs_4326.shp
    
  4. load the UK Asthma data .csv into a pandas dataframe and add a CCG column id so it can join up with GeoJSON. See the Gist for the python code to generate the dataframe.

  5. make the choropleth using folium magic python code

    map = folium.Map(location=[54.2, -2.45], zoom_start=5)
    map.geo_json(geo_path=ccg_geo, data_out='data1.json', data=df1,
          columns=['CCG13CD', 'Asthma emergency admissions per 1,000 population(2011)'],
          key_on='feature.properties.CCG13CD',
          fill_color='PuBu', fill_opacity=0.7, line_opacity=0.3,
          legend_name='Asthma emergency admissions per 1,000 population(2011)')
    map.create_map(path='map_1.html')
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment