-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·101 lines (86 loc) · 2.7 KB
/
cli.js
File metadata and controls
executable file
·101 lines (86 loc) · 2.7 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Copyright ©️ 2019 GaltProject Society Construction and Terraforming Company
* (Founded by [Nikolai Popeka](https://github.com/npopeka)
*
* Copyright ©️ 2019 Galt•Core Blockchain Company
* (Founded by [Nikolai Popeka](https://github.com/npopeka) by
* [Basic Agreement](ipfs/QmaCiXUmSrP16Gz8Jdzq6AJESY1EAANmmwha15uR3c1bsS)).
*/
#!/usr/bin/env node
const Table = require('cli-table');
const utils = require('./src/common');
const latLon = require('./src/latLon');
const utm = require('./src/utm');
const ngeohash = require('ngeohash');
require('yargs')
.scriptName("galtproject-geodesic")
.usage('$0 <cmd> [args]')
.command('geohash [geohash]', 'describe geohash string', (yargs) => {
yargs.positional('geohash', {
type: 'string',
describe: 'geohash'
})
}, function (argv) {
printGeohashConversionTable(argv.geohash);
})
.command('geohash5 [geohash5]', 'describe geohash number', (yargs) => {
yargs.positional('geohash5', {
type: 'string',
describe: 'geohash5'
})
}, function (argv) {
printGeohash5ConversionTable(argv.geohash5);
})
.command('latlon [lat] [lon]', 'describe latitude and latitude', (yargs) => {
yargs.positional('lat', {
type: 'string',
describe: 'latitude'
})
.positional('lon', {
type: 'string',
describe: 'longitude'
})
}, function (argv) {
printLatLonConversionTable(argv.lat.replace(/[^-0-9. ]/g, ""), argv.lon.replace(/[^-0-9. ]/g, ""));
})
.help()
.argv;
function printGeohashConversionTable(geohash) {
const table = new Table({
head: ['Geohash', geohash],
colWidths: [20, 40]
});
const {latitude, longitude} = ngeohash.decode(geohash);
table.push(
['Geohash5', utils.geohashToNumber(geohash)],
['Lat/Lon', `${latitude} ${longitude}`],
['UTM', utm.toString(latLon.toUtm(latitude, longitude))]
);
console.log(table.toString());
}
function printGeohash5ConversionTable(geohash5) {
const table = new Table({
head: ['Geohash5', geohash5],
colWidths: [20, 40]
});
const {latitude, longitude} = ngeohash.decode(utils.numberToGeohash(geohash5));
table.push(
['Geohash', utils.numberToGeohash(geohash5)],
['Lat/Lon', `${latitude} ${longitude}`],
['UTM', utm.toString(latLon.toUtm(latitude, longitude))]
);
console.log(table.toString());
}
function printLatLonConversionTable(lat, lon) {
const table = new Table({
head: ['Lat/Lon', `${lat} ${lon}`],
colWidths: [20, 40]
});
const geohash = ngeohash.encode(lat, lon, '12');
table.push(
['Geohash', geohash],
['Geohash5', utils.geohashToNumber(geohash)],
['UTM', utm.toString(latLon.toUtm(parseInt(lat), parseInt(lon)))]
);
console.log(table.toString());
}