Giter Site home page Giter Site logo

mapbox-isochrone's Introduction

isochrone

Isochrone generator built atop the Mapbox Matrix API, with CONREC polygonization. Calculates isochrones up to 1 hour of travel time.

Demo!

Setup

Clone the repository, and either

  • include dist/app.js in your markup directly, or
  • build your own via browserify index.js -o <filename>

For all pull requests that modify isochrone.js, please also rebuild dist/app.js to make sure your changes get applied.

Usage

isochrone(origin, options, callback)

  • origin Starting point for isochrone generation expressed as [lng, lat].

  • options

Parameter Required? Default Limits Description
token Yes n/a --- ๐Ÿ”‘ Mapbox user token
threshold Yes n/a min:1, max: 3600 โŒ›๏ธ Time thresholds for the desired ischrone(s), expressed in seconds. Can be expressed as either a) an array of numbers (e.g. [600, 1200, 1800]) to calculate isochrones at those specific time cutoffs, or b) a single number (e.g. 1800) to calculate isochrones at 60-second intervals, up to that time
mode No driving one of driving, cycling, or walking ๐Ÿš— ๐Ÿšฒ ๐Ÿ‘Ÿ Method of transportation desired, as defined in the Mapbox Matrix API documentation.
direction No divergent divergent or convergent โฌ‡๏ธ โฌ†๏ธ Direction of travel. Divergent isochrones are the total area reachable from the origin within the given time, while convergent ones cover the total area that can reach it.
resolution No An auto value, computed from mode and maximum threshold min:0.05, max: 5 ๐Ÿ“ Granularity of the underlying sample grid, in units of kilometers. Lower values yield finer results, but are more expensive in both query time and API request load. Scaling this value with both time threshold and transport mode is recommended.
batchSize No 25 min: 2 ๐Ÿ‘จ ๐Ÿ‘ฌ ๐Ÿ‘จโ€๐Ÿ‘ฆโ€๐Ÿ‘ฆ Number of coordinates per Matrix API request. The default value applies for most Mapbox starter plans. Higher values will speed up computation and avoid rate-limiting issues.
  • callback

Function to execute once the calculation completes.

Example

This requests a set of isochrones at 1-minute intervals up to 30 minutes, from near Sacramento, CA:

	isochrone([-121.4738,38.6194], {"token":<token>, "threshold":1800}, function(err, output){
		if (err) throw err;
		console.log(output);
	})

Output

Isochrones are returned as a GeoJSON featurecollection of polygon features. Each feature contains a time parameter that corresponds to its threshold in seconds.

mapbox-isochrone's People

Contributors

alaingilbert avatar heystenson avatar michieldemey avatar peter avatar peterqliu avatar petersirota avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapbox-isochrone's Issues

Deprecate?

I wasn't aware of the existence of the Mapbox Isochrone API when I landed on this. It would really be worth at least mentioning it at the top of the README, so people know that using this client-side method probably isn't the best solution for their situation.

NPM package?

Is this package available on NPM? I can't find it. The package.json gives "isochrone" as the name, but that seems to be a different library. It's also not at @mapbox/isochrone.

Too many requests

Following up on the ambiguous-yet-earnest #9, I looked at the responses to the looped directions API call. I logged the error associated with the call and found this:

"message":"Too Many Requests"

@peterqliu did the platform team feel this module was hammering the API too hard and lock usage down? Any single call still works fine.

A subway option for mode?

Hi, I like this plugin very much. I wonder if there is a subway option so I can map the area within 20 mins subway.

Not able to use it

I imported the file app.js in code.
and tried passing

`var state = {
token: '',
debug: window.location.search.indexOf('debug')>-1,
mode: 'driving',
direction:'divergent',
threshold: 3600,
resolution: 1.5,
batchSize: 400,
inspector: false
};

isochrone([12.957194522,77.5682954863], state, function(output){
console.log(output);
})`

but I am getting an error
Uncaught TypeError: Cannot read property 'durations' of undefined
at Object. (app.js:157)
at Dispatch.call (app.js:2266)
at XMLHttpRequest.respond (app.js:2516)

my call is
https://api.mapbox.com/directions-matrix/v1/mapbox/driving/12.9572,77.5683;12.9572,77.5683;12.9572,77.5873;13.0454,77.5683;13.0454,77.5873?sources=0&destinations=all&access_token=

I am new to this and jsin particular kindly help me.

traffic-aware isochrones?

What would be the obstacles to drawing traffic-aware isochrones by using the driving-traffic profile? Is the 10x10, 30/min limit too restrictive for good results?

rate limiting w/ enterprise

I have been trying to use the isochrone API to generate 10-minute walking isochrones using a list of coordinate pairs but my attempt fails even while iterating over a small number (such as 5) points. I have an enterprise account so should there should be a very high rate limit.

The script will execute the first time on 5 points, but on the second try and subsequent tries, it will throw the following error from isochrone.js :

            'data': resp.durations[0],
                        ^
      TypeError: Cannot read property 'durations' of undefined

If I include a geojson with many points (such as 100), it will fail every time.

Any ideas on how to solve this?
I have included both the geojson that I am iterating over and the modified index.js file below:

index.js

isochrone = require('./isochrone.js');
var turf = require('@turf/turf');
var fs = require('fs'),
obj

token = 'mytoken'

fs.readFile('poi.geojson', handleFile);
fts = []

function handleFile(err, data) {
    if (err) throw err
    obj = JSON.parse(data)
    features = obj.features
    console.log(features.length)

    for (var j = 0; j <features.length; j++) {

    	console.log(j)
	
		coords = features[j].geometry.coordinates

		isochrone(coords, {"token":token, "threshold":[600], "mode":"walking", batchSize:25}, function(err, output){
			
			if (err) console.log("not throwing error");
				
			output = output.features
			console.log(output)
			fts.push(output[0]);
			

			 if (j >= features.length){console.log('made it to the end')
			 	
		 	var collection = JSON.stringify({
			features: fts,
     	    type: 'FeatureCollection'
			});

		 	fs.writeFileSync('isochrones.geojson', collection);

			 }
		});	

   }

}

poi.geojson

{
"type": "FeatureCollection",
"name": "poi",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "stop_id": 6, "stop_name": "Jackson & Lotus", "stop_lat": 41.876513, "stop_lon": -87.761446 }, "geometry": { "type": "Point", "coordinates": [ -87.761446, 41.876513 ] } },
{ "type": "Feature", "properties": { "stop_id": 2, "stop_name": "5900 W Jackson", "stop_lat": 41.87706679, "stop_lon": -87.77131794 }, "geometry": { "type": "Point", "coordinates": [ -87.77131794, 41.87706679 ] } },
{ "type": "Feature", "properties": { "stop_id": 1, "stop_name": "Jackson & Austin Terminal", "stop_lat": 41.87632184, "stop_lon": -87.77410482000001 }, "geometry": { "type": "Point", "coordinates": [ -87.77410482, 41.87632184 ] } },
{ "type": "Feature", "properties": { "stop_id": 4, "stop_name": "5700 W Jackson", "stop_lat": 41.87702418, "stop_lon": -87.76745055000001 }, "geometry": { "type": "Point", "coordinates": [ -87.76745055, 41.87702418 ] } },
{ "type": "Feature", "properties": { "stop_id": 3, "stop_name": "Jackson & Menard", "stop_lat": 41.87695725, "stop_lon": -87.76975039 }, "geometry": { "type": "Point", "coordinates": [ -87.76975039, 41.87695725 ] } }
]
}

Would mapbox be interested in faster isochrones?

A little unorthodox perhaps, but a while ago for my own project I built isochrones that solves/sends results O(log(n))

https://isochrones.regia.io/

Would mapbox be interested? I would love to continue working on this and perhaps open source (ideal). Current what I am showing is only Utah, and tops 30 min, but given more time, it could render on the gpu rather than svg's and also I tested with 3 hour isochrones and it's still pretty instant (less than a second locally)

edit - also I used an OSRM like algorithm in that the accuracy is down to the second on the road

Distance is required

Error: distance is required
    at distanceToRadians (index.js?70ad:402)
    at module.exports (index.js?2faa:45)
    at makeGrid (index.js?99b1:13)
    at isochrone (index.js?99b1:94)
    at VueComponent.created (HelloWorld.vue?18db:25)
    at callHook (vue.esm.js?efeb:2895)
    at VueComponent.Vue._init (vue.esm.js?efeb:4560)
    at new VueComponent (vue.esm.js?efeb:4728)
    at createComponentInstanceForVnode (vue.esm.js?efeb:4242)
    at init (vue.esm.js?efeb:4059)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.