drewfustin / isocronut

For a given geospatial location, calculate an isochrone (same time) contour around it.
97 stars 44 forks source link

isocronut

For a given geospatial location, calculate an isochrone (same time) contour around it. Any point on an x-minute isochrone contour should take a total of x minutes of travel to reach from the origin. Any point within an x-minute contour should be reachable in fewer than x minutes.

Update: Javascript implementation

Thanks to help from wolframteetz, I've also created a more useable Mapbox/turf.js implementation which allows you to just click on a spot on a map and it calculates 30/60/90/120 minute isochrones real-time. It lives inside MapboxIsochrones.html. You can change the desired isochrone limits by editing the html itself. Also, make sure to insert your Mapbox access token into the html.

If you want to try it out yourself and are a Python noob, put the .html file in a folder. From the terminal, cd to that folder. If you're running Python 2, enter the command

python -m SimpleHTTPServer

or if you're running Python 3, enter the command

python3 -m http.server

Go to your favorite browser, and point it to http://localhost:8000/MapboxIsochrones.html. Click away on the map.

Use

import isocronut

origin = '111 W Washington, Chicago'
duration = 10

isochrone = isocronut.get_isochrone(origin, duration)
print isochrone

or generate your own html file with an embedded Google Maps with isochrone (which will be written to isochrone.html in the current directory):

import isocronut

origin = '111 W Washington, Chicago'
duration = 10

isochrone = isocronut.generate_isochrone_map(origin, duration)
print isochrone

Parameters

origin : Google Maps parseable origination address (str) or [lat, lng] 2-list ([scalar, scalar])

duration : Number of minutes (scalar) for the isochrone contour

number_of_angles : Number of points defining the isochrone (int) -- think of it as a resolution, default: 12

tolerance : Number of minutes (scalar) that a test point can be away from duration to be considered acceptable, default: 0.1

__access_type__ : Either 'personal' or 'business' (str), specifying if you are using a personal or business API access for Google Maps (GeoCode API), default: 'personal'

[api]
api_number=<your api number>
[api]
client_id=<your client id>
crypto_key=<your crypto key>

__config_path__ : Path location (str) of the 'google_maps.cfg' file, default 'config/'

Returns

Isochrone contour as a list of [lat, lng] 2-lists -- [[lat1, lng1], [lat2, lng2], ..., [latn, lngn]] where n = number_of_angles.

Dependencies

This module makes use of the following Python modules that you must have installed.