Skip to content

Instantly share code, notes, and snippets.

@JerrySievert
Created August 8, 2013 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JerrySievert/6189314 to your computer and use it in GitHub Desktop.
Save JerrySievert/6189314 to your computer and use it in GitHub Desktop.
building footprint processing for downtown portland
var JSONStream = require('JSONStream'),
fs = require('fs'),
Terraformer = require('Terraformer');
var incoming = fs.createReadStream("./buildings.json", { encoding: "utf8" });
var outgoing = fs.createWriteStream("./processed.json", { encoding: "utf8" });
var stream = JSONStream.parse(['features', true]);
var downtown = new Terraformer.Polygon(
[
[
[ -122.686858, 45.534251 ],
[ -122.682910, 45.534431 ],
[ -122.670207, 45.526194 ],
[ -122.669606, 45.522195 ],
[ -122.674541, 45.511851 ],
[ -122.671623, 45.507099 ],
[ -122.674413, 45.505745 ],
[ -122.681408, 45.506136 ],
[ -122.689605, 45.513204 ],
[ -122.685657, 45.522045 ],
[ -122.686772, 45.524270 ],
[ -122.686858, 45.534251 ]
]
]
);
outgoing.write('{ "type": "FeatureCollection", "features": [');
outgoing.write("\n");
stream.on('data', function (data) {
var primitive = new Terraformer.Primitive(data.geometry);
if (primitive.within(downtown)) {
outgoing.write(JSON.stringify(data) + ",\n");
}
});
stream.on('end', function () {
outgoing.write("] }\n");
outgoing.end();
});
incoming.pipe(stream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment