-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebTransCoordDGT.sh
executable file
·152 lines (111 loc) · 3.11 KB
/
WebTransCoordDGT.sh
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
#!/usr/bin/env bash
#title :WebTransCoordDGT.sh
#description :Transformção de coordenadas com o serviço REST(WebTransCoord) da DGT
#author :apinhal
#date :2020-12-01
usage() {
echo "Usage: ${0##*/} [-hl] [-am arg] [-cH arg,arg]"
echo
echo "Transformção de coordenadas com o serviço REST(WebTransCoord) da DGT"
echo
echo "Default arguments:"
echo " ${0##*/} -m grelhas -c 27493,3763"
echo
echo "Options:"
echo " -a area: Portugal%20Continental¹ | Madeira | Acores"
echo " -c crsIN,crsOUT (EPSG codes): 27493,3763¹"
echo " -H altIN,altOUT: Ortometrica,Ortometrica¹ | Elipsoidal"
echo " -m metodo: grelhas¹ | bursaWolf"
echo " -h help"
echo " -l lista de Sistemas de Referência disponíveis"
echo " ¹default"
echo
echo "Examples:"
echo " ${0##*/} -c 4258,3763 -H Elipsoidal,Ortometrica"
echo " ${0##*/} -a Madeira -c 3061,5016 -m bursaWolf"
}
get_url() {
url="http://cgpr.dgterritorio.pt/webtranscoord/transformar?x=$1&y=$2&z=$3&area=$area&crsin=$crsin&crsout=$crsout&altin=$altin&altout=$altout&metodo=$metodo"
curl -s $url
}
print_error() {
echo "input error"
}
print_epsg_list() {
echo "Lista de Sistemas de Referência:
EPSG Nome
-a Portugal%20Continental -m grelhas | bursaWolf
4258 ETRS89
3763 ETRS89/PT-TM06
4274 Datum73
27493 Datum73/Hayford-Gauss
4207 Datum Lisboa
5018 Datum Lisboa/Hayford-Gauss
20790 Datum Lisboa/Hayford-Gauss falsa origem (Coordenadas Militares)
-a Acores -m bursaWolf
5013 ITRF93
5014 ITRF93/PTRA08-UTM25N
5015 ITRF93/PTRA08-UTM26N
2188 Datum Observatório - Flores/UTM25N
2189 Datum Base SW - Graciosa/UTM26N
2190 Datum S.Braz - S.Miguel/UTM26N
-a Madeira -m bursaWolf
5013 ITRF93
5016 ITRF93/PTRA08-UTM28N
3061 Datum Base SE/UTM28N"
}
# check if curl exists
if ! command -v curl >/dev/null 2>&1; then
echo "curl is not installed. Please install it first."
exit 1
fi
# default input argumets
area="Portugal%20Continental"
crsin="27493"
crsout="3763"
altin="Ortometrica"
altout="Ortometrica"
metodo="grelhas"
#
while getopts "a:c:H:m:lh" opt; do
IFS=,
case $opt in
a) area=$OPTARG ;;
c) crs=($OPTARG)
crsin=${crs[0]}
crsout=${crs[1]} ;;
H) alt=($OPTARG)
altin=${alt[0]}
altout=${alt[1]} ;;
m) metodo=$OPTARG ;;
l) print_epsg_list
exit 0 ;;
h) usage
exit 0 ;;
*) usage
exit 1 ;;
esac
done
shift $((OPTIND - 1))
reg="^[+-]?[0-9]+([.][0-9]+)?$" # regex: decimal number
while IFS=" " read -r -a xyz; do # input 2d or 3d
case ${#xyz[@]} in # check number of elements of array: xyz
2)
if [[ ${xyz[0]} =~ $reg ]] && [[ ${xyz[1]} =~ $reg ]]; then # validate 2d input
get_url ${xyz[0]} ${xyz[1]} 0 | awk -F';' '{print $1" "$2}'
else
print_error
fi
;;
3)
if [[ ${xyz[0]} =~ $reg ]] && [[ ${xyz[1]} =~ $reg ]] && [[ ${xyz[2]} =~ $reg ]]; then # validate 3d input
get_url ${xyz[0]} ${xyz[1]} ${xyz[2]} | awk -F';' '{print $1" "$2" "$3}'
else
print_error
fi
;;
*)
print_error
;;
esac
done