-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapillary2pg.sh
154 lines (134 loc) · 4.5 KB
/
mapillary2pg.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
#!/bin/sh
# ------------------------------------------------------------------------------
# 2022 Florian Boret
# https://github.com/igeofr/mapillary2pg
# CC BY-SA 4.0 : https://creativecommons.org/licenses/by-sa/4.0/deed.fr
#-------------------------------------------------------------------------------
# RECUPERATION DU TYPE DE DATA A INTEGRER (images ou map_features)
if [ "$#" -ge 1 ]; then
if [ "$1" = "images" ] || [ "$1" = "map_features" ];
then
TYPE=$1
echo $TYPE
else
IFS= read -p "Type : " S_TYPE
if [ "$S_TYPE" = "images" ] || [ "$S_TYPE" = "map_features" ];
then
export TYPE=$S_TYPE
echo $TYPE
else
echo "Erreur de paramètre"
exit 0
fi
fi
else
IFS= read -p "Type : " S_TYPE
if [ "$S_TYPE" = "images" ] || [ "$S_TYPE" = "map_features" ];
then
export TYPE=$S_TYPE
echo $TYPE
else
echo "Erreur de paramètre"
exit 0
fi
fi
# VARIABLES DATES
export DATE_YM=$(date "+%Y%m")
export DATE_YMD=$(date "+%Y%m%d")
# LECTURE DU FICHIER DE CONFIGURATION
. './config.env'
# REPERTOIRE DE TRAVAIL
cd $REPER
echo $REPER
# VERIFIE l'EXISTENCE D'UN REPERTOIRE
DIR_DATA=$REPER'/'$TYPE'/'$DATE_YMD
echo $DIR_DATA
if [ -d "$DIR_DATA" ]; then
echo "Le répertoire $DIR_DATA existe"
rm $DIR_DATA'/'*
else
mkdir $DIR_DATA
fi
# COORDONNEES DE L'EMPRISE
echo $V_LAT_MIN
echo $V_LAT_MAX
echo $V_LONG_MIN
echo $V_LONG_MAX
# COMPTER LE NOMBRE D'ITERATIONS NECESSAIRES
sizeX=$(echo "scale=0; (($V_LONG_MAX - $V_LONG_MIN)/$PAS)" | bc)
echo $sizeX
sizeY=$(echo "scale=0; (($V_LAT_MAX - $V_LAT_MIN)/$PAS)" | bc)
echo $sizeY
# EXTRACTION DES DONNEES PAR ITERATION
x=1
while [ $x -le $sizeX ]
do
echo "X $x times"
vBBOX_X1=$(echo "scale=4; ($V_LONG_MIN+(($x-1)*$PAS))" | bc)
echo $vBBOX_X1
vBBOX_X2=$(echo "scale=4; ($V_LONG_MIN+($x*$PAS))" | bc)
echo $vBBOX_X2
x=$(( $x + 1 ))
#------------------------------
y=1
while [ $y -le $sizeY ]
do
echo "Y $y times"
vBBOX_Y1=$(echo "scale=4; ($V_LAT_MIN+(($y-1)*$PAS))" | bc)
echo $vBBOX_Y1
vBBOX_Y2=$(echo "scale=4; ($V_LAT_MIN+($y*$PAS))" | bc )
echo $vBBOX_Y2
y=$(( $y + 1 ))
vBBOX=$vBBOX_X1","$vBBOX_Y1","$vBBOX_X2","$vBBOX_Y2
sBBOX_X1=$(echo $vBBOX_X1 | sed -e 's/\./_/g')
echo $sBBOX_X1
sBBOX_X2=$(echo $vBBOX_X2 | sed -e 's/\./_/g')
echo $sBBOX_X2
sBBOX_Y1=$(echo $vBBOX_Y1 | sed -e 's/\./_/g')
echo $sBBOX_Y1
sBBOX_Y2=$(echo $vBBOX_Y2 | sed -e 's/\./_/g')
echo $sBBOX_Y2
#-------------------------------------------------------------------------------
# ATTRIBUTS A EXTRAIRE
if [ "$TYPE" = "images" ]; then
FIELD="id,geometry,captured_at,exif_orientation"
F_DATE="start_captured_at"
elif [ "$TYPE" = "map_features" ]
then
FIELD="id,geometry,object_value,object_type,aligned_direction,first_seen_at,last_seen_at"
F_DATE="start_last_seen_at"
fi
# Ajouter &limit=5 pour restreindre l'extraction
wget 'https://graph.mapillary.com/'$TYPE'?access_token='$TOKEN'&fields='$FIELD'&'$F_DATE'='$DATE_DEBUT'&bbox='$vBBOX -O $REPER'/'$TYPE'/'$DATE_YMD'/'$DATE_YMD'_'$TYPE'_'$sBBOX_X1'_'$sBBOX_Y1'_'$sBBOX_X2'_'$sBBOX_Y2'.geojson'
find $REPER'/'$TYPE'/'$DATE_YMD | xargs grep -l '{"data":\[\]}' | xargs -I {} rm -rf {}
FILE_IMG=$REPER'/'$TYPE'/'$DATE_YMD'/'$DATE_YMD'_'$TYPE'_'$sBBOX_X1'_'$sBBOX_Y1'_'$sBBOX_X2'_'$sBBOX_Y2'.geojson'
if [ -f "$FILE_IMG" ]; then
echo "$FILE_IMG existe."
sed -i -e 's/"data":/"type": "FeatureCollection", "features":/g' $REPER'/'$TYPE'/'$DATE_YMD'/'$DATE_YMD'_'$TYPE'_'$sBBOX_X1'_'$sBBOX_Y1'_'$sBBOX_X2'_'$sBBOX_Y2'.geojson'
sed -i -e 's/"id"/"type": "Feature","id"/g' $REPER'/'$TYPE'/'$DATE_YMD'/'$DATE_YMD'_'$TYPE'_'$sBBOX_X1'_'$sBBOX_Y1'_'$sBBOX_X2'_'$sBBOX_Y2'.geojson'
fi
done
# -----------------------------
done
# DEBUT DE FUSION DES DONNEES ET DE L'INTEGRATION DANS PG
echo 'Debut Mapillary PG'
file=$REPER'/'$TYPE'/'$DATE_YMD'_'$TYPE'.gpkg'
rm $file
for i in $(ls $REPER'/'$TYPE'/'$DATE_YMD'/'*'.geojson')
do
echo "merge $i"
ogr2ogr -progress -f 'GPKG' -update -append --debug ON -lco SPATIAL_INDEX=YES $file $i $(basename "${i%.*}") -nln $DATE_YMD'_'$TYPE -nlt POINT
done
# IMPORT PG
ogr2ogr \
-append \
-f "PostgreSQL" PG:"service='$C_SERVICE' schemas='$C_SCHEMA'" \
-nln 'mapillary_'$TYPE \
-s_srs 'EPSG:4326' \
-t_srs 'EPSG:2154' \
$file \
--config OGR_TRUNCATE YES \
--debug ON \
--config CPL_LOG './'$REPER_LOGS'/'$DATE_YMD'_mapillary_'$TYPE'.log'
# FIN DE FUSION DES DONNEES ET DE L'INTEGRATION DANS PG
echo 'Fin Mapillary PG'