/** * @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; }