-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform.js
71 lines (60 loc) · 1.93 KB
/
transform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const fs = require('fs');
const converter = require('./index.js');
const configFile = process.argv.length == 3 ? process.argv[2] : 'configuration.default.json';
console.log('Reading configuration from ', configFile);
let config;
try {
config = JSON.parse(fs.readFileSync(configFile));
}
catch(err) {
console.error('Error while reading config file from ', configFile);
process.exit(1);
}
if( ! config.originalProjection ) {
console.error('Bad configuration, miss <defaultOriginalProjection>');
process.exit(3);
}
if( ! config.finalProjection ) {
console.error('Bad configuration, miss <defaultFinalProjection>');
process.exit(3);
}
if( ! config.inputPath ) {
console.error('Bad configuration, miss <inputPath>');
process.exit(3);
}
if( ! config.outputPath ) {
console.error('Bad configuration, miss <outputPath>');
process.exit(3);
}
if( ! config.lonCol ) {
console.error('Bad configuration, miss <lonCol>');
process.exit(3);
}
if( ! config.latCol ) {
console.error('Bad configuration, miss <latCol>');
process.exit(3);
}
try {
console.log('Reading from ', config.inputPath);
const inputData = fs.readFileSync(config.inputPath);
console.log('Converting...');
converter.transformCSV(inputData, config.latCol, config.lonCol, config.originalProjection, config.finalProjection)
.then((convertedCSV) => {
try {
//console.log(convertedCSV);
console.log('Writing reuslt to', config.outputPath);
fs.writeFileSync(config.outputPath, convertedCSV);
}
catch(err) {
console.error('Error writing data to ', config.outputPath, ': ', err);
}
})
.catch((err) => {
console.error('Error processing data: ', err);
process.exit(2);
});
}
catch(err) {
console.error('Error reading data form ', config.inputPath, ': ', err);
}