Skip to content

Instantly share code, notes, and snippets.

@fentas
Created July 4, 2015 11:03
Show Gist options
  • Save fentas/1ddb7946983255628bba to your computer and use it in GitHub Desktop.
Save fentas/1ddb7946983255628bba to your computer and use it in GitHub Desktop.
Download and output airport database as geojson (openflights.org)
#!/usr/bin/env node
var got = require('got'),
csv = require('csv-parser'),
through = require('through2'),
geojsonStream = require('geojson-stream');
/**
* Download and output airport database
*
* http://openflights.org/data.html#airport
*/
got('https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat')
.pipe(csv({
headers: [
'id',
'name',
'city',
'country',
'faa',
'icao',
'lat',
'lng',
'alt',
'tz-offset',
'dst',
'tz'
]
}))
.pipe(through.obj(function(row, enc, cb) {
this.push({
type: 'Feature',
properties: row,
geometry: {
type: 'Point',
coordinates: [
parseFloat(row.lng),
parseFloat(row.lat)
]
}
});
cb();
}))
.pipe(geojsonStream.stringify())
.pipe(process.stdout);
@fentas
Copy link
Author

fentas commented Jul 4, 2015

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