how to iterate over a shapefile in node.js -
i have following node.js code reads shapefile based on code (https://github.com/mbostock/shapefile)
var shp=require('shapefile'); var path="polygons.shp" var encoding="utf8" function readrecords(path, encoding) { return function() { var callback = this.callback; shp.read(path, encoding, function(error, header, records) { callback(error, records); }); }; }; var rs = readrecords(path,encoding) console.log(rs)
when execute above code : undefined
any idea of how iterate on such object?
you need read header before move reading records. bit of code logs entire shapefile console:
var shapefile = require( 'shapefile' ), reader = shapefile.reader( 'polygons' ); var logger = function( error, record ) { console.log( record ); if( record !== shapefile.end ) reader.readrecord( logger ); } reader.readheader( logger );