Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion bin/here-xyz.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,21 @@ program

if (options.file) {
var fs = require('fs');
if(options.file.indexOf(".shp")!=-1){
if(options.file.indexOf(".geojsonl")!=-1){
transform.readLineFromFile(options.file,function(result,isCompleted){
const totalFeatures = result.reduce(function (features, feature) {
if(feature.type=="Feature"){
features.push(feature);
}else if(feature.type=="FeatureCollection"){
features=features.concat(feature.features);
}else{
console.log("Unknown type"+feature.type);
}
return features
}, []);
uploadData(id,options,tags,{type:"FeatureCollection",features:totalFeatures},true,options.ptag,options.file,options.id);
},100);
}else if(options.file.indexOf(".shp")!=-1){
transform.readShapeFile(options.file,function(result){
uploadData(id,options,tags,result,true,options.ptag,options.file,options.id);
},true);
Expand Down
52 changes: 51 additions & 1 deletion bin/transformutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,53 @@ function readDataFromFile(path,callBack,needConversion){
callBack(file_data);
}


function readData(path,postfix){
return new Promise((resolve,reject)=>{
if(path.indexOf("http://")!=-1 || path.indexOf("https://")!=-1){
const request = require('request');
const fs = require('fs');
const tmp = require('tmp');
tmp.file({ mode: 0644, prefix: '', postfix: postfix }, function _tempFileCreated(err, tempFilePath, fd) {
if (err) throw err;
const dest = fs.createWriteStream(tempFilePath);
dest.on('finish', function (e) {
resolve(tempFilePath);
});
request.get(path)
.on('error', function(err) {
console.log(err)
}).pipe(dest);
});
}else{
resolve(path);
}
});

}

/*
chunckSize should be used later to stream data
*/
function readLineFromFile(incomingPath,callBack,chunckSize=100) {
readData(incomingPath,'geojsonl').then(path=>{
const dataArray=new Array();
const fs = require('fs'),
readline = require('readline'),
instream = fs.createReadStream(path),
outstream = new (require('stream'))(),
rl = readline.createInterface(instream, outstream);

rl.on('line', function (line) {
dataArray.push(JSON.parse(line));
});

rl.on('close', function (line) {
callBack(dataArray,true);
});
});
}

function dataToJson(file_data){
var csvjson = require('csvjson');
var options = {
Expand Down Expand Up @@ -186,4 +233,7 @@ function isLon(k){
}
module.exports.read = read;
module.exports.transform = transform;
module.exports.readShapeFile = readShapeFile
module.exports.readShapeFile = readShapeFile
module.exports.readLineFromFile = readLineFromFile


5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"open": "0.0.5",
"project-version": "1.2.0",
"prompt": "^1.0.0",
"readline": "1.3.0",
"request": "^2.83.0",
"shapefile": "0.6.6",
"tmp": "0.0.33",
Expand Down