204 lines
6.1 KiB
PHP
204 lines
6.1 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Documentation, License etc.
|
||
|
*
|
||
|
* @package jpg2gpx
|
||
|
*/
|
||
|
//exiftool -c "%.6f" /mnt/perso/Nextcloud/Chine_2019/chutes_hu_kou/IMG_20190920_*.jpg | grep GPS | grep Position
|
||
|
setlocale(LC_ALL, 'fr_FR');
|
||
|
CONST EOL = "\n";
|
||
|
|
||
|
|
||
|
$dir="/mnt/perso/Nextcloud";
|
||
|
$list = array();
|
||
|
dirrecurse( $dir );
|
||
|
//$dir = new RecursiveDirectoryIterator($path);
|
||
|
//$files = new RecursiveIteratorIterator($dir);
|
||
|
//echo "[$path]\n";
|
||
|
//foreach ($files as $file) {
|
||
|
// echo " ├ $file\n";
|
||
|
//}
|
||
|
function dirrecurse( $dir )
|
||
|
{
|
||
|
global $list;
|
||
|
$x =0;
|
||
|
$paths = new RecursiveIteratorIterator(new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ));
|
||
|
|
||
|
foreach ($paths as $file)
|
||
|
{
|
||
|
$x +=1;
|
||
|
$gpscoord=readgps($x, $file);
|
||
|
}
|
||
|
exportGPX($list);
|
||
|
}
|
||
|
|
||
|
function readgps( $x, $path )
|
||
|
{
|
||
|
global $list;
|
||
|
$flag = false;
|
||
|
//echo $path .EOL;
|
||
|
if (exif_imagetype($path) == 2)
|
||
|
{
|
||
|
$datas = exif_read_data($path, "ANY_TAG");
|
||
|
//echo "$path\n";
|
||
|
if (! empty($datas["GPSLatitude"]))
|
||
|
{
|
||
|
$list[$x]["name"] = $path;
|
||
|
print_r( $datas );
|
||
|
$latitude = convert2decimal( $datas["GPSLatitude"][0], $datas["GPSLatitude"][1],$datas["GPSLatitude"][2] );
|
||
|
$dlatitude = $datas["GPSLatitudeRef"];
|
||
|
$longitude = convert2decimal( $datas["GPSLongitude"][0], $datas["GPSLongitude"][1],$datas["GPSLongitude"][2] );
|
||
|
$dlongitude = $datas["GPSLongitudeRef"];
|
||
|
|
||
|
|
||
|
if ($dlongitude == "S")
|
||
|
{
|
||
|
$list[$x]["longitude"] = -$longitude;
|
||
|
}else
|
||
|
{
|
||
|
$list[$x]["longitude"] = $longitude;
|
||
|
}
|
||
|
if ($dlatitude == "O")
|
||
|
{
|
||
|
$list[$x]["latitude"] = -$latitude;
|
||
|
}else
|
||
|
{
|
||
|
$list[$x]["latitude"] = $latitude;
|
||
|
}
|
||
|
if ( ! empty($datas["GPSAltitude"]) )
|
||
|
{
|
||
|
$altitude = str_replace( ",", "", number_format( transform( $datas["GPSAltitude"] ),2 ));
|
||
|
$list[$x]["altitude"] = $altitude;
|
||
|
}else
|
||
|
{
|
||
|
$list[$x]["altitude"] = "";
|
||
|
}
|
||
|
$time = gpstime( $datas["GPSTimeStamp"] );
|
||
|
//$datetime = new DateTime();
|
||
|
$date = $datas["GPSDateStamp"] . " " . $time;
|
||
|
$datetime = date_create_from_format("Y:m:d H:i:s", $date, new DateTimeZone( "UTC" ) );
|
||
|
$list[$x]["datetimeUTC"] = date( "c", $datetime->getTimestamp());
|
||
|
//echo $date . EOL;
|
||
|
if ( ! empty($datas["DateTime"]) )
|
||
|
{
|
||
|
$datetime_local = date_create_from_format("Y:m:d H:i:s", $datas["DateTime"]);
|
||
|
}elseif ( ! empty($datas["DateTimeOriginal"]) )
|
||
|
{
|
||
|
$datetime_local = date_create_from_format("Y:m:d H:i:s", $datas["DateTimeOriginal"]);
|
||
|
}else
|
||
|
{
|
||
|
$flag = true;
|
||
|
}
|
||
|
if ( $flag = false )
|
||
|
{
|
||
|
$list[$x]["datetimelocal"] = date( "c", $datetime_local->getTimestamp());
|
||
|
$dh = $datetime->diff( $datetime_local );
|
||
|
$decalagehoraire = $dh->h;
|
||
|
|
||
|
if ( $dh->i >55)
|
||
|
{
|
||
|
$decalagehoraire += 1;
|
||
|
}
|
||
|
if ( $decalagehoraire >=0 )
|
||
|
{
|
||
|
$decalagehoraire = "+" . str_pad(abs($decalagehoraire), 4, "0", STR_PAD_BOTH );
|
||
|
}else
|
||
|
{
|
||
|
$decalagehoraire = "-" . str_pad(abs($decalagehoraire), 4, "0", STR_PAD_BOTH );
|
||
|
}
|
||
|
$list[$x]["fuseauhoraire"] = $decalagehoraire;
|
||
|
}else
|
||
|
{
|
||
|
$decalagehoraire = "";
|
||
|
}
|
||
|
|
||
|
|
||
|
$datetime->setTimeZone(new DateTimeZone('Europe/Paris'));
|
||
|
echo $path . EOL;
|
||
|
echo strftime( "le %A %c heure de Paris", $datetime->getTimestamp() ) . EOL;
|
||
|
echo strftime( "le %A %c heure locale", $datetime_local->getTimestamp() ) . EOL;
|
||
|
echo "Fuseau horaire : " . $decalagehoraire .EOL;
|
||
|
echo "Latitude : $latitude $dlatitude\nLongitude : $longitude $dlongitude\nAltitude : $altitude\n";
|
||
|
//print_r($datas);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function convert2decimal( $d, $m, $s)
|
||
|
{
|
||
|
return transform( $d ) + transform($m)/60 + transform($s)/3600;
|
||
|
}
|
||
|
|
||
|
function transform($a)
|
||
|
{
|
||
|
$b = explode( "/", $a);
|
||
|
$r = floatval($b[0]) / floatval($b[1]);
|
||
|
return $r;
|
||
|
}
|
||
|
|
||
|
function gpstime( $a )
|
||
|
{
|
||
|
$h = explode("/", $a[0]);
|
||
|
$m = explode("/", $a[1]);
|
||
|
$s = explode("/", $a[2]);
|
||
|
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 );
|
||
|
}
|
||
|
|
||
|
function exportKML( $list )
|
||
|
{
|
||
|
$enteteKML = '<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2">' . EOL;
|
||
|
print_r($list);
|
||
|
if ( ! $fh = fopen("export_jpg2gpx_" . date("YmdHis") . ".kml", "w") )
|
||
|
{
|
||
|
$erreur = error_get_last();
|
||
|
echo "Erreur fopen ligne " . __LINE__ . " : " . $erreur["message"] . EOL;
|
||
|
exit (1);
|
||
|
}
|
||
|
fwrite( $fh, $enteteKML );
|
||
|
|
||
|
foreach ( $list as $ligne )
|
||
|
{
|
||
|
$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;
|
||
|
$text .= " <point>" . EOL . " <coordinates>" . $ligne["longitude"] . "," . $ligne["latitude"] . "</coordinates>" . EOL . " </point>" . EOL . " </Placemark>" . EOL;
|
||
|
fwrite( $fh, $text );
|
||
|
}
|
||
|
fwrite( $fh, "</kml>" );
|
||
|
}
|
||
|
|
||
|
function exportGPX( $list )
|
||
|
{
|
||
|
$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;
|
||
|
|
||
|
if ( ! $fh = fopen("export_jpg2gpx_" . date("YmdHis") . ".gpx", "w") )
|
||
|
{
|
||
|
$erreur = error_get_last();
|
||
|
echo "Erreur fopen ligne " . __LINE__ . " : " . $erreur["message"] . EOL;
|
||
|
exit (1);
|
||
|
}
|
||
|
fwrite( $fh, $enteteXML );
|
||
|
|
||
|
foreach ( $list as $ligne )
|
||
|
{
|
||
|
$text = '<wpt lat="' . str_replace( ",", ".", $ligne["latitude"]) . '" lon="' . str_replace( ",", ".", $ligne["longitude"]) . '">';
|
||
|
$text .= "<ele>" . $ligne["altitude"] . "</ele>";
|
||
|
$text .= "<time>" . $ligne["datetimeUTC"] . "</time>" . EOL;
|
||
|
$text .= "<name>" . basename($ligne["name"]) . "</name>" . EOL;
|
||
|
$text .= "<cmt>Généré automatiquement</cmt>" . EOL;
|
||
|
$text .= "<desc>" . $ligne["name"] . EOL;
|
||
|
if ( ! empty($ligne["datetimelocal"]) )
|
||
|
{
|
||
|
$text .= " Heure locale :" . $ligne["datetimelocal"];
|
||
|
}
|
||
|
$text .= "</desc>" . EOL;
|
||
|
$text .= "</wpt>" .EOL;
|
||
|
fwrite( $fh, $text );
|
||
|
}
|
||
|
fwrite( $fh, "</gpx>" );
|
||
|
}
|
||
|
|
||
|
function remplacevirgule ( $f )
|
||
|
{
|
||
|
|
||
|
}
|