Created
December 4, 2013 21:43
-
-
Save springmeyer/7796138 to your computer and use it in GitHub Desktop.
shapefile to geojson in node.js with mapnik
This file contains hidden or 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 geojsonStream = require('geojson-stream'); | |
var mapnik = require('mapnik'); | |
var fs = require('fs'); | |
var input = 'test/data/world_merc.shp'; | |
var output = './out.geojson'; | |
// set up geojson output stream | |
var fileOut = fs.createWriteStream(output); | |
var geojsonOut = geojsonStream.stringify(); | |
geojsonOut.pipe(fileOut); | |
// set up mapnik to read shapefile | |
var ds = new mapnik.Datasource({type:'shape',file:input}); | |
var featureset = ds.featureset() | |
var feat = featureset.next(); | |
// read all features | |
while (feat) { | |
geojsonOut.write(JSON.parse(feat.toJSON())); | |
feat = featureset.next(); | |
} | |
geojsonOut.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment