Skip to content

Instantly share code, notes, and snippets.

@sergiolucero
Last active November 24, 2020 03:40
Show Gist options
  • Save sergiolucero/bcb6c67d977942e7ab0cbe5846600990 to your computer and use it in GitHub Desktop.
Save sergiolucero/bcb6c67d977942e7ab0cbe5846600990 to your computer and use it in GitHub Desktop.
here isolines
from creds import ID,CODE # isolines: driving from my house
import folium
import requests
home =[-33.406654,-70.572701] # 085 LOS MILITARES / ALONSO DE CORDOVA
head = 'https://isoline.route.cit.api.here.com/routing/7.2/calculateisoline.json?'
URL_BASE = '{}app_id={}&app_code={}&mode=shortest;car;traffic:disabled&start=geo!{},{}&range={}&rangetype={}'
def isodata(home, range, type):
url = URL_BASE.format(head, ID, CODE, home[0],home[1], range, type)
js = requests.get(url).json()['response']
center = js['center'] # {'latitude': -33.406654, 'longitude': -70.572701}
iso = js['isoline']
comps = [(float(x.split(',')[0]),float(x.split(',')[1])) for x in iso[0]['component'][0]['shape']]
return comps
fm = folium.Map(location = home, zoom_start=13, tiles='CartoDBPositron')
for time, color in zip([60,300,600],['green','blue','red']): # 1,5,10 min
isoline = isodata(home, time, 'time')
folium.PolyLine(locations=isoline,color=color).add_to(fm)
fm.save('maida.html')
@sergiolucero
Copy link
Author

@sergiolucero
Copy link
Author

import branca.colormap as cm
colormap = cm.linear.Set1.scale(0, 30).to_step(5)
colormap.caption = 'A colormap caption'
fm.add_child(colormap)

@sergiolucero
Copy link
Author

All APIs listed here
Modes can be publicTransport, bicycle...

@kasper747
Copy link

Great example! Still works in 2018.
If you add the following code, it will even take into account the traffic situation in the rush hour time (in this example 2018-08-07T08:00:00 considered to be a time of high traffic - the start of working hours on a working day.)
&mode=fastest;car;traffic:enabled&departure=2018-08-07T08:00:00.

Works also with the free plan.

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