Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created February 19, 2015 18:45
Show Gist options
  • Save tmcw/1f2c5f5eb5b1cc8f4019 to your computer and use it in GitHub Desktop.
Save tmcw/1f2c5f5eb5b1cc8f4019 to your computer and use it in GitHub Desktop.
var dowel = require('dowel'); // get it? joins? dowel? ugh
var mydata = require('./data.geojson');
var csvParser = require('csv-parser');
/**
* okay so i have this dataset that's tabular
* it's basically like
*
* country | value
* usa | 5
* spain | 2
*
* and i want to make a choropleth map of it
*/
var joined = dowel.join(mydata, dowel.countries, {
left: 'country',
right: 'country'
});
/**
* so now the variable 'joined' is a geojson of
* countries with properties from your dataset
* mydata joined to them.
*
* let's visualize the data.
*/
var turf = require('turf');
var categorized = turf.categorize(joined, 'val', 'jenks', 5, 'class');
/**
* Now the data is the geojson of countries with a 'class'
* column of it broken up by values of the property 'val'.
* Finally we want to visualize it.
*/
var colored = turf.helpers.color(categorized, 'class', 'RdGn', 'fill');
/**
* And now it has a simplestyle-spec "fill" property which will
* make it styled in Mapbox.js and Mapbox GL.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment