Skip to content

Instantly share code, notes, and snippets.

@defvol
Last active July 21, 2016 02:52
Show Gist options
  • Save defvol/8ea57cb723f990f0a3a881baa2d54af9 to your computer and use it in GitHub Desktop.
Save defvol/8ea57cb723f990f0a3a881baa2d54af9 to your computer and use it in GitHub Desktop.
Builds GeoJSON Feature objects from the profeco.precios dataset: http://datos.gob.mx/busca/dataset/quien-es-quien-en-los-precios
var es = require('event-stream')
var fs = require('fs')
var JSONStream = require('JSONStream')
var request = require('request')
function toGeoJSON(obj) {
var lon = parseFloat(obj.longitud);
var lat = parseFloat(obj.latitud);
if (!lon || !lat) return null;
return {
type: 'Feature',
properties: {
precio: obj.precio,
producto: obj.producto
},
geometry: {
type: 'Point',
coordinates: [ lon, lat ]
}
}
}
process.stdin
.pipe(JSONStream.parse('results.*'))
.pipe(es.mapSync((data) => {
var feature = toGeoJSON(data);
if (feature) console.log('%j', feature);
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment