-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAcces.sh
More file actions
330 lines (323 loc) · 14.1 KB
/
Copy pathAcces.sh
File metadata and controls
330 lines (323 loc) · 14.1 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/bin/bash
orange=`tput setaf 11`
bg_orange=`tput setab 178`
purple=`tput setaf 13`
Line=`tput smul`
bold=`tput bold`
black=`tput setaf 0`
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
blue=`tput setaf 4`
magenta=`tput setaf 5`
cyan=`tput setaf 6`
white=`tput setaf 15`
reset=`tput sgr0`
bg_red=`tput setab 1`
bg_green=`tput setab 2`
bg_white=`tput setab 7`
bg_blue=`tput setab 4`
lightblue=`tput setaf 45`
lightgreen=`tput setaf 46`
bleuetern=`tput setaf 45`
ilghtpurple=`tput setaf 33`
lightred=`tput setaf 161`
darkblue=`tput setaf 19`
dir=$(
cd -P -- "$(dirname -- "$0")" && pwd -P
)
cd "$dir" 2>&1 &>/dev/null
FileDate=$(echo $(date +%Y_%m_%d) | tr "/" "_")
while read -re linecsv
do
# NODE INFO + DATA
substringfields=$(echo "$linecsv" | awk -F'|' '{print $20}' )
#echo "$red$substringfields"
NodeTitle=$(echo -e "$linecsv" | awk -F'|' '{print $3}' | sed "s/title' => //g" | sed 's/^"//g' | sed "s/^'//g" | awk 'FNR == 1' | sed 's/&/et/g')
echo -e "${white}---> \$NodeTitle ----- ------ ------ ------ ------> ${orange}$NodeTitle"
NodeID=$(echo -e "$linecsv" | awk -F'nid'\'' => '\''' '{print $2}' | awk -F'|' '{print $1}' | awk 'NF')
echo -e "${white}---> \$NodeID ----- ------ ------ ------ ------> ${orange}"$NodeID""
NodeVID=$(echo -e "$linecsv" | awk -F'vid'\'' => '\''' '{print $2}' | awk -F'|' '{print $1}' | awk 'NF')
echo -e "${white}---> \$NodeVID ----- ------ ------ ------ ------> ${orange}"$NodeVID""
Vuuid=$(echo -e "$linecsv" | awk -F'vuuid'\'' => '\''' '{print $2}' | awk -F'|' '{print $1}' | awk 'NF')
echo -e "${white}---> \$Vuuid ----- ------ ------ ------ ------> ${orange}"$Vuuid""
Date=$(echo -e "$linecsv" | awk -F'created'\'' => '\''' '{print $2}' | awk -F'|' '{print $1}' | awk 'NF')
echo -e "${white}---> \$Date ----- ------ ------ ------ ------> ${orange}"$Date""
RevisionTimestamp=$(echo -e "$linecsv" | awk -F'changed'\'' => '\''' '{print $2}' | awk -F'|' '{print $1}' | awk 'NF')
echo -e "${white}---> \$RevisionTimestamp ----- ------ ------ ------ ------> ${orange}"$RevisionTimestamp""
# F#cking Date on Mac OS X (Condition)
System=$(uname)
if [ "$System" == "Darwin" ]
then
echo "Date MAC OS X condition"
CreatedDatetmp=$(date -r $Date | sed 's/CET //g'| sed 's/UTC //g' | sed 's/CEST //g')
# KML DATE FORMAT
CreatedDate=$(date -jf"%a %b %e %H:%M:%S %Y" "$CreatedDatetmp" +"%Y-%m-%dT%H:%M:%S+01:00")
LastRevisionTimestamptmp=$(date -r $RevisionTimestamp | sed 's/CET //g'| sed 's/UTC //g' | sed 's/CEST //g')
# KML DATE FORMAT
LastRevisionTimestamp=$(date -jf"%a %b %e %H:%M:%S %Y" "$LastRevisionTimestamptmp" +"%Y-%m-%dT%H:%M:%S+01:00")
else
CreatedDatetmp=$(date -d @$Date | sed 's/CET //g'| sed 's/UTC //g' | sed 's/CEST //g')
# KML DATE FORMAT
CreatedDate=$(date -d "$CreatedDatetmp" +"%Y-%m-%dT%H:%M:%S+01:00")
LastRevisionTimestamptmp=$(date -d @$RevisionTimestamp | sed 's/CET //g'| sed 's/UTC //g' | sed 's/CEST //g')
# KML DATE FORMAT
LastRevisionTimestamp=$(date -d "$LastRevisionTimestamptmp" +"%Y-%m-%dT%H:%M:%S+01:00")
fi
echo -e "${white}---> \$CreatedDate ----- ------ ------ ------ ------> ${orange}"$CreatedDate""
echo -e "${white}---> \$LastRevisionTimestamp ----- ------ ------ ------ ------> ${orange}"$LastRevisionTimestamp""
substringfieldsGeom=$(echo "$linecsv" | awk -F'|' '{print $20}' | awk -F''\''geometry'\'' => '\''' '{print $2}' | awk -F''\''' '{print $1}' | awk 'NF' | geomet )
#
SRSID=$(echo -e "$substringfieldsGeom" | awk -F'\"name\": \"EPSG' '{print $2}' | awk -F''\"'' '{print $1}')
coordinates3857=$(echo -e "$substringfieldsGeom" | awk -F'coordinates\": ' '{print $2}' | awk -F', \"' '{print $1}' | tr -d '[]' )
echo -e "${white}---> \$coordinates3857 ----- ------ ------ ------ ------> ${orange}"$coordinates3857""
TypeGeom=$(echo -e "$substringfieldsGeom" | awk -F'"srid": ' '{print $2}' | awk -F'\"type\": \"' '{print $2}' | awk -F'\"' '{print $1}')
echo -e "${white}---> \$TypeGeom ----- ------ ------ ------ ------> ${orange}"$TypeGeom""
TypeDacces=$(echo -e "$substringfields" | awk -F'field_type_acces' '{print $2}' | awk -F'tid'\'' => '\''' '{print $2}'| awk -F''\''' '{print $1}' |awk 'NF')
echo -e "${white}---> \$TypeDacces ----- ------ ------ ------ ------> ${orange}"$TypeDacces""
Hauteur=$(echo -e "$substringfields" | awk -F'field_hauteur' '{print $2}' | awk -F'value'\'' => '\''' '{print $2}' | awk -F''\'',' '{print $1}' |awk 'NF' | awk '{print $1}')
echo -e "${white}---> \$Hauteur ----- ------ ------ ------ ------> ${purple}"$Hauteur""
OpenClosed=$(echo -e "$substringfields" | awk -F'field_etat_acces' '{print $2}' | awk -F'tid'\'' => '\''' '{print $2}' | awk -F''\'',' '{print $1}' |awk 'NF')
echo -e "${white}---> \$OpenClosed ----- ------ ------ ------ ------> ${orange}"$OpenClosed""
coordinates4326=$(echo "$coordinates3857"| gdaltransform -s_srs EPSG:3857 -t_srs EPSG:4326 | sed 's/\ /\,/g')
echo -e "${white}---> \$coordinates4326 ----- ------ ------ ------ ------> ${orange}"$coordinates4326""
body=$(printf "$substringfields" | tr -d '\n'| awk -F'body' '{print $2}' | awk -F'value'\'' => "' '{print $2}' | awk -F'", '\''summary'\'' =>' '{print $1}' | sed 's/<p/\
<p/'g | sed 's/<\/p/\
<\/p/'g | sed 's/<span/\
<span/'g | sed 's/<\/span/\
<\/span/'g| sed 's/<div/\
<div/'g| sed 's/<br/\
<br/'g| sed 's/<\/div/\
<\/div/'g | sed 's/>/>\
/'g | sed 's/ //g' | awk '!/<span/' | awk '!/<\/span/' | awk '!/<p/'| awk '!/<\/p/'| awk '!/<\/div/'| awk '!/<div/' | awk 'NF'|awk '!/^[[:blank:]]*$/')
#body=$(cat "body.txt"| awk 'NF')
echo -e "---> \$body ------ ------ ------ ------ ------> "$body""
if [[ "$TypeDacces" == 294 ]]
then
TypeDaccesABC=$(echo -e "Puits de service (PS)")
IconAcces=$(echo "https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/PS.png")
echo -e "${white}---> Type d'accès : ${orange}Puits de service (PS)"
StyleKml="PS"
fi
if [[ "$TypeDacces" == 295 ]]
then
TypeDaccesABC=$(echo -e "Entrée en cavage (EC)")
IconAcces=$(echo "https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/EC.png")
StyleKml="EC"
echo -e "${white}---> Type d'accès : ${orange}Entrée en cavage (EC)"
fi
if [[ "$TypeDacces" == 296 ]]
then
TypeDaccesABC=$(echo -e "Escalier circulaire (ESc)")
IconAcces=$(echo "https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/ESc.png")
StyleKml="ESc"
echo -e "${white}---> Type d'accès : ${orange}Escalier circulaire (ESc)"
fi
if [[ "$TypeDacces" == 297 ]]
then
TypeDaccesABC=$(echo -e "Escalier droit (ESd)")
IconAcces=$(echo "https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/ESd.png")
StyleKml="ESd"
echo -e "${white}---> Type d'accès : ${orange}Escalier droit (ESd)"
fi
if [[ "$TypeDacces" == 298 ]]
then
TypeDaccesABC=$(echo -e "Galerie technique, autre (GT)")
IconAcces=$(echo "https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/GT.png")
StyleKml="GT"
echo -e "${white}---> Type d'accès : ${orange}Galerie technique, autre (GT)"
fi
if [[ "$TypeDacces" == 299 ]]
then
TypeDaccesABC=$(echo -e "Raccordement aux carrières (RC)")
IconAcces=$(echo "https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/RC.svg")
StyleKml="RC"
echo -e "${white}---> Type d'accès : ${orange}Raccordement aux carrières (RC)"
fi
if [[ "$TypeDacces" == 300 ]]
then
TypeDaccesABC=$(echo -e "Puits de service comblé (PSc)")
IconAcces=$(echo "https://raw.githubusercontent.com/babinet/InOutNOutIn/main/SVG/PSc.svg")
StyleKml="PSc"
echo -e "${white}---> Type d'accès : ${orange}Puits de service comblé (PSc)"
fi
if [[ "$TypeDacces" == 301 ]]
then
TypeDaccesABC=$(echo -e "Lunette (Lte)")
IconAcces=$(echo "https://raw.githubusercontent.com/babinet/InOutNOutIn/main/SVG/Lte.svg")
StyleKml="Lte"
echo -e "${white}---> Type d'accès : ${orange}Lunette (Lte)"
fi
if [[ "$TypeDacces" == 309 ]]
then
TypeDaccesABC=$(echo -e "Puits de service à échelons (PSé)")
IconAcces=$(echo "https://raw.githubusercontent.com/babinet/InOutNOutIn/main/SVG/PSe.svg")
StyleKml="PSe"
echo -e "${white}---> Type d'accès : ${orange}Puits de service à échelons (PSé)"
fi
####
# Ouvert/fermé 307 = ouvert 308 = fermé
if [[ "$OpenClosed" == 307 ]]
then
Ouvert=1
echo -e "${white}---> État : ${orange}Ouvert 1"
fi
if [[ "$OpenClosed" == 308 ]]
then
Ouvert=0
echo -e "${white}---> État : ${orange}Fermé (0)"
fi
echo -e " <Placemark>
<name>"$NodeTitle"</name>
<styleUrl>#"$StyleKml"</styleUrl>
<ExtendedData>
<SchemaData schemaUrl=\"#schemaAccess\">
<SimpleData name=\"Type d’accès\">"$TypeDaccesABC"</SimpleData>
<SimpleData name=\"Description\">$body</SimpleData>
<SimpleData name=\"Commentaire\"></SimpleData>
<SimpleData name=\"Accessible\">$Ouvert</SimpleData>
<SimpleData name=\"Hauteur\">$Hauteur m</SimpleData>
<SimpleData name=\"Nombre de marches\"></SimpleData>
<SimpleData name=\"Date de Création\"><when>$CreatedDate</when></SimpleData>
<SimpleData name=\"Dernier Revision\"><when>$LastRevisionTimestamp</when></SimpleData>
<SimpleData name=\"NodeID\">$NodeID</SimpleData>
<SimpleData name=\"VID\">$NodeVID</SimpleData>
<SimpleData name=\"Vuuid\">$Vuuid</SimpleData>
<TimeStamp><when></when></TimeStamp>
</SchemaData>
</ExtendedData>
<Point>
<coordinates>$coordinates4326</coordinates>
</Point>
</Placemark>" >> AccesTemp.kml
done < NodeAcces.csv
echo -e '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document>
<Schema id="schemaAccess" name="SchemaAccess">
<SimpleField name="Type d’accès" type="string"/>
<SimpleField name="Description" type="string"/>
<SimpleField name="pdfmaps_photos" type="string">
<displayName>Photos</displayName>
</SimpleField>
<SimpleField name="Commentaire" type="string"/>
<SimpleField name="Accessible" type="bool"/>
<SimpleField name="Hauteur" type="string"/>
<SimpleField name="Nombre de marches" type="string"/>
<SimpleField name="Nombre d’échelons" type="string"/>
<SimpleField name="NodeID" type="string"/>
<SimpleField name="VID" type="string"/>
<SimpleField name="Vuuid" type="string"/>
</Schema>
<ExtendedData xmlns:avenza="http://www.avenza.com">
<avenza:picklist schemaUrl="schemaAccess" avenza:field="Type d’accès">
<avenza:picklistvalue><![CDATA[Escalier Circulaire (ECc)]]></avenza:picklistvalue>
<avenza:picklistvalue><![CDATA[Escalier Droit (ESd)]]></avenza:picklistvalue>
<avenza:picklistvalue><![CDATA[Puits de Service (PS)]]></avenza:picklistvalue>
<avenza:picklistvalue><![CDATA[Puits de Service à Échelons (PSé)]]></avenza:picklistvalue>
<avenza:picklistvalue><![CDATA[Galerie Technique, autre (GT)]]></avenza:picklistvalue>
<avenza:picklistvalue><![CDATA[Entrée en Cavage (EC)]]></avenza:picklistvalue>
<avenza:picklistvalue><![CDATA[Raccordement aux Carrières (RC)]]></avenza:picklistvalue>
<avenza:picklistvalue><![CDATA[Lunette (Lte)]]></avenza:picklistvalue>
</avenza:picklist>
</ExtendedData>
<Folder>
<styleUrl>#style0</styleUrl>
<name>Accès</name>
<ExtendedData>
<SchemaData schemaUrl="#schemaAccess"/>
</ExtendedData>
' > Acces.kml
# LOOP END
cat AccesTemp.kml| awk 'NF' | awk 'NF' | awk '!/Hauteur"><\/SimpleData>/'| awk '!/Accessible"><\/SimpleData>/'| awk '!/Nombre de marches"><\/SimpleData>/'| awk '!/Commentaire"><\/SimpleData>/'| awk '!/Création"><\/SimpleData>/'| awk '!/NodeID"><\/SimpleData>/'| awk '!/VID"><\/SimpleData>/'| awk '!/Vuuid"><\/SimpleData>/'| awk '!/Description"><\/SimpleData>/' >> Acces.kml
rm AccesTemp.kml
echo -e ' </Folder>
<Style id="ESd">
<IconStyle>
<Icon>
<scale>10</scale>
<href>https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/ESd.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="PS">
<IconStyle>
<Icon>
<scale>10</scale>
<href>https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/PS.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="PSc">
<IconStyle>
<Icon>
<scale>10</scale>
<href>https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/PSc.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="PSe">
<IconStyle>
<Icon>
<scale>10</scale>
<href>https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/PSe.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="ESc">
<IconStyle>
<Icon>
<scale>10</scale>
<href>https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/ESc.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="EC">
<IconStyle>
<Icon>
<scale>10</scale>
<href>https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/EC.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="GT">
<IconStyle>
<Icon>
<scale>10</scale>
<href>https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/GT.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="Lte">
<IconStyle>
<Icon>
<scale>10</scale>
<href>https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/Lte.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="RC">
<IconStyle>
<Icon>
<scale>10</scale>
<href>https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/EC.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="CDM">
<IconStyle>
<Icon>
<scale>10</scale>
<href>https://raw.githubusercontent.com/babinet/InOutNOutIn/main/Img/logo_white.png</href>
</Icon>
</IconStyle>
</Style>
</Document>
</kml>' >> Acces.kml
gpsbabel -w -i kml -f Acces.kml -o gpx -F Acces.gpx
ogr2ogr -f GeoJSON Acces.json Acces.kml
mv Acces.gpx "$FileDate"_Acces.gpx
mv Acces.kml "$FileDate"_Acces.kml
mv Acces.json "$FileDate"_Acces.json
zip Acces.zip *_Acces.*
cd -