-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.go
177 lines (138 loc) · 2.91 KB
/
cli.go
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package main
import (
"fmt"
"strings"
)
var (
idfield string
selectfields arrayFlag
command string
inputfile string
basefile string
referencefile string
targetfile string
)
type arrayFlag []string
func (i *arrayFlag) String() string {
return strings.Join(*i, ",")
}
func (i *arrayFlag) Set(value string) error {
*i = append(*i, value)
return nil
}
func cli() {
p := func(s string, x ...any) {
println(fmt.Sprintf(s, x...))
}
if inputfile == "" {
panic("No -i (input file) given")
}
var err error
var out string
switch command {
case "bounds":
{
fmt.Println("bounds:", info_bounds(inputfile).ToJSON())
}
case "vectors-info":
{
fmt.Println("info:", vectors_info(inputfile))
}
case "subgeographies":
{
out, err = routine_subgeographies(p, inputfile, idfield)
}
case "zeros":
{
out, err = raster_zeros(inputfile, 1000, p)
}
case "strip":
{
if len(selectfields) == 0 {
panic("No -s (select fields) given.")
}
out, err = vectors_strip(inputfile, selectfields, p)
}
case "rasterise":
{
if targetfile == "" {
panic("No -t (targetfile) given:")
}
out, err = raster_geometry(inputfile, targetfile, p)
}
case "proximity":
{
if targetfile == "" {
panic("No -t (targetfile) given:")
}
r, _ := raster_geometry(inputfile, targetfile, p)
out, err = raster_proximity(r, p)
}
case "ids-raster":
{
out, err = raster_ids(inputfile, idfield, 1000, p)
}
case "clip":
{
if targetfile == "" {
panic("No -t (targetfile) given:")
}
out, err = vectors_clip(inputfile, targetfile, p)
}
case "csv":
{
if len(selectfields) == 0 {
panic("No -s (select fields) given.")
}
out, err = csv(inputfile, selectfields)
}
case "simplify":
{
if targetfile == "" {
panic("No -t (targetfile) given:")
}
out, err = vectors_simplify(inputfile, 0.01, p)
}
case "csv-points":
{
if len(selectfields) == 0 {
println("No -s (select fields) given.")
}
out, err = csv_points(inputfile, [2]string{"Longitude", "Latitude"}, selectfields)
}
case "admin-boundaries":
{
out, err = routine_admin_boundaries(nil, inputfile, idfield, 1000)
}
case "routine-clip-proximity":
{
if referencefile == "" {
panic("No -r (referencefile) given:")
}
out, err = routine_clip_proximity(p, inputfile, referencefile, []string{idfield}, 1000, 0.001)
}
case "routine-crop-raster":
{
if referencefile == "" {
panic("No -r (referencefile) given:")
}
if basefile == "" {
panic("No -r (referencefile) given:")
}
out, err = routine_crop_raster(nil, inputfile, basefile, referencefile, "{\"nodata\": -1, \"numbertype\": \"Int16\", \"resample\": \"average\"}", 1000)
}
case "s3put":
{
s3put(inputfile)
}
default:
{
println("No (valid) -c command given:", command)
}
}
if err != nil {
println(err.Error())
} else {
println(out)
}
}