var fs = require('fs'), path = require('path'); fs.readFile(__dirname + '/test.txt', {flag: 'r+', encoding: 'utf8'}, function (err, data) { if(err) { console.error(err); return; } console.log(data); }); var shapefile = require("shapefile"); let allshape = [] shapefile.open(__dirname+"/tl_2017_us_county.shp") .then(source => source.read() .then(function log(result) { if (result.done) { console.log(allshape.length) Allwritefile(allshape) return }; allshape.push(result.value) return source.read().then(log); })) .catch(error => console.error(error.stack)); let d3 = require("d3"); function Allwritefile(allshape){ let count = 0 var w_data = "" var xValue = function(d) {return d[0];} var yValue = function(d) {return d[1];} for(let i =0;i=3000&&i<4000){ if(i%100==0){ console.log(i) } let thisshape = allshape[i] thisshape.bbox = [ d3.min(thisshape.geometry.coordinates[0], xValue), d3.min(thisshape.geometry.coordinates[0], yValue), d3.max(thisshape.geometry.coordinates[0], xValue), d3.max(thisshape.geometry.coordinates[0], yValue)] w_data = w_data + thisshape.properties.COUNTYFP+","+thisshape.properties.COUNTYNS+";" for(let j =0 ; j