| 1 |
<?
|
| 2 |
// $Id: track.gpx.inc,v 1.4 2006/11/10 22:04:55 gaby Exp $
|
| 3 |
|
| 4 |
class GPX_file {
|
| 5 |
var $coordonnees = array();
|
| 6 |
var $catData = "";
|
| 7 |
var $catDataTime = "";
|
| 8 |
var $currentTag = "";
|
| 9 |
var $count = 0;
|
| 10 |
var $ZMax = -1;
|
| 11 |
var $GPXfile = "";
|
| 12 |
|
| 13 |
function debutElement($parser, $name, $attrs)
|
| 14 |
{
|
| 15 |
$this->currentTag = $name;
|
| 16 |
|
| 17 |
if ($name == "TRKPT") {
|
| 18 |
$this->coordonnees[$this->count][0] = $attrs["LAT"];
|
| 19 |
$this->coordonnees[$this->count][1] = $attrs["LON"];
|
| 20 |
$this->count++;
|
| 21 |
}
|
| 22 |
}
|
| 23 |
|
| 24 |
function characterData($parser, $data)
|
| 25 |
{
|
| 26 |
if ($this->currentTag == "ELE") {
|
| 27 |
$this->catData .= trim($data);
|
| 28 |
}
|
| 29 |
if ($this->currentTag == "TIME") {
|
| 30 |
$this->catDataTime .= trim($data);
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
| 34 |
function getZMax() {
|
| 35 |
return $ZMax;
|
| 36 |
}
|
| 37 |
|
| 38 |
function finElement($parser, $name)
|
| 39 |
{
|
| 40 |
if ($name = "ELE") {
|
| 41 |
if ($this->catData != "") {
|
| 42 |
$ZMax = max($ZMax, $this->catData);
|
| 43 |
$this->coordonnees[$this->count-1][2] = $this->catData;
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
if ($name = "TIME") {
|
| 48 |
if ($this->catDataTime != "") {
|
| 49 |
$this->coordonnees[$this->count-1][3] = $this->catDataTime;
|
| 50 |
}
|
| 51 |
}
|
| 52 |
|
| 53 |
unset($this->catData);
|
| 54 |
$this->catData = "";
|
| 55 |
unset($this->catDataTime);
|
| 56 |
$this->catDataTime = "";
|
| 57 |
}
|
| 58 |
|
| 59 |
function DenivelePositif() {
|
| 60 |
$denivp = 0;
|
| 61 |
|
| 62 |
$z = $this->ZArray();
|
| 63 |
|
| 64 |
for ($i=1; $i<count($z); $i++) {
|
| 65 |
if (($z[$i] - $z[$i-1])>0)
|
| 66 |
{
|
| 67 |
$denivp += ($z[$i] - $z[$i-1]);
|
| 68 |
}
|
| 69 |
}
|
| 70 |
return $denivp;
|
| 71 |
}
|
| 72 |
|
| 73 |
function DeniveleNegatif() {
|
| 74 |
$denivm = 0;
|
| 75 |
$z = $this->ZArray();
|
| 76 |
|
| 77 |
for ($i=1; $i<count($z); $i++) {
|
| 78 |
if (($z[$i] - $z[$i-1])<0)
|
| 79 |
$denivm += ($z[$i] - $z[$i-1]);
|
| 80 |
}
|
| 81 |
return $denivm;
|
| 82 |
}
|
| 83 |
|
| 84 |
function XArray() {
|
| 85 |
$res = array();
|
| 86 |
|
| 87 |
$r = 6378;
|
| 88 |
|
| 89 |
$pi = atan2(1,1) * 4;
|
| 90 |
|
| 91 |
$dist = 0;
|
| 92 |
$res[] = 0;
|
| 93 |
for ($i=1; $i<$this->count; $i++) {
|
| 94 |
$a1 = $this->coordonnees[$i-1][0] * ($pi/180);
|
| 95 |
$a2 = $this->coordonnees[$i][0] * ($pi/180);
|
| 96 |
$b1 = $this->coordonnees[$i-1][1] * ($pi/180);
|
| 97 |
$b2 = $this->coordonnees[$i][1] * ($pi/180);
|
| 98 |
|
| 99 |
if ( ($a1==$a2) && ($b1==$b2) )
|
| 100 |
$delta = 0;
|
| 101 |
else
|
| 102 |
{
|
| 103 |
$toacos = cos($a1)*cos($b1)*cos($a2)*cos($b2) + cos($a1)*sin($b1)*cos($a2)*sin($b2) + sin($a1)*sin($a2);
|
| 104 |
|
| 105 |
if ($toacos > 1)
|
| 106 |
$delta = 0;
|
| 107 |
else
|
| 108 |
$delta = acos($toacos) * $r;
|
| 109 |
}
|
| 110 |
$dist += $delta;
|
| 111 |
$res[] = $dist;
|
| 112 |
}
|
| 113 |
return $res;
|
| 114 |
}
|
| 115 |
|
| 116 |
function Pentes() {
|
| 117 |
$res = array();
|
| 118 |
for ($i=0; $i<41; $i++) {
|
| 119 |
$res[] = $i-20;
|
| 120 |
}
|
| 121 |
return $res;
|
| 122 |
}
|
| 123 |
|
| 124 |
function RepartitionPentes() {
|
| 125 |
$datax = $this->XArray();
|
| 126 |
$datay = $this->ZArray();
|
| 127 |
|
| 128 |
$res = array();
|
| 129 |
for ($i=0; $i<41; $i++) {
|
| 130 |
$res[] = 0;
|
| 131 |
}
|
| 132 |
|
| 133 |
for ($i=1; $i<count($datax); $i++) {
|
| 134 |
$distance = ($datax[$i] - $datax[$i - 1]) * 1000;
|
| 135 |
$dz = $datay[$i] - $datay[$i - 1];
|
| 136 |
if ($distance>0) {
|
| 137 |
$pente = (100 * $dz) / $distance;
|
| 138 |
if ($pente<-20) {
|
| 139 |
$res[0] += $distance;
|
| 140 |
} else
|
| 141 |
if ($pente>20) {
|
| 142 |
$res[40] += $distance;
|
| 143 |
} else
|
| 144 |
{
|
| 145 |
$ires = round($pente + 20);
|
| 146 |
$res[$ires] += $distance;
|
| 147 |
}
|
| 148 |
}
|
| 149 |
}
|
| 150 |
|
| 151 |
for ($i=0; $i<41; $i++) {
|
| 152 |
$res[$i] = $res[$i] / 1000;
|
| 153 |
}
|
| 154 |
return $res;
|
| 155 |
}
|
| 156 |
|
| 157 |
function FilterValue($valuearray) {
|
| 158 |
sort($valuearray, SORT_NUMERIC);
|
| 159 |
$newarray = array();
|
| 160 |
for ($i=1; $i<count($valuearray)-1; $i++) {
|
| 161 |
$newarray[] = $valuearray[$i];
|
| 162 |
}
|
| 163 |
return array_sum($newarray)/count($newarray);
|
| 164 |
}
|
| 165 |
|
| 166 |
function FilterArray($anarray) {
|
| 167 |
$res = array();
|
| 168 |
|
| 169 |
if (count($anarray)>5) {
|
| 170 |
for ($i=0; $i<5; $i++) {
|
| 171 |
$res[] = $anarray[$i];
|
| 172 |
}
|
| 173 |
|
| 174 |
for ($i=5; $i<count($anarray); $i++) {
|
| 175 |
$res[] = $this->FilterValue( array($anarray[$i-5], $anarray[$i-4], $anarray[$i-3], $anarray[$i-2], $anarray[$i-1], $anarray[$i]) );
|
| 176 |
}
|
| 177 |
}
|
| 178 |
else
|
| 179 |
$res = $anarray;
|
| 180 |
|
| 181 |
return $res;
|
| 182 |
}
|
| 183 |
|
| 184 |
function ZArray() {
|
| 185 |
$res = array();
|
| 186 |
for ($i=0; $i<$this->count; $i++) {
|
| 187 |
$res[] = $this->coordonnees[$i][2];
|
| 188 |
}
|
| 189 |
return $this->FilterArray($res);
|
| 190 |
}
|
| 191 |
|
| 192 |
function Longueur() {
|
| 193 |
$r = 6378;
|
| 194 |
|
| 195 |
$pi = atan2(1,1) * 4;
|
| 196 |
|
| 197 |
$dist = 0;
|
| 198 |
for ($i=1; $i<$this->count; $i++) {
|
| 199 |
$a1 = $this->coordonnees[$i-1][0] * ($pi/180);
|
| 200 |
$a2 = $this->coordonnees[$i][0] * ($pi/180);
|
| 201 |
$b1 = $this->coordonnees[$i-1][1] * ($pi/180);
|
| 202 |
$b2 = $this->coordonnees[$i][1] * ($pi/180);
|
| 203 |
|
| 204 |
if ( ($a1==$a2) && ($b1==$b2) )
|
| 205 |
$delta = 0;
|
| 206 |
else
|
| 207 |
{
|
| 208 |
$toacos = cos($a1)*cos($b1)*cos($a2)*cos($b2) + cos($a1)*sin($b1)*cos($a2)*sin($b2) + sin($a1)*sin($a2);
|
| 209 |
|
| 210 |
if ($toacos > 1)
|
| 211 |
$delta = 0;
|
| 212 |
else
|
| 213 |
$delta = acos($toacos) * $r;
|
| 214 |
}
|
| 215 |
$dist += $delta;
|
| 216 |
}
|
| 217 |
return $dist;
|
| 218 |
}
|
| 219 |
|
| 220 |
function XMLforProfile() {
|
| 221 |
$datax = $this->XArray();
|
| 222 |
$datay = $this->ZArray();
|
| 223 |
|
| 224 |
$n = count($datax);
|
| 225 |
|
| 226 |
$ymin = 100000;
|
| 227 |
$ymax = -100000;
|
| 228 |
|
| 229 |
for ($i=0; $i<($n-1); $i++) {
|
| 230 |
$ymin = min($ymin, $datay[$i]);
|
| 231 |
$ymax = max($ymax, $datay[$i]);
|
| 232 |
}
|
| 233 |
|
| 234 |
echo "<graph caption='".t("Profile")."' xaxisname='".t("Distance")."' yaxisname='".t("Altitude")."' ";
|
| 235 |
echo "showAreaBorder='0' lineThickness='1' numdivlines='10' numVDivLines='10' showgridbg='1' showhovercap='1' ";
|
| 236 |
echo "showVerLines='0' hoverCapSepChar=' ' yaxisminvalue='".$ymin."' yaxismaxvalue='".$ymax."' anchorScale='0' showNames='1' showValues='0' animation='0'>\n";
|
| 237 |
|
| 238 |
$ndata = 200;
|
| 239 |
$step = ($datax[$n-1])/$ndata;
|
| 240 |
|
| 241 |
// echo $step;
|
| 242 |
|
| 243 |
$curindex = 0;
|
| 244 |
|
| 245 |
$values = array();
|
| 246 |
$xvalues = array();
|
| 247 |
|
| 248 |
for ($i=0; $i<($ndata-1); $i++) {
|
| 249 |
$xmin = $i * $step;
|
| 250 |
$xmax = ($i+1) * $step;
|
| 251 |
$index = $curindex;
|
| 252 |
|
| 253 |
// echo $i." ".$xmin." ".$xmax." ".."\n";
|
| 254 |
|
| 255 |
while (($datax[$index] < $xmax) && ($index<$n))
|
| 256 |
$index++;
|
| 257 |
$val = 0;
|
| 258 |
$valn = 0;
|
| 259 |
|
| 260 |
$maxv = -10000;
|
| 261 |
$minv = 25000;
|
| 262 |
|
| 263 |
for ($j=$curindex; $j<$index; $j++) {
|
| 264 |
$val+=$datay[$j];
|
| 265 |
$maxv = max($maxv, $datay[$j]);
|
| 266 |
$minv = min($minv, $datay[$j]);
|
| 267 |
$valn++;
|
| 268 |
}
|
| 269 |
if ($valn>0) {
|
| 270 |
$vavg = $val / $valn;
|
| 271 |
|
| 272 |
$deltamin = $vavg - $minv;
|
| 273 |
$deltamax = $maxv - $vavg;
|
| 274 |
|
| 275 |
$currentval = $vavg;
|
| 276 |
|
| 277 |
if (max($deltamin, $deltamax)>15) {
|
| 278 |
if ($deltamin>$deltamax)
|
| 279 |
$currentval = $minv;
|
| 280 |
else
|
| 281 |
$currentval = $maxv;
|
| 282 |
}
|
| 283 |
|
| 284 |
$values[] = $currentval;
|
| 285 |
$xvalues[] = $xmin;
|
| 286 |
|
| 287 |
$curindex = $index;
|
| 288 |
}
|
| 289 |
}
|
| 290 |
|
| 291 |
$values[] = $datay[$n-1];
|
| 292 |
$xvalues[] = $datax[$n-1];
|
| 293 |
|
| 294 |
for ($i=0; $i<count($values); $i++) {
|
| 295 |
if (($i==0) || ($i==(count($values)-1)))
|
| 296 |
echo "\n<set name='".sprintf('%2.2f',$xvalues[$i])."' value='".$values[$i]."' showName='1'/>";
|
| 297 |
else
|
| 298 |
echo "\n<set value='".$values[$i]."' showName='0'/>";
|
| 299 |
}
|
| 300 |
echo "</graph>";
|
| 301 |
}
|
| 302 |
|
| 303 |
|
| 304 |
function XMLforRepartition() {
|
| 305 |
/*
|
| 306 |
<graph bgcolor='e1f5ff' canvasbgcolor="FFFFFF" caption='Decline in Net Interest Margins of Asian Banks (1995-2001)' subCaption='(in Percentage %)' yaxismaxvalue="2" yaxisminvalue='-2.5' yaxisname='Points' xaxisname='Country' gridbgcolor='f1f1f1' hovercapbg='FFFFDD' hovercapborder='000000' numdivlines='4' divlinecolor='999999' zeroPlaneColor="333333" zeroPlaneAlpha='40' numberSuffix=' %'>
|
| 307 |
<set name='Taiwan' value='-0.33' color='F23456'/>
|
| 308 |
<set name='Malaysia' value='-0.27' color='FF6600'/>
|
| 309 |
<set name='Hong Kong' value='0.40' color='009966' alpha='70'/>
|
| 310 |
<set name='Philippines' value='0.6' color='CC3399'/>
|
| 311 |
<set name='Singapore' value='-0.8' color='FFCC33' alpha='70'/>
|
| 312 |
<set name='Thailand' value='-2.2' color='F23456'/>
|
| 313 |
<set name='India' value='1.2' color='FF6600'/>
|
| 314 |
<trendlines>
|
| 315 |
<line value='0.8' displayValue='Good' color='FF0000' thickness='1'/>
|
| 316 |
<line value='-0.4' displayValue='Bad' color='009999' thickness='1'/>
|
| 317 |
</trendlines>
|
| 318 |
</graph>
|
| 319 |
*/
|
| 320 |
|
| 321 |
echo "<graph caption='".t("Histogram")."' subCaption='' yaxisname='".t("Distance")."' xaxisname='".t("Difficulty")."' ynumdivlines='4' numberSuffix=' km'>";
|
| 322 |
|
| 323 |
$trans = get_html_translation_table(HTML_ENTITIES);
|
| 324 |
|
| 325 |
$l = $this->Longueur();
|
| 326 |
|
| 327 |
$datax = $this->Pentes();
|
| 328 |
$datay = $this->RepartitionPentes();
|
| 329 |
|
| 330 |
$tot = 0;
|
| 331 |
for ($i=0; $i<10; $i++) {
|
| 332 |
$tot += $datay[$i];
|
| 333 |
}
|
| 334 |
echo "<set name='".t("Steep descent")."' value='".$tot."' />"; //<-10%
|
| 335 |
|
| 336 |
$tot = 0;
|
| 337 |
for ($i=10; $i<19; $i++) {
|
| 338 |
$tot += $datay[$i];
|
| 339 |
}
|
| 340 |
echo "<set name='".t("Descent")."' value='".$tot."' />"; //(entre -10% et -2%)
|
| 341 |
|
| 342 |
$tot = 0;
|
| 343 |
for ($i=19; $i<22; $i++) {
|
| 344 |
$tot += $datay[$i];
|
| 345 |
}
|
| 346 |
echo "<set name='".t("Flat")."' value='".$tot."' />"; // (entre -2% et 2%)
|
| 347 |
|
| 348 |
$tot = 0;
|
| 349 |
for ($i=22; $i<31; $i++) {
|
| 350 |
$tot += $datay[$i];
|
| 351 |
}
|
| 352 |
echo "<set name='".t("Ascent")."' value='".$tot."' />"; //(entre 2% et 10%)
|
| 353 |
|
| 354 |
$tot = 0;
|
| 355 |
for ($i=31; $i<41; $i++) {
|
| 356 |
$tot += $datay[$i];
|
| 357 |
}
|
| 358 |
echo "<set name='".t("Steep ascent")."' value='".$tot."' />"; //(>10%)
|
| 359 |
|
| 360 |
echo "</graph>";
|
| 361 |
}
|
| 362 |
|
| 363 |
function htmlentities2unicodeentities ($input) {
|
| 364 |
$htmlEntities = array_values (get_html_translation_table (HTML_ENTITIES, ENT_QUOTES));
|
| 365 |
$entitiesDecoded = array_keys (get_html_translation_table (HTML_ENTITIES, ENT_QUOTES));
|
| 366 |
$num = count ($entitiesDecoded);
|
| 367 |
for ($u = 0; $u < $num; $u++) {
|
| 368 |
$utf8Entities[$u] = '&#'.ord($entitiesDecoded[$u]).';';
|
| 369 |
}
|
| 370 |
return str_replace ($htmlEntities, $utf8Entities, $input);
|
| 371 |
}
|
| 372 |
|
| 373 |
function PointsForGoogleMaps($npoints) {
|
| 374 |
$points = array();
|
| 375 |
$step = max(1, floor(count($this->coordonnees) / $npoints));
|
| 376 |
|
| 377 |
$j=0;
|
| 378 |
for ($i=0; $i<$this->count; $i++) {
|
| 379 |
if ($i % $step < 1) {
|
| 380 |
$points[$j][1] = $this->coordonnees[$i][0];
|
| 381 |
$points[$j][0] = $this->coordonnees[$i][1];
|
| 382 |
$j++;
|
| 383 |
}
|
| 384 |
}
|
| 385 |
|
| 386 |
return $points;
|
| 387 |
}
|
| 388 |
|
| 389 |
function ConvertToKML() {
|
| 390 |
header('Content-Type: application/vnd.google-earth.kml+xml');
|
| 391 |
header('Content-Disposition: attachment; filename="'.substr($this->GPXfile, 0, -4).'.kml"');
|
| 392 |
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
|
| 393 |
?>
|
| 394 |
<kml xmlns="http://earth.google.com/kml/2.1">
|
| 395 |
<Document>
|
| 396 |
<name><? echo $this->GPXfile; ?></name>
|
| 397 |
<open>1</open>
|
| 398 |
<Style id="lineStyle">
|
| 399 |
<LineStyle>
|
| 400 |
<color>6422FF22</color>
|
| 401 |
<width>4</width>
|
| 402 |
</LineStyle>
|
| 403 |
</Style>
|
| 404 |
<Folder>
|
| 405 |
<open>1</open>
|
| 406 |
<name><? echo $this->GPXfile; ?></name>
|
| 407 |
<Placemark>
|
| 408 |
<visibility>1</visibility>
|
| 409 |
<name><? echo $this->GPXfile; ?></name>
|
| 410 |
<Style>
|
| 411 |
<IconStyle>
|
| 412 |
<Icon>
|
| 413 |
<href>root://icons/palette-4.png</href>
|
| 414 |
<y>32</y>
|
| 415 |
<w>32</w>
|
| 416 |
<h>32</h>
|
| 417 |
</Icon>
|
| 418 |
</IconStyle>
|
| 419 |
</Style>
|
| 420 |
<Point>
|
| 421 |
<extrude>1</extrude>
|
| 422 |
<coordinates><? echo $this->coordonnees[0][1].",".$this->coordonnees[0][0].",0"; ?></coordinates>
|
| 423 |
</Point>
|
| 424 |
<description><? echo $this->htmlentities2unicodeentities(t("Length")." : ". sprintf('%2.2f', $this->Longueur()) ."km <br> ".t("D+")." : ". sprintf('%2.0f', $this->DenivelePositif()) ."m / ".t("D-")." : ". sprintf('%2.0f', $this->DeniveleNegatif()) ."m"); ?></description>
|
| 425 |
</Placemark>
|
| 426 |
<Placemark>
|
| 427 |
<name>Path</name>
|
| 428 |
<styleUrl>#lineStyle</styleUrl>
|
| 429 |
<LineString>
|
| 430 |
<tessellate>1</tessellate>
|
| 431 |
<coordinates>
|
| 432 |
<?
|
| 433 |
for ($i=0; $i<count($this->coordonnees) - 1; $i++) {
|
| 434 |
?>
|
| 435 |
<? echo $this->coordonnees[$i][1].",".$this->coordonnees[$i][0].",0"; ?>
|
| 436 |
<?
|
| 437 |
}
|
| 438 |
?>
|
| 439 |
</coordinates>
|
| 440 |
</LineString>
|
| 441 |
</Placemark>
|
| 442 |
</Folder>
|
| 443 |
</Document>
|
| 444 |
</kml>
|
| 445 |
<?
|
| 446 |
}
|
| 447 |
|
| 448 |
function ConvertToTRK() {
|
| 449 |
|
| 450 |
header('Content-Disposition: attachment; filename="'.substr($this->GPXfile, 0, -4).'.trk"');
|
| 451 |
?>
|
| 452 |
|
| 453 |
H SOFTWARE NAME & VERSION
|
| 454 |
I PCX5 2.09
|
| 455 |
|
| 456 |
H R DATUM IDX DA DF DX DY DZ
|
| 457 |
M G WGS 84 121 +0.000000e+000 +0.000000e+000 +0.000000e+000 +0.000000e+000 +0.000000e+000
|
| 458 |
|
| 459 |
H COORDINATE SYSTEM
|
| 460 |
U LAT LON DEG
|
| 461 |
|
| 462 |
H LATITUDE LONGITUDE DATE TIME ALT ;track
|
| 463 |
<?php
|
| 464 |
for ($i=0; $i<$this->count; $i++) {
|
| 465 |
$lat = $this->coordonnees[$i][0];
|
| 466 |
$lon = $this->coordonnees[$i][1];
|
| 467 |
$alt = abs($this->coordonnees[$i][2]);
|
| 468 |
printf('T ');
|
| 469 |
//T N47.5118714 W002.2987803 19-OCT-03 08:46:25 00038
|
| 470 |
|
| 471 |
if ($lat>0) {
|
| 472 |
printf('N', $lat);
|
| 473 |
}
|
| 474 |
else
|
| 475 |
{
|
| 476 |
$lat = - $lat;
|
| 477 |
printf('S', $lat);
|
| 478 |
}
|
| 479 |
|
| 480 |
printf('%02d', $lat);
|
| 481 |
printf('.');
|
| 482 |
// 0.5118714 -> 5118714
|
| 483 |
printf('%07d', ($lat - floor($lat)) * 10000000);
|
| 484 |
|
| 485 |
printf(' ');
|
| 486 |
|
| 487 |
if ($lon>0) {
|
| 488 |
printf('E', $lon);
|
| 489 |
}
|
| 490 |
else
|
| 491 |
{
|
| 492 |
$lon = - $lon;
|
| 493 |
printf('W', $lon);
|
| 494 |
}
|
| 495 |
|
| 496 |
printf('%03d', $lon);
|
| 497 |
printf('.');
|
| 498 |
// 0.5118714 -> 5118714
|
| 499 |
printf('%07d', ($lon - floor($lon)) * 10000000);
|
| 500 |
|
| 501 |
$datetime = $this->coordonnees[$i][3];
|
| 502 |
// 2005-10-29T11:00:49Z -> 30-DEC-99 00:00:00
|
| 503 |
$annee = substr($datetime, 0, 4);
|
| 504 |
$mois = substr($datetime, 5, 2);
|
| 505 |
$jour = substr($datetime, 8, 2);
|
| 506 |
$heure = substr($datetime, 11, 2);
|
| 507 |
$minute = substr($datetime, 14, 2);
|
| 508 |
$seconde = substr($datetime, 17, 2);
|
| 509 |
$dt = mktime($heure, $minute, $seconde, $mois, $jour, $annee);
|
| 510 |
printf(" ".strtoupper(date("d-M-y H:i:s", $dt))." ");
|
| 511 |
printf('%05d', $alt);
|
| 512 |
printf("\n");
|
| 513 |
}
|
| 514 |
}
|
| 515 |
|
| 516 |
function getInfos(&$latstart,&$lonstart,&$latmin,&$latmax,&$lonmin,&$lonmax,&$length,&$dzminu,&$dzplus,&$zmin,&$zmax) {
|
| 517 |
$length = $this->Longueur();
|
| 518 |
$dzplus = $this->DenivelePositif();
|
| 519 |
$dzminu = $this->DeniveleNegatif();
|
| 520 |
|
| 521 |
$latmin = 200.0;
|
| 522 |
$lonmin = 200.0;
|
| 523 |
$zmin = 20000.0;
|
| 524 |
|
| 525 |
$latmax = -200.0;
|
| 526 |
$lonmax = -200.0;
|
| 527 |
$zmax = -20000.0;
|
| 528 |
|
| 529 |
$latstart = 0.0;
|
| 530 |
$lonstart = 0.0;
|
| 531 |
|
| 532 |
for ($i=0; $i<$this->count; $i++) {
|
| 533 |
$lat = $this->coordonnees[$i][0];
|
| 534 |
$lon = $this->coordonnees[$i][1];
|
| 535 |
$alt = $this->coordonnees[$i][2];
|
| 536 |
|
| 537 |
$latstart += $lat;
|
| 538 |
$lonstart += $lon;
|
| 539 |
|
| 540 |
$latmin = min($latmin, $lat);
|
| 541 |
$lonmin = min($lonmin, $lon);
|
| 542 |
$zmin = min($zmin, $alt);
|
| 543 |
|
| 544 |
$latmax = max($latmax, $lat);
|
| 545 |
$lonmax = max($lonmax, $lon);
|
| 546 |
$zmax = max($zmax, $alt);
|
| 547 |
}
|
| 548 |
$latstart = (1.0*$latstart) / (1.0*$this->count);
|
| 549 |
$lonstart = (1.0*$lonstart) / (1.0*$this->count);
|
| 550 |
}
|
| 551 |
|
| 552 |
function LoadFromFile($filename) {
|
| 553 |
$this->GPXfile = basename($filename);
|
| 554 |
$xml_parser = xml_parser_create();
|
| 555 |
xml_set_element_handler($xml_parser, array(&$this,"debutElement"), array(&$this,"finElement"));
|
| 556 |
xml_set_character_data_handler($xml_parser, array(&$this,"characterData"));
|
| 557 |
if (!($fp = fopen($filename, "r"))) {
|
| 558 |
die("Can't open file: ".$filename);
|
| 559 |
}
|
| 560 |
|
| 561 |
while ($data = fread($fp, 4096)) {
|
| 562 |
if (!xml_parse($xml_parser, $data, feof($fp))) {
|
| 563 |
die(sprintf("erreur XML : %s à la ligne %d",
|
| 564 |
xml_error_string(xml_get_error_code($xml_parser)),
|
| 565 |
xml_get_current_line_number($xml_parser)));
|
| 566 |
}
|
| 567 |
}
|
| 568 |
xml_parser_free($xml_parser);
|
| 569 |
}
|
| 570 |
|
| 571 |
}
|