Last active
July 21, 2016 02:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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