fix elevation of gpxfile from another gpx file with barometer
PHP5 CLI version (command line).
gpx_fix_ele_cli.php
#!/usr/bin/php
#fix elevation of gpxfile from another gpx file with barometer
<?php
$file_in="La_Estancita_Race_2017_.gpx"; // gpx to fix
$file_in_ok="strava_full_seba.gpx"; // gpx to extract correct elevation
$file_out=substr($file_in,0,-4).'_fixed.gpx';
if (!file($file_in)) {echo "Error\n$file_in no existe.";die;}
if (!file($file_in_ok)) {echo "Error\n$file_in no existe.";die;}
$gpx1 = simplexml_load_file($file_in);
$gpx2 = simplexml_load_file($file_in_ok);
$i=0;
foreach ($gpx1->trk->trkseg->children() as $trk1) {
$lat = (string) $trk1['lat'];
$lon = (string) $trk1['lon'];
$ele = (string) $trk1->ele;
$name = (string) $trk1->name;
$newele=find_ele($lat,$lon);
if ($newele) {
<------>$gpx1->trk->trkseg->trkpt[$i]->ele=$newele;
}
$i++;
}
echo "writing $file_out\n";
file_put_contents($file_out, $gpx1->asXML());
unset($gpx1);
unset($gpx2);
die;
function find_ele($lat1,$lon1) {
$gpx2=$GLOBALS['gpx2'];
$newele=false;
$mindist=5000;
foreach ($gpx2->trk->trkseg->children() as $trk2) {
<------>$lat2 = (string) $trk2['lat'];
<------>$lon2 = (string) $trk2['lon'];
<------>$grados = rad2deg(acos((sin(deg2rad($lat1))*sin(deg2rad($lat2)))+
<------><------>(cos(deg2rad($lat1))*cos(deg2rad($lat2))*cos(deg2rad($lon1-$lon2)))));
<------>$d = round($grados * 111133.84,6);
<------>if ($d<$mindist) {
<------> $mindist=$d;
<------> $newele=(string) $trk2->ele;
<------>}
}
echo ".";
return $newele;
}
No hay comentarios:
Publicar un comentario