|
@@ -0,0 +1,203 @@
|
|
1
|
+<?php
|
|
2
|
+/**
|
|
3
|
+ * Documentation, License etc.
|
|
4
|
+ *
|
|
5
|
+ * @package jpg2gpx
|
|
6
|
+ */
|
|
7
|
+//exiftool -c "%.6f" /mnt/perso/Nextcloud/Chine_2019/chutes_hu_kou/IMG_20190920_*.jpg | grep GPS | grep Position
|
|
8
|
+setlocale(LC_ALL, 'fr_FR');
|
|
9
|
+CONST EOL = "\n";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+$dir="/mnt/perso/Nextcloud";
|
|
13
|
+$list = array();
|
|
14
|
+dirrecurse( $dir );
|
|
15
|
+//$dir = new RecursiveDirectoryIterator($path);
|
|
16
|
+//$files = new RecursiveIteratorIterator($dir);
|
|
17
|
+//echo "[$path]\n";
|
|
18
|
+//foreach ($files as $file) {
|
|
19
|
+// echo " ├ $file\n";
|
|
20
|
+//}
|
|
21
|
+function dirrecurse( $dir )
|
|
22
|
+{
|
|
23
|
+ global $list;
|
|
24
|
+ $x =0;
|
|
25
|
+ $paths = new RecursiveIteratorIterator(new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ));
|
|
26
|
+
|
|
27
|
+ foreach ($paths as $file)
|
|
28
|
+ {
|
|
29
|
+ $x +=1;
|
|
30
|
+ $gpscoord=readgps($x, $file);
|
|
31
|
+ }
|
|
32
|
+ exportGPX($list);
|
|
33
|
+}
|
|
34
|
+
|
|
35
|
+function readgps( $x, $path )
|
|
36
|
+{
|
|
37
|
+ global $list;
|
|
38
|
+ $flag = false;
|
|
39
|
+ //echo $path .EOL;
|
|
40
|
+ if (exif_imagetype($path) == 2)
|
|
41
|
+ {
|
|
42
|
+ $datas = exif_read_data($path, "ANY_TAG");
|
|
43
|
+ //echo "$path\n";
|
|
44
|
+ if (! empty($datas["GPSLatitude"]))
|
|
45
|
+ {
|
|
46
|
+ $list[$x]["name"] = $path;
|
|
47
|
+ print_r( $datas );
|
|
48
|
+ $latitude = convert2decimal( $datas["GPSLatitude"][0], $datas["GPSLatitude"][1],$datas["GPSLatitude"][2] );
|
|
49
|
+ $dlatitude = $datas["GPSLatitudeRef"];
|
|
50
|
+ $longitude = convert2decimal( $datas["GPSLongitude"][0], $datas["GPSLongitude"][1],$datas["GPSLongitude"][2] );
|
|
51
|
+ $dlongitude = $datas["GPSLongitudeRef"];
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+ if ($dlongitude == "S")
|
|
55
|
+ {
|
|
56
|
+ $list[$x]["longitude"] = -$longitude;
|
|
57
|
+ }else
|
|
58
|
+ {
|
|
59
|
+ $list[$x]["longitude"] = $longitude;
|
|
60
|
+ }
|
|
61
|
+ if ($dlatitude == "O")
|
|
62
|
+ {
|
|
63
|
+ $list[$x]["latitude"] = -$latitude;
|
|
64
|
+ }else
|
|
65
|
+ {
|
|
66
|
+ $list[$x]["latitude"] = $latitude;
|
|
67
|
+ }
|
|
68
|
+ if ( ! empty($datas["GPSAltitude"]) )
|
|
69
|
+ {
|
|
70
|
+ $altitude = str_replace( ",", "", number_format( transform( $datas["GPSAltitude"] ),2 ));
|
|
71
|
+ $list[$x]["altitude"] = $altitude;
|
|
72
|
+ }else
|
|
73
|
+ {
|
|
74
|
+ $list[$x]["altitude"] = "";
|
|
75
|
+ }
|
|
76
|
+ $time = gpstime( $datas["GPSTimeStamp"] );
|
|
77
|
+ //$datetime = new DateTime();
|
|
78
|
+ $date = $datas["GPSDateStamp"] . " " . $time;
|
|
79
|
+ $datetime = date_create_from_format("Y:m:d H:i:s", $date, new DateTimeZone( "UTC" ) );
|
|
80
|
+ $list[$x]["datetimeUTC"] = date( "c", $datetime->getTimestamp());
|
|
81
|
+ //echo $date . EOL;
|
|
82
|
+ if ( ! empty($datas["DateTime"]) )
|
|
83
|
+ {
|
|
84
|
+ $datetime_local = date_create_from_format("Y:m:d H:i:s", $datas["DateTime"]);
|
|
85
|
+ }elseif ( ! empty($datas["DateTimeOriginal"]) )
|
|
86
|
+ {
|
|
87
|
+ $datetime_local = date_create_from_format("Y:m:d H:i:s", $datas["DateTimeOriginal"]);
|
|
88
|
+ }else
|
|
89
|
+ {
|
|
90
|
+ $flag = true;
|
|
91
|
+ }
|
|
92
|
+ if ( $flag = false )
|
|
93
|
+ {
|
|
94
|
+ $list[$x]["datetimelocal"] = date( "c", $datetime_local->getTimestamp());
|
|
95
|
+ $dh = $datetime->diff( $datetime_local );
|
|
96
|
+ $decalagehoraire = $dh->h;
|
|
97
|
+
|
|
98
|
+ if ( $dh->i >55)
|
|
99
|
+ {
|
|
100
|
+ $decalagehoraire += 1;
|
|
101
|
+ }
|
|
102
|
+ if ( $decalagehoraire >=0 )
|
|
103
|
+ {
|
|
104
|
+ $decalagehoraire = "+" . str_pad(abs($decalagehoraire), 4, "0", STR_PAD_BOTH );
|
|
105
|
+ }else
|
|
106
|
+ {
|
|
107
|
+ $decalagehoraire = "-" . str_pad(abs($decalagehoraire), 4, "0", STR_PAD_BOTH );
|
|
108
|
+ }
|
|
109
|
+ $list[$x]["fuseauhoraire"] = $decalagehoraire;
|
|
110
|
+ }else
|
|
111
|
+ {
|
|
112
|
+ $decalagehoraire = "";
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+ $datetime->setTimeZone(new DateTimeZone('Europe/Paris'));
|
|
117
|
+ echo $path . EOL;
|
|
118
|
+ echo strftime( "le %A %c heure de Paris", $datetime->getTimestamp() ) . EOL;
|
|
119
|
+ echo strftime( "le %A %c heure locale", $datetime_local->getTimestamp() ) . EOL;
|
|
120
|
+ echo "Fuseau horaire : " . $decalagehoraire .EOL;
|
|
121
|
+ echo "Latitude : $latitude $dlatitude\nLongitude : $longitude $dlongitude\nAltitude : $altitude\n";
|
|
122
|
+ //print_r($datas);
|
|
123
|
+
|
|
124
|
+ }
|
|
125
|
+ }
|
|
126
|
+}
|
|
127
|
+
|
|
128
|
+function convert2decimal( $d, $m, $s)
|
|
129
|
+{
|
|
130
|
+ return transform( $d ) + transform($m)/60 + transform($s)/3600;
|
|
131
|
+}
|
|
132
|
+
|
|
133
|
+function transform($a)
|
|
134
|
+{
|
|
135
|
+ $b = explode( "/", $a);
|
|
136
|
+ $r = floatval($b[0]) / floatval($b[1]);
|
|
137
|
+ return $r;
|
|
138
|
+}
|
|
139
|
+
|
|
140
|
+function gpstime( $a )
|
|
141
|
+{
|
|
142
|
+ $h = explode("/", $a[0]);
|
|
143
|
+ $m = explode("/", $a[1]);
|
|
144
|
+ $s = explode("/", $a[2]);
|
|
145
|
+ return str_pad( $h[0], 2 ,"0", STR_PAD_LEFT ) . ":" . str_pad( $m[0], 2 ,"0", STR_PAD_LEFT ) . ":" . str_pad( $s[0], 2 ,"0", STR_PAD_LEFT );
|
|
146
|
+}
|
|
147
|
+
|
|
148
|
+function exportKML( $list )
|
|
149
|
+{
|
|
150
|
+ $enteteKML = '<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2">' . EOL;
|
|
151
|
+ print_r($list);
|
|
152
|
+ if ( ! $fh = fopen("export_jpg2gpx_" . date("YmdHis") . ".kml", "w") )
|
|
153
|
+ {
|
|
154
|
+ $erreur = error_get_last();
|
|
155
|
+ echo "Erreur fopen ligne " . __LINE__ . " : " . $erreur["message"] . EOL;
|
|
156
|
+ exit (1);
|
|
157
|
+ }
|
|
158
|
+ fwrite( $fh, $enteteKML );
|
|
159
|
+
|
|
160
|
+ foreach ( $list as $ligne )
|
|
161
|
+ {
|
|
162
|
+ $text = "<Placemark>" . EOL . "<name>" . basename($ligne["name"]) . "</name>" . EOL . "<description>" . $ligne["name"] . EOL . "Altitude : " . $ligne["altitude"] . EOL . "Heure UTC : " . $ligne["datetimeUTC"] . EOL . "Heure locale :" . $ligne["datetimelocal"] . EOL . "Fuseau horaire : " . $ligne["fuseauhoraire"] . EOL . "Généré automatiquement</description>" .EOL;
|
|
163
|
+ $text .= " <point>" . EOL . " <coordinates>" . $ligne["longitude"] . "," . $ligne["latitude"] . "</coordinates>" . EOL . " </point>" . EOL . " </Placemark>" . EOL;
|
|
164
|
+ fwrite( $fh, $text );
|
|
165
|
+ }
|
|
166
|
+ fwrite( $fh, "</kml>" );
|
|
167
|
+}
|
|
168
|
+
|
|
169
|
+function exportGPX( $list )
|
|
170
|
+{
|
|
171
|
+ $enteteXML = '<?xml version="1.1" encoding="UTF-8" standalone="no" ?><gpx version="1.1" creator="jpg2gpx" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"><metadata><name>export_jpg2gpx_' . date("YmdHis") . '</name></metadata>' . EOL;
|
|
172
|
+
|
|
173
|
+ if ( ! $fh = fopen("export_jpg2gpx_" . date("YmdHis") . ".gpx", "w") )
|
|
174
|
+ {
|
|
175
|
+ $erreur = error_get_last();
|
|
176
|
+ echo "Erreur fopen ligne " . __LINE__ . " : " . $erreur["message"] . EOL;
|
|
177
|
+ exit (1);
|
|
178
|
+ }
|
|
179
|
+ fwrite( $fh, $enteteXML );
|
|
180
|
+
|
|
181
|
+ foreach ( $list as $ligne )
|
|
182
|
+ {
|
|
183
|
+ $text = '<wpt lat="' . str_replace( ",", ".", $ligne["latitude"]) . '" lon="' . str_replace( ",", ".", $ligne["longitude"]) . '">';
|
|
184
|
+ $text .= "<ele>" . $ligne["altitude"] . "</ele>";
|
|
185
|
+ $text .= "<time>" . $ligne["datetimeUTC"] . "</time>" . EOL;
|
|
186
|
+ $text .= "<name>" . basename($ligne["name"]) . "</name>" . EOL;
|
|
187
|
+ $text .= "<cmt>Généré automatiquement</cmt>" . EOL;
|
|
188
|
+ $text .= "<desc>" . $ligne["name"] . EOL;
|
|
189
|
+ if ( ! empty($ligne["datetimelocal"]) )
|
|
190
|
+ {
|
|
191
|
+ $text .= " Heure locale :" . $ligne["datetimelocal"];
|
|
192
|
+ }
|
|
193
|
+ $text .= "</desc>" . EOL;
|
|
194
|
+ $text .= "</wpt>" .EOL;
|
|
195
|
+ fwrite( $fh, $text );
|
|
196
|
+ }
|
|
197
|
+ fwrite( $fh, "</gpx>" );
|
|
198
|
+}
|
|
199
|
+
|
|
200
|
+function remplacevirgule ( $f )
|
|
201
|
+{
|
|
202
|
+
|
|
203
|
+}
|