我有以下 node.js 代码,它根据来自 ( https://github.com/mbostock/shapefile ) 的代码读取 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)
当我执行上面的代码时,我得到:未定义
知道如何迭代这样的对象吗?
在开始阅读记录之前,您需要先阅读标题。这段代码将整个 shapefile 记录到控制台:
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 );
我是一名优秀的程序员,十分优秀!