Last active
December 12, 2018 16:34
-
-
Save miccferr/77185c3009b0fc7f70853ca4ef05d5df to your computer and use it in GitHub Desktop.
Using JSONStream to read/filter/write a GeoJSON. Outputs only Polygon geometries.
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
const fs = require('fs'); | |
const JSONStream = require('JSONStream'); | |
const es = require('event-stream') | |
let stream = fs.createReadStream('./data/kensington/kensington.geojson', {encoding: 'utf8'}); | |
let WriteStream =fs.createWriteStream('./data/kensington/kensington_clean.geojson', {encoding: 'utf8'}); | |
let open = '{"type":"FeatureCollection","features":[', | |
close = ']}'; | |
let transformStream =JSONStream.stringify(open, '\n,\n', close); | |
let filterOutMultiPolygons= type=> { | |
if (type.geometry.type == 'Polygon') | |
return type | |
} | |
let parser = JSONStream.parse('features.*', filterOutMultiPolygons); | |
stream.pipe(parser).pipe(transformStream).pipe(WriteStream); | |
//parser.on('data', d =>d ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment