Exemplo n.º 1
0
 /**
  * @param SimpleXMLElement $xml
  * @return TrackSegment
  * @throws InvalidGPXException
  */
 public static function fromXML(SimpleXMLElement $xml)
 {
     $trackSegment = new TrackSegment();
     if (!empty($xml->trkpt)) {
         $trackPoints = [];
         foreach ($xml->trkpt as $trackPoint) {
             array_push($trackPoints, Waypoint::fromXML($trackPoint));
         }
         $trackSegment->setTrackPoints($trackPoints);
     }
     if (!empty($xml->extensions)) {
         $trackSegment->setExtensions(Extensions::fromXML($xml->extensions[0]));
     }
     return $trackSegment;
 }
Exemplo n.º 2
0
 /**
  * @param SimpleXMLElement $xml
  * @return Waypoint
  * @throws InvalidGPXException
  */
 public static function fromXML(SimpleXMLElement $xml)
 {
     $attributes = $xml->attributes();
     if (!($latitude = $attributes['lat'])) {
         throw new InvalidGPXException("No latitude specified on waypoint node.");
     }
     if (!($longitude = $attributes['lon'])) {
         throw new InvalidGPXException("No longitude specified on waypoint node.");
     }
     $waypoint = new Waypoint((double) $latitude, (double) $longitude);
     if (!empty($xml->ele)) {
         $waypoint->setElevation((double) $xml->ele[0]);
     }
     if (!empty($xml->time)) {
         $waypoint->setTime(strtotime((string) $xml->time[0]));
     }
     if (!empty($xml->magvar)) {
         $waypoint->setMagvar((double) $xml->magvar[0]);
     }
     if (!empty($xml->geoidheight)) {
         $waypoint->setGeoidheight((double) $xml->geoidheight[0]);
     }
     if (!empty($xml->name)) {
         $waypoint->setName((string) $xml->name[0]);
     }
     if (!empty($xml->cmt)) {
         $waypoint->setComment((string) $xml->cmt[0]);
     }
     if (!empty($xml->desc)) {
         $waypoint->setDescription((string) $xml->desc[0]);
     }
     if (!empty($xml->src)) {
         $waypoint->setSource((string) $xml->src[0]);
     }
     if (!empty($xml->link)) {
         $links = [];
         foreach ($xml->link as $link) {
             array_push($links, Link::fromXML($link));
         }
         $waypoint->setLinks($links);
     }
     if (!empty($xml->sym)) {
         $waypoint->setSymbol((string) $xml->sym[0]);
     }
     if (!empty($xml->type)) {
         $waypoint->setType((string) $xml->type[0]);
     }
     if (!empty($xml->fix)) {
         $waypoint->setFix((string) $xml->fix[0]);
     }
     if (!empty($xml->sat)) {
         $waypoint->setFix((int) $xml->sat[0]);
     }
     if (!empty($xml->hdop)) {
         $waypoint->setHdop((double) $xml->hdop[0]);
     }
     if (!empty($xml->vdop)) {
         $waypoint->setVdop((double) $xml->vdop[0]);
     }
     if (!empty($xml->pdop)) {
         $waypoint->setPdop((double) $xml->pdop[0]);
     }
     if (!empty($xml->ageofdgpsdata)) {
         $waypoint->setAgeofdgpsdata((double) $xml->ageofdgpsdata[0]);
     }
     if (!empty($xml->dgpsid)) {
         $waypoint->setDgpsid((int) $xml->dgpsid[0]);
     }
     if (!empty($xml->extensions)) {
         $waypoint->setExtensions(Extensions::fromXML($xml->extensions[0]));
     }
     return $waypoint;
 }
Exemplo n.º 3
0
 /**
  * @param SimpleXMLElement $xml
  * @return Metadata
  * @throws InvalidGPXException
  */
 public static function fromXML(SimpleXMLElement $xml)
 {
     $metadata = new Metadata();
     if (!empty($xml->name)) {
         $metadata->setName((string) $xml->name[0]);
     }
     if (!empty($xml->desc)) {
         $metadata->setDescription((string) $xml->desc[0]);
     }
     if (!empty($xml->author)) {
         $metadata->setAuthor(Person::fromXML($xml->author[0]));
     }
     if (!empty($xml->copyright)) {
         $metadata->setCopyright(Copyright::fromXML($xml->copyright[0]));
     }
     if (!empty($xml->link)) {
         $links = [];
         foreach ($xml->link as $link) {
             array_push($links, Link::fromXML($link));
         }
         $metadata->setLinks($links);
     }
     if (!empty($xml->time)) {
         $metadata->setTime(strtotime((string) $xml->time[0]));
     }
     if (!empty($xml->keywords)) {
         $metadata->setKeywords((string) $xml->keywords[0]);
     }
     if (!empty($xml->bounds)) {
         $metadata->setBounds(Bounds::fromXML($xml->bounds0[0]));
     }
     if (!empty($xml->extensions)) {
         $metadata->setExtensions(Extensions::fromXML($xml->extensions[0]));
     }
     return $metadata;
 }
