Skip to content

Instantly share code, notes, and snippets.

@morganherlocker
Created March 6, 2018 22:27
Show Gist options
  • Save morganherlocker/bc506c813c946788b587f60f4ac66eec to your computer and use it in GitHub Desktop.
Save morganherlocker/bc506c813c946788b587f60f4ac66eec to your computer and use it in GitHub Desktop.
cat line-delimitted-geo-data.json | node to-collection.js > valid-geojson.json
var fs = require('fs');
var byline = require('byline');
var through2 = require('through2');
// write beginning of featurecollection
process.stdout.write('{"type":"FeatureCollection","features":[');
var first = true;
process.stdin
.pipe(byline.createStream())
.pipe(through2(function(chunk, enc, next){
if (first) process.stdout.write(chunk.toString());
else process.stdout.write(','+chunk.toString());
first = false;
next();
}))
.on('finish', function(){
process.stdout.write(']}\n');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment