-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_mission_download_img.sh
213 lines (174 loc) · 8.06 KB
/
3_mission_download_img.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
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
#!/bin/bash
# LECTURE DU FICHIER DE CONFIGURATION
. './config.env'
# REPERTOIRE DE TRAVAIL
cd $REPER
echo $REPER
folder_mission=$REPER'/2_mission/'$id_mission
rm $folder_mission'/couverture_bbox/captures.'*
rm $folder_mission'/couverture_bbox/captures_join.'*
for h in $folder_mission'/kml/'*'.kml'
do
# EXTRACTION DU NOM DE FICHIER
h1="${h%%.*}"
mission_part="${h1##*/}"
echo '################################################################'
echo 'Nom du fichier kml : ' $mission_part
if [ "$(uname)" == "Darwin" ]; then
sed -i '' "s/<value\/>/<value><\/value>/g" $h
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
sed -i "s/<value\/>/<value><\/value>/g" $h
fi
# PERMET L'EXTRACTION DES ATTRIBUTS DE CHACUNE DES IMG
awk -F"[><]" '/<\/Data>/{a="";next} /<Data>/{a=1;next} a && /<value>/{print $3}' $folder_mission'/kml/'${h##*/} > $folder_mission'/csv_attributs/'$mission_part'_value.csv'
awk -F"[><]" '/<\/Data>/{a="";next} /<Data>/{a=1;next} a && /<displayName>/{print $3}' $folder_mission'/kml/'${h##*/} > $folder_mission'/csv_attributs/'$mission_part'_displayName.csv'
if [ "$(uname)" == "Darwin" ]; then
sed -i '' "s/ //g" $folder_mission'/csv_attributs/'$mission_part'_value.csv' > $folder_mission'/csv_attributs/'$mission_part'_value_origin.csv'
sed -i '' "s/ //g" $folder_mission'/csv_attributs/'$mission_part'_displayName.csv' > $folder_mission'/csv_attributs/'$mission_part'_displayName_origin.csv'
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
sed "s/ //g" $folder_mission'/csv_attributs/'$mission_part'_value.csv' > $folder_mission'/csv_attributs/'$mission_part'_value_origin.csv'
sed "s/ //g" $folder_mission'/csv_attributs/'$mission_part'_displayName.csv' > $folder_mission'/csv_attributs/'$mission_part'_displayName_origin.csv'
fi
count=$(awk '/id/{++n; if (n==2) { print NR; exit}}' $folder_mission'/csv_attributs/'$mission_part'_displayName.csv')
number=`expr $count - 1`
echo $number
# PASSAGE DE LIGNES EN COLONNES
count=1
while read line; do
output=`echo $line | sed "s/id;//" | sed "s/name;//" | sed "s/NUMCLI;//" | sed "s/IDCLICHE;//" | sed "s/RES;//" | sed "s/ORIENTATION;//" | sed "s/DATE;//" | sed "s/IDTA;//" | sed "s/SUPPORT;//" | sed "s/JP2;//" | sed "s/IDMISS;//" | sed "s/PRFXCLI;//" | sed "s/SUFXCLI;//" | sed "s/X;//" | sed "s/Y;//" | sed "s/TYPE;//" | sed "s/RES;//" | sed "s/HEURE;//"`
echo -n $output
if [ $count -lt $number ]; then
echo -n ","
let "count++"
else
echo
count=1
fi
done < $folder_mission'/csv_attributs/'$mission_part'_value.csv' > $folder_mission'/csv_attributs/'$mission_part'_value_transpose.csv'
########################
count=1
while read line; do
output=`echo $line `
echo -n $output
if [ $count -lt $number ]; then
echo -n ","
let "count++"
else
echo
count=1
fi
done < $folder_mission'/csv_attributs/'$mission_part'_displayName.csv' > $folder_mission'/csv_attributs/'$mission_part'_displayName_transpose.csv'
# EXTRACTION DES NOMS DE CHAMPS (PREMIERE LIGNE)
line=$(head -n 1 $folder_mission'/csv_attributs/'$mission_part'_displayName_transpose.csv')
# AJOUTE LES NOMS DE CHAMPS
if [ "$(uname)" == "Darwin" ]; then
sed -i '' "1i\\
$line
" $folder_mission'/csv_attributs/'$mission_part'_value_transpose.csv'
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
sed -i 1i"$line" $folder_mission'/csv_attributs/'$mission_part'_value_transpose.csv'
fi
# IDENTIFICATION DES PRISES DE VUE DE LA MISSION QUI SE TROUVENT DANS LA BBOX
file=$folder_mission'/couverture_bbox/captures.shp'
if [ -f "$file" ]
then
echo "merge ${h%%.*}.shp"
ogr2ogr \
-f 'ESRI Shapefile' \
-clipdst $bbox_ogr \
-append \
$file \
$folder_mission'/kml/'${h##*/} \
-nlt POLYGON
else
echo "creating merge ${h%%.*}.shp"
ogr2ogr \
-f 'ESRI Shapefile' \
-clipdst $bbox_ogr \
$file \
$folder_mission'/kml/'${h##*/} \
-nlt POLYGON
fi
# LISTE DES PRISES DE VUE AU FORMAT CSV
ogr2ogr -f CSV $folder_mission'/couverture_bbox/captures.csv' $folder_mission'/couverture_bbox/captures.shp' -sql "SELECT Name FROM captures"
# TROUVE LE NUMERO DE LA COLONNE JP2
cut -d, -f2- $folder_mission'/csv_attributs/'$mission_part'_value_transpose.csv' > $folder_mission'/csv_attributs/'$mission_part'_value_transpose_noid.csv'
loc_col_cap=$( awk '
BEGIN{
FS=","
}
{
gsub(/\r/,"")
for(i=1;i<=NF;i++){
if($i=="JP2"){
print i
exit
}
}
}
' $folder_mission'/csv_attributs/'$mission_part'_value_transpose_noid.csv')
echo $loc_col_cap
# JOINTURE ENTRE LES DEUX FICHIERS
awk -F, 'FNR==NR{a[$1]=$'$loc_col_cap';next} $1 in a{$2=a[$1]} 1' OFS=',' $folder_mission'/csv_attributs/'$mission_part'_value_transpose_noid.csv' $folder_mission'/couverture_bbox/captures.csv' > $folder_mission'/csv_liste_img/liste_img.csv'
# PERMET DE MODIFIER L'ENTETE
if [ "$(uname)" == "Darwin" ]; then
sed -i '' '1s/.*/Name,jp2/' $folder_mission'/csv_liste_img/liste_img.csv'
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
sed -i '1s/.*/Name,jp2/' $folder_mission'/csv_liste_img/liste_img.csv'
fi
# PERMET D'EXTRAIRE LE NUMERO DE LA COLONNE
loc_col_a=$( awk '
BEGIN{
FS=","
}
{
gsub(/\r/,"")
for(i=1;i<=NF;i++){
if($i=="jp2"){
print i
exit
}
}
}
' $folder_mission'/csv_liste_img/liste_img.csv')
if [ "$(uname)" == "Darwin" ]; then
while IFS="," read -r Name ; do
echo ">>>>>>>" $Name
echo "URL de téléchargement : https://wxs.ign.fr/$key/jp2/DEMAT.PVA/$id_mission/$Name.jp2"
curl "https://wxs.ign.fr/$key/jp2/DEMAT.PVA/$id_mission/$Name.jp2" > $folder_mission'/img_jp2/'$Name'.jp2'
gdal_translate -of JPEG $folder_mission'/img_jp2/'$Name'.jp2' $folder_mission'/img_jpg/'$Name'.jpg';
done < <(cut -d "," -f${loc_col_a} -s $folder_mission'/csv_liste_img/liste_img.csv' | awk '{if (NR!=1) {print}}')
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
while IFS="," read -r Name ; do
echo ">>>>>>>" $Name
echo "URL de téléchargement : https://wxs.ign.fr/$key/jp2/DEMAT.PVA/$id_mission/$Name.jp2"
curl "https://wxs.ign.fr/$key/jp2/DEMAT.PVA/$id_mission/$Name.jp2" > $folder_mission'/img_jp2/'$Name'.jp2'
gdal_translate -of JPEG $folder_mission'/img_jp2/'$Name'.jp2' $folder_mission'/img_jpg/'$Name'.jpg';
done < <(cut -d "," -f${loc_col_a} $folder_mission'/csv_liste_img/liste_img.csv' | awk '{if (NR!=1) {print}}')
fi
#JOINTURE ENTRE LE CSV ET LE SHAPEFILE POUR RECUPERER LES VALEURS DU CSV
mv $folder_mission'/csv_attributs/'$mission_part'_value_transpose.csv' $folder_mission'/liste.csv'
file_pv=$folder_mission'/couverture_bbox/captures_join.shp'
if [ -f "$file" ]
then
echo "merge ${h%%.*}.shp"
ogr2ogr \
-append \
-f "ESRI Shapefile" \
-sql "SELECT liste.name AS name,liste.NUMCLI AS numcli, liste.IDCLICHE AS idcliche, liste.RES AS res, liste.ORIENTATION AS orientation, liste.DATE AS date, liste.JP2 AS img FROM captures LEFT JOIN '$folder_mission/liste.csv'.liste ON captures.Name = liste.name" \
$file_pv \
$file \
-nlt POLYGON
else
echo "creating merge ${h%%.*}.shp"
ogr2ogr \
-f "ESRI Shapefile" \
-sql "SELECT liste.name AS name,liste.NUMCLI AS numcli, liste.IDCLICHE AS idcliche, liste.RES AS res, liste.ORIENTATION AS orientation, liste.DATE AS date, liste.JP2 AS img FROM captures LEFT JOIN '$folder_mission/liste.csv'.liste ON captures.Name = liste.name" \
$file_pv \
$file \
-nlt POLYGON
fi
mv $folder_mission'/liste.csv' $folder_mission'/csv_attributs/'$mission_part'_value_transpose.csv'
done
ogr2ogr -f CSV $folder_mission'/csv_exif/list_exif.csv' $folder_mission'/couverture_bbox/captures_join.shp' -dialect sqlite -sql "SELECT '"$folder_mission'/img_jpg/'"'||img||'"'.jpg'"' as SourceFile, y(Centroid(geometry)) as GPSLatitude, x(Centroid(geometry)) as GPSLongitude, replace(date,'-',':')||' 00:00:00' AS DateTimeOriginal FROM captures_join"
exiftool -csv=$folder_mission'/csv_exif/list_exif.csv' $folder_mission'/img_jpg' -Overwrite_Original -m