Esempio 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;
 }
Esempio n. 2
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;
 }
Esempio n. 3
0
File: GPX.php Progetto: 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;
 }