implement 'tcx to gpx' conversion function
parent
d219584582
commit
625359f170
|
@ -342,4 +342,69 @@ function unicsvToGpx($csvFilePath) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function tcxToGpx($tcxFilePath) {
|
||||||
|
$tcxcontent = file_get_contents($tcxFilePath);
|
||||||
|
$dom_tcx = new DOMDocument();
|
||||||
|
$dom_tcx->loadXML($tcxcontent);
|
||||||
|
|
||||||
|
$dom_gpx = createDomGpxWithHeaders();
|
||||||
|
$gpx = $dom_gpx->getElementsByTagName('gpx')->item(0);
|
||||||
|
|
||||||
|
foreach ($dom_tcx->getElementsByTagName('Course') as $course) {
|
||||||
|
$name = '';
|
||||||
|
foreach ($course->getElementsByTagName('Name') as $name) {
|
||||||
|
$name = $name->nodeValue;
|
||||||
|
}
|
||||||
|
//add the new track
|
||||||
|
$gpx_trk = $dom_gpx->createElement('trk');
|
||||||
|
$gpx_trk = $gpx->appendChild($gpx_trk);
|
||||||
|
|
||||||
|
$gpx_name = $dom_gpx->createElement('name');
|
||||||
|
$gpx_name = $gpx_trk->appendChild($gpx_name);
|
||||||
|
$gpx_name_text = $dom_gpx->createTextNode($name);
|
||||||
|
$gpx_name->appendChild($gpx_name_text);
|
||||||
|
|
||||||
|
foreach ($course->getElementsByTagName('Track') as $track) {
|
||||||
|
|
||||||
|
$gpx_trkseg = $dom_gpx->createElement('trkseg');
|
||||||
|
$gpx_trkseg = $gpx_trk->appendChild($gpx_trkseg);
|
||||||
|
|
||||||
|
foreach ($track->getElementsByTagName('Trackpoint') as $trackpoint) {
|
||||||
|
|
||||||
|
$gpx_trkpt = $dom_gpx->createElement('trkpt');
|
||||||
|
$gpx_trkpt = $gpx_trkseg->appendChild($gpx_trkpt);
|
||||||
|
|
||||||
|
foreach ($trackpoint->getElementsByTagName('Time') as $time) {
|
||||||
|
$gpx_time = $dom_gpx->createElement('time');
|
||||||
|
$gpx_time = $gpx_trkpt->appendChild($gpx_time);
|
||||||
|
$gpx_time_text = $dom_gpx->createTextNode($time->nodeValue);
|
||||||
|
$gpx_time->appendChild($gpx_time_text);
|
||||||
|
}
|
||||||
|
foreach ($trackpoint->getElementsByTagName('Position') as $position) {
|
||||||
|
foreach ($trackpoint->getElementsByTagName('LatitudeDegrees') as $lat) {
|
||||||
|
$gpx_trkpt_lat = $dom_gpx->createAttribute('lat');
|
||||||
|
$gpx_trkpt->appendChild($gpx_trkpt_lat);
|
||||||
|
$gpx_trkpt_lat_text = $dom_gpx->createTextNode($lat->nodeValue);
|
||||||
|
$gpx_trkpt_lat->appendChild($gpx_trkpt_lat_text);
|
||||||
|
}
|
||||||
|
foreach ($trackpoint->getElementsByTagName('LongitudeDegrees') as $lon) {
|
||||||
|
$gpx_trkpt_lon = $dom_gpx->createAttribute('lon');
|
||||||
|
$gpx_trkpt->appendChild($gpx_trkpt_lon);
|
||||||
|
$gpx_trkpt_lon_text = $dom_gpx->createTextNode($lon->nodeValue);
|
||||||
|
$gpx_trkpt_lon->appendChild($gpx_trkpt_lon_text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($trackpoint->getElementsByTagName('AltitudeMeters') as $ele) {
|
||||||
|
$gpx_ele = $dom_gpx->createElement('ele');
|
||||||
|
$gpx_ele = $gpx_trkpt->appendChild($gpx_ele);
|
||||||
|
$gpx_ele_text = $dom_gpx->createTextNode($ele->nodeValue);
|
||||||
|
$gpx_ele->appendChild($gpx_ele_text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dom_gpx->saveXML();
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue