-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgconv.sh
More file actions
executable file
·311 lines (303 loc) · 14 KB
/
Copy pathgconv.sh
File metadata and controls
executable file
·311 lines (303 loc) · 14 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/bash
#
# versione 1.0
# data 18/02/2021
# autore MSeverin
# co-autore DZuliani
#
#########################################################################################
# VARIABILI
#########################################################################################
ONLY_TITLE="GCONV"
BTITLE="$ONLY_TITLE 1.0 by MSeverin"
PATH_OUT="$HOME/Desktop"
PATH_FILE="$HOME/github/gconv/test.csv"
FILE_NAME="out_file"
EPSG_IN="4326"
EPSG_OUT="32633"
TYPE="s/f"
SEP=","
QUE1="no"
QUE2="si"
QUE3="no"
QUE4="1"
#########################################################################################
# VARIABILI DI FORMATTAZIONE
#########################################################################################
sottolineato=$(tput smul) # attiva il sottolineato
nonsottolineato=$(tput rmul) # disattiva il sottolineato
grassetto=$(tput bold) # attiva il grassetto
inverso=$(tput rev) # attiva la modalità inversa
normale=$(tput sgr0) # annulla tutti gli effetti e torna al default
txtrosso=$(tput setaf 1) # carattere rosso
txtverde=$(tput setaf 2) # carattere verde
txtgiallo=$(tput setaf 3) # carattere giallo
txtblu=$(tput setaf 4) # carattere blu
txtporpora=$(tput setaf 5) # carattere porpora
txtciano=$(tput setaf 6) # carattere ciano (azzurro)
txtbianco=$(tput setaf 7) # carattere bianco
txtsforosso=$(tput setab 1) # sfondo carattere rosso
txtsfoverde=$(tput setab 2) # sfondo carattere verde
txtsfogiallo=$(tput setab 3) # sfondo carattere giallo
txtsfoblu=$(tput setab 4) # sfondo carattere blu
txtsfoporpora=$(tput setab 5) # sfondo carattere porpora
txtsfociano=$(tput setab 6) # sfondo carattere ciano (azzurro)
txtsfobianco=$(tput setab 7) # sfondo carattere bianco
#########################################################################################
# FUNZIONI DI DIALOGO RICORSIVE
#########################################################################################
PATH_FILE,QUE1,SEP,EPSG_GEOGR,EPSG_IN,FILE_NAME,TYPE (){
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci il path con il file da convertire:${normale} (default $PATH_FILE) "
if [[ $REPLY ]]; then
PATH_FILE=$REPLY
fi
echo " ${grassetto}${txtverde}$PATH_FILE${normale}"
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Vuoi vedere le prime 5 righe del file? (si/no)${normale} (default $QUE1) "
if [[ $REPLY ]]; then
QUE1=$REPLY
fi
echo " ${grassetto}${txtverde}$QUE1${normale}"
if [ $QUE1 = "si" ]; then
cat $PATH_FILE | gawk 'NR>=1 && NR<=5 {print $0}' | gawk -F $SEP '{printf ("%5d,",$1); print $2","$3","$4}'
echo ""
else [ $QUE1 != "no" ];
fi
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci il separatore:${normale} (default $SEP) "
if [[ $REPLY ]]; then
SEP=$REPLY
fi
echo " ${grassetto}${txtverde}il separatore è $SEP${normale}"
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci EPSG del file in entrata:${normale} (default $EPSG_IN): "
if [[ $REPLY ]]; then
EPSG_IN=$REPLY
fi
echo " ${grassetto}${txtverde}$EPSG_IN${normale}"
}
PATH_FILE,QUE1,SEP,EPSG_GEOGR,EPSG_OUT,FILE_NAME,TYPE (){
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci il path con il file da convertire:${normale} (default $PATH_FILE) "
if [[ $REPLY ]]; then
PATH_FILE=$REPLY
fi
echo " ${grassetto}${txtverde}$PATH_FILE${normale}"
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Vuoi vedere le prime 5 righe del file? (si/no)${normale} (default $QUE1) "
if [[ $REPLY ]]; then
QUE1=$REPLY
fi
echo " ${grassetto}${txtverde}$QUE1${normale}"
if [ $QUE1 = "si" ]; then
cat $PATH_FILE | gawk 'NR>=1 && NR<=5 {print $0}' | gawk -F $SEP '{printf ("%5d,",$1); print $2","$3","$4}'
echo ""
else [ $QUE1 != "no" ];
fi
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci il separatore:${normale} (default $SEP) "
if [[ $REPLY ]]; then
SEP=$REPLY
fi
echo " ${grassetto}${txtverde}il separatore è $SEP${normale}"
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci EPSG del file in uscita:${normale} (default $EPSG_OUT) "
if [[ $REPLY ]]; then
EPSG_OUT=$REPLY
fi
echo " ${grassetto}${txtverde}$EPSG_OUT${normale}"
}
PATH_FILE,QUE1,SEP,EPSG_GEOGR,EPSG_IN,EPSG_OUT,FILE_NAME,TYPE (){
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci il path con il file da convertire:${normale} (default $PATH_FILE) "
if [[ $REPLY ]]; then
PATH_FILE=$REPLY
fi
echo " ${grassetto}${txtverde}$PATH_FILE${normale}"
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Vuoi vedere le prime 5 righe del file? (si/no)${normale} (default $QUE1) "
if [[ $REPLY ]]; then
QUE1=$REPLY
fi
echo " ${grassetto}${txtverde}$QUE1${normale}"
if [ $QUE1 = "si" ]; then
cat $PATH_FILE | gawk 'NR>=1 && NR<=5 {print $0}' | gawk -F $SEP '{printf ("%5d,",$1); print $2","$3","$4}'
echo ""
else [ $QUE1 != "no" ];
fi
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci il separatore:${normale} (default $SEP) "
if [[ $REPLY ]]; then
SEP=$REPLY
fi
echo " ${grassetto}${txtverde}il separatore è $SEP${normale}"
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci EPSG del file in entrata:${normale} (default $EPSG_IN) "
if [[ $REPLY ]]; then
EPSG_IN=$REPLY
fi
echo " ${grassetto}${txtverde}$EPSG_IN${normale}"
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci EPSG del file in uscita:${normale} (default $EPSG_OUT) "
if [[ $REPLY ]]; then
EPSG_OUT=$REPLY
fi
echo " ${grassetto}${txtverde}$EPSG_OUT${normale}"
}
#########################################################################################
clear
echo ""
echo -e "${txtsfoblu}${grassetto}$ONLY_TITLE${normale}"
echo -e "${normale}Questo tool permette la conversione di coordinate a partire da un file *.csv"
echo -e "${normale}Si può inserire un file *.csv di coordinate Piane, Geografiche o Geocentriche e viceversa."
echo ""
PATH_FILE,QUE1,SEP,EPSG_GEOGR,EPSG_IN,EPSG_OUT,FILE_NAME,TYPE
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Vuoi vedere le prime 5 righe del file in uscita? (si/no)${normale} (default $QUE3) "
if [[ $REPLY ]]; then
QUE3=$REPLY
fi
echo " ${grassetto}${txtverde}$QUE3${normale}"
if [[ $QUE3 = "si" ]]; then
if [[ $EPSG_IN = 4328 ]]; then
# conversione da geocentriche a ...
# conversione da geocentriche a geografiche
if [[ $EPSG_OUT = 4326 ]] || [[ $EPSG_OUT = 3857 ]]; then
head -n 5 $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$2" "$3" "$4" \
| cs2cs -f '%.8f' +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.8f\t%10.8f\t%8.3f\n", $3, $2, $4)}'
else
# conversione da geocentriche a piane
head -n 5 $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$3" "$2" "$4" \
| cs2cs -r +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.3f\t%10.3f\t%8.3f\n", $2, $3, $4)}'
fi
elif [[ $EPSG_IN = 4326 ]] || [[ $EPSG_IN = 3857 ]]; then
# conversione da geografiche a ...
# conversione da geografiche a geocentriche
if [[ $EPSG_OUT = 4328 ]]; then
head -n 5 $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$3" "$2" "$4" \
| cs2cs +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.3f\t%10.3f\t%8.3f\n", $2, $3, $4)}'
else
# conversione da geografiche a piane
head -n 5 $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$3" "$2" "$4" \
| cs2cs +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.3f\t%10.3f\t%8.3f\n", $2, $3, $4)}'
fi
else
# conversione da piane a ...
if [[ $EPSG_OUT = 4328 ]]; then
# comando di conversione da piane a geocentriche
head -n 5 $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$3" "$2" "$4" \
| cs2cs -r +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.3f\t%10.3f\t%8.3f\n", $2, $3, $4)}'
elif [[ $EPSG_OUT = 4326 ]] || [[ $EPSG_OUT = 3857 ]]; then
# comando di conversione da piane a geografiche
head -n 5 $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$2" "$3" "$4" \
| cs2cs -f '%.8f' +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.8f\t%10.8f\t%8.3f\n", $3, $2, $4)}'
else
# comando di conversione da piane a piane
head -n 5 $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$3" "$2" "$4" \
| cs2cs -r +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.3f\t%10.3f\t%8.3f\n", $2, $3, $4)}'
fi
fi
else [[ $QUE3 != "no" ]];
fi
echo ""
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Vuoi salvarlo in un file? (si/no)${normale} (default $QUE2) "
if [[ $REPLY ]]; then
QUE2=$REPLY
fi
echo " ${grassetto}${txtverde}$QUE2${normale}"
if [ $QUE2 = "si" ]; then
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci il path di uscita:${normale} (default $PATH_OUT) "
if [[ $REPLY ]]; then
PATH_OUT=$REPLY
fi
echo " ${grassetto}${txtverde}$PATH_OUT${normale}"
read -p "${grassetto}${txtverde}-->${normale} ${grassetto}${txtbianco}Inserisci il nome del file in uscita:${normale} (default $FILE_NAME) "
if [[ $REPLY ]]; then
FILE_NAME=$REPLY
fi
echo " ${grassetto}${txtverde}$FILE_NAME${normale}"
if [[ $EPSG_IN = 4328 ]]; then
# conversione da geocentriche a ...
# conversione da geocentriche a geografiche
if [[ $EPSG_OUT = 4326 ]] || [[ $EPSG_OUT = 3857 ]]; then
cat $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$2" "$3" "$4" \
| cs2cs -f '%.8f' +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.8f\t%10.8f\t%8.3f\n", $3, $2, $4)}' \
| gawk '{print $1","$2","$3","$4}' > $PATH_OUT/$FILE_NAME.csv
else
# conversione da geocentriche a piane
cat $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$3" "$2" "$4" \
| cs2cs -r +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.3f\t%10.3f\t%8.3f\n", $2, $3, $4)}' \
| gawk '{print $1","$2","$3","$4}' > $PATH_OUT/$FILE_NAME.csv
fi
elif [[ $EPSG_IN = 4326 ]] || [[ $EPSG_IN = 3857 ]]; then
# conversione da geografiche a ...
# conversione da geografiche a geocentriche
if [[ $EPSG_OUT = 4328 ]]; then
cat $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$3" "$2" "$4" \
| cs2cs +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.3f\t%10.3f\t%8.3f\n", $2, $3, $4)}' \
| gawk '{print $1","$2","$3","$4}' > $PATH_OUT/$FILE_NAME.csv
else
# conversione da geografiche a piane
cat $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$3" "$2" "$4" \
| cs2cs +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.3f\t%10.3f\t%8.3f\n", $2, $3, $4)}' \
| gawk '{print $1","$2","$3","$4}' > $PATH_OUT/$FILE_NAME.csv
fi
else
# conversione da piane a ...
if [[ $EPSG_OUT = 4328 ]]; then
# comando di conversione da piane a geocentriche
cat $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$3" "$2" "$4" \
| cs2cs -r +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.3f\t%10.3f\t%8.3f\n", $2, $3, $4)}' \
| gawk '{print $1","$2","$3","$4}' > $PATH_OUT/$FILE_NAME.csv
elif [[ $EPSG_OUT = 4326 ]] || [[ $EPSG_OUT = 3857 ]]; then
# comando di conversione da piane a geografiche
cat $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$2" "$3" "$4" \
| cs2cs -f '%.8f' +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.8f\t%10.8f\t%8.3f\n", $3, $2, $4)}' \
| gawk '{print $1","$2","$3","$4}' > $PATH_OUT/$FILE_NAME.csv
else
# comando di conversione da piane a piane
cat $PATH_FILE \
| gawk -F$SEP \
'{printf ("%d ",$1); system ("echo "$3" "$2" "$4" \
| cs2cs -r +init=epsg:"'"$EPSG_IN"'" +to +init=epsg:"'"$EPSG_OUT"'"")}' \
| gawk '{printf ("%5d\t",$1); printf("%10.3f\t%10.3f\t%8.3f\n", $2, $3, $4)}' \
| gawk '{print $1","$2","$3","$4}' > $PATH_OUT/$FILE_NAME.csv
fi
fi
echo ""
echo -n "Premi un tasto per tornare al menù principale... "
echo ""
read
gconv.sh
else
echo ""
echo -n "Premi un tasto per tornare al menù principale... "
read
gconv.sh
fi