Exemplo n.º 4
0
 /**
  * @param SimpleXMLElement $xml
  * @return Route
  * @throws InvalidGPXException
  */
 public static function fromXML(SimpleXMLElement $xml)
 {
     $route = new Route();
     if (!empty($xml->name)) {
         $route->setName((string) $xml->name[0]);
     }
     if (!empty($xml->cmt)) {
         $route->setComment((string) $xml->cmt[0]);
     }
     if (!empty($xml->desc)) {
         $route->setDescription((string) $xml->desc[0]);
     }
     if (!empty($xml->src)) {
         $route->setSource((string) $xml->src[0]);
     }
     if (!empty($xml->link)) {
         $links = [];
         foreach ($xml->link as $link) {
             array_push($links, Link::fromXML($link));
         }
         $route->setLinks($links);
     }
     if (!empty($xml->number)) {
         $route->setNumber((int) $xml->number[0]);
     }
     if (!empty($xml->type)) {
         $route->setType((string) $xml->type[0]);
     }
     if (!empty($xml->extensions)) {
         $route->setExtensions(Extensions::fromXML($xml->extensions[0]));
     }
     if (!empty($xml->rtept)) {
         $routePoints = [];
         foreach ($xml->rtept as $routePoint) {
             array_push($routePoints, Waypoint::fromXML($routePoint));
         }
         $route->setRoutePoints($routePoints);
     }
     return $route;
 }
Exemplo n.º 5
0
 /**
  * @param SimpleXMLElement $xml
  * @return Track
  */
 public static function fromXML(SimpleXMLElement $xml)
 {
     $track = new Track();
     if (!empty($xml->name)) {
         $track->setName((string) $xml->name[0]);
     }
     if (!empty($xml->cmt)) {
         $track->setComment((string) $xml->cmt[0]);
     }
     if (!empty($xml->desc)) {
         $track->setDescription((string) $xml->desc[0]);
     }
     if (!empty($xml->src)) {
         $track->setSource((string) $xml->src[0]);
     }
     if (!empty($xml->link)) {
         $links = [];
         foreach ($xml->link as $link) {
             array_push($links, Link::fromXML($link));
         }
         $track->setLinks($links);
     }
     if (!empty($xml->number)) {
         $track->setNumber((int) $xml->number[0]);
     }
     if (!empty($xml->type)) {
         $track->setType((string) $xml->type[0]);
     }
     if (!empty($xml->extensions)) {
         $track->setExtensions(Extensions::fromXML($xml->extensions[0]));
     }
     if (!empty($xml->trkseg)) {
         $trackSegments = [];
         foreach ($xml->trkseg as $trackSegment) {
             array_push($trackSegments, TrackSegment::fromXML($trackSegment));
         }
         $track->setTrackSegments($trackSegments);
     }
     return $track;
 }
Exemplo n.º 6
0
Arquivo: GPX.php Projeto: Crayg/PHPGPX
 /**
  * @param SimpleXMLElement $xml
  * @return GPX
  * @throws InvalidGPXException
  */
 public static function fromXML(SimpleXMLElement $xml)
 {
     if ($xml->getName() != 'gpx') {
         throw new InvalidGPXException("Root node should be 'gpx'");
     }
     $attributes = $xml->attributes();
     $version = $attributes['version'];
     if ($version != 1.1) {
         throw new InvalidGPXException("Invalid GPX version. This library only supports GPX 1.1");
     }
     if (!($creator = $attributes['creator'])) {
         throw new InvalidGPXException("No creator specified on GPX node.");
     }
     $gpx = new GPX((double) $version, (string) $creator);
     if (!empty($xml->metadata)) {
         $gpx->setMetadata(Metadata::fromXML($xml->metadata[0]));
     }
     if (!empty($xml->wpt)) {
         $waypoints = [];
         foreach ($xml->wpt as $waypoint) {
             array_push($waypoints, Waypoint::fromXML($waypoint));
         }
         $gpx->setWaypoints($waypoints);
     }
     if (!empty($xml->rte)) {
         $routes = [];
         foreach ($xml->rte as $route) {
             array_push($routes, Route::fromXML($route));
         }
         $gpx->setRoutes($routes);
     }
     if (!empty($xml->trk)) {
         $tracks = [];
         foreach ($xml->trk as $track) {
             array_push($tracks, Track::fromXML($track));
         }
         $gpx->setTracks($tracks);
     }
     if (!empty($xml->extensions)) {
         $gpx->setExtensions(Extensions::fromXML($xml->extensions[0]));
     }
     return $gpx;
 }