Exemplo n.º 1
0
 public function parseGPXAsObject()
 {
     $this->document = new Document();
     //Collect all root attributes for gpx
     $attributes = $this->fillAttributes($this->xml);
     if ($this->areAttributesFilled($attributes)) {
         $this->document->setAttributes($attributes);
     }
     /**
      * @var  $index
      * @var SimpleXMLElement $xml
      */
     foreach ($this->xml as $index => $xml) {
         if ($this->isMetadata($index)) {
             $this->parseMetadata($xml);
         }
         if ($this->isWaypoint($index)) {
             $this->parseWaypoint($xml);
         }
         if ($this->isTrack($index)) {
             $this->parseTrack($xml);
         }
         if ($this->isRoute($index)) {
             $this->parseRoute($xml);
         }
     }
     /*while($this->xml->read()) {
     
                 $this->document->setCreator($this->xml->getAttribute('creator'));
                 $this->document->setVersion($this->xml->getAttribute('version'));
     
                 if($this->xml->nodeType == \XMLReader::ELEMENT) {
                     $nodeName[] = $this->xml->name;
                 }
     
                 if ($this->xml->localName == 'wpt' && $this->xml->nodeType == \XMLReader::ELEMENT)
                     $this->parseWaypoints();
     
                 if ($this->xml->localName == 'trk' && $this->xml->nodeType == \XMLReader::ELEMENT)
                     $this->parseTracks();
     
                 if ($this->xml->localName == 'trkseg' && $this->xml->nodeType == \XMLReader::ELEMENT)
                     $this->parseTrackSegments();
             }*/
     /*foreach ($this->document->getTracks() as $track) {
           foreach ($track->getTrkseg() as $trackSegment) {
               foreach($trackSegment->getTrkpt() as $point) {
                   $test[] = $point->getLat();
               }
           }
       }*/
     //echo 'test';
 }
Exemplo n.º 2
0
 public function setUp()
 {
     $document = new Document();
     $attributes = array('creator' => 'John Doe', 'version' => 1.1);
     $document->setAttributes($attributes);
     $metadata = new Metadata();
     $metadata->setName('GPX File');
     $metadata->setDesc('Description');
     $author = new Person();
     $author->setName('John');
     $email = new Email();
     $attributes = array('id' => 'john', 'domain' => 'test.com');
     $email->setAttributes($attributes);
     $author->setEmail($email);
     $metadata->setAuthor($author);
     $copyright = new Copyright();
     $copyright->setYear(2005);
     $copyright->setLicense('MIT');
     $metadata->setCopyright($copyright);
     $link = new Link();
     $link->setAttributes(array('href' => 'test.com'));
     $metadata->setLink($link);
     $metadata->setKeywords('123');
     $bounds = new Bound();
     $bounds->setAttributes(array('minlat' => 1, 'minlon' => 5, 'maxlat' => 10, 'maxlon' => 20));
     $metadata->setBounds($bounds);
     $document->setMetadata($metadata);
     $waypoint = new Waypoint();
     $attributes = array('lat' => 46.57638889, 'lon' => 8.892638890000001);
     $waypoint->setAttributes($attributes);
     $waypoint->setEle(2372);
     $waypoint->setName('LAGORETICO');
     $document->addWaypoint($waypoint);
     $track = new Track();
     $track->setName('Example gpx');
     $track->setNumber(1);
     $ts = new TrackSegment();
     $waypoint = new Waypoint();
     $attributes = array("lat" => 46.57608333, "lon" => 8.892416669999999);
     $waypoint->setAttributes($attributes);
     $waypoint->setEle(2376);
     $waypoint->setTime('2007-10-14T10:09:57Z');
     $ts->addTrack($waypoint);
     $track->addTrackSegment($ts);
     $document->addTrack($track);
     $this->writer = new Writer($document);
 }