#!/usr/bin/env python # coding: utf-8 # # Journey time Statistics # # https://www.gov.uk/government/collections/journey-time-statistics # # https://www.gov.uk/government/statistical-data-sets/journey-times-to-key-services-by-lower-super-output-area-jts05 # https://www.gov.uk/government/statistical-data-sets/journey-times-to-key-services-by-local-authority-jts04 # In[1]: from __future__ import division get_ipython().run_line_magic('matplotlib', 'inline') import pandas as pd # In[2]: gp='https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/485260/jts0505.xls' xl=pd.ExcelFile(gp) xl.sheet_names # In[3]: tname='JTS0505' dbd=xl.parse(tname,skiprows=6) dbd[:3] # In[4]: foodstore='https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/485262/jts0507.xls' xl=pd.ExcelFile(foodstore) xl.sheet_names # In[5]: tname='JTS0507' dbd2=xl.parse(tname,skiprows=6) iwfood=dbd2[dbd2['LA_Code']=='E06000046'] # In[6]: iwfood[:3] # In[7]: iw=dbd[dbd['LA_Code']=='E06000046'] # In[17]: import fiona code='E06000046' geojson='https://github.com/martinjc/UK-GeoJSON/raw/master/json/statistical/eng/lsoa_by_lad/{}.json'.format(code) get_ipython().system('wget {geojson}') #fi=fiona.open('../IWgeodata/wards_by_lad/E06000046.json') geojson_local='{}.json'.format(code) fi=fiona.open(geojson_local) centre_lat,centre_lon=((fi.bounds[0]+fi.bounds[2])/2,(fi.bounds[1]+fi.bounds[3])/2) # In[12]: import folium # In[24]: import folium m = folium.Map([centre_lon,centre_lat], zoom_start=11) m.choropleth( geo_path=geojson_local, data=iw, columns=['LSOA_code', 'GPPTt'], key_on='feature.properties.LSOA11CD', fill_color='PuBuGn', fill_opacity=1.0 ) ''' m.choropleth( geo_path=geojson_local, data=iwfood, columns=['LSOA_code', 'FoodPTt'], key_on='feature.properties.LSOA11CD', fill_color='PuBuGn', fill_opacity=1.0 ) ''' m # In[113]: import os import time from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait delay=5 fn='testmap.html' tmpurl='file://{path}/{mapfile}'.format(path=os.getcwd(),mapfile=fn) m.save(fn) browser = webdriver.Firefox() browser.get(tmpurl) #Give the map tiles some time to load time.sleep(delay) browser.save_screenshot('map.png') browser.quit() # In[ ]: