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); }
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'; }
public function write() { $gpx = new \SimpleXMLElement("<gpx></gpx>"); foreach ($this->document->getAttributes() as $index => $attribute) { $gpx->addAttribute($index, $attribute); } foreach ($this->document->readyXML() as $index => $value) { if (!$value instanceof Collection) { if (is_object($value)) { $child = $gpx->addChild($index); return $this->recursiveFunction($value, $child); } else { $gpx->addChild($index, $value); } } } //$this->recursiveFunction($this->document, $gpx); /*foreach ($this->document->readyXML() as $index => $value) { $child = $gpx->addChild($index); if (! $value instanceof Collection) { foreach ($value->readyXML() as $index => $value) { if (is_object($value)) { $grandChild = $gpx->addChild($index); foreach ($value->readyXML() as $index => $value) { $grandChild->addChild($index); if (is_object($value)) { $greatGrandChild = $gpx->addChild($index); foreach ($value->readyXML() as $index => $value) { $greatGrandChild->addChild($index, $value); } } else { $grandChild->addChild($index, $value); } } } else { $child->addChild($index, $value); } } } }*/ if ($this->document->getMetadata() instanceof Metadata) { $metadata = $gpx->addChild('metadata'); foreach ($this->document->getMetadata()->readyXML() as $index => $value) { if (is_object($value)) { } } $metadata->addChild('name', $this->document->getMetadata()->getName()); } if ($this->document->getWaypointCollection()->hasValues()) { $gpx->addChild('wpt'); } //$gpx->addChild('wpt'); /*foreach ($this->document->getWaypoints() as $waypoints) { foreach ($waypoints->getAttributes() as $index => $attribute) { $gpx->addAttribute($index, $attribute); } }*/ $test = $gpx->asXML(); /*$properties = $this->findMethods($this->document); foreach($properties as $index => $value) { echo 'hi'; }*/ }