* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * */ namespace libgpx; use \DateTimeInterface; /** * A GPX file. * * @see https://www.topografix.com/gpx.asp * * @author Andy Street */ class GPX implements Geographic { /** * The program that created the GPX file. * * @var string */ protected $creator; /** * The name of the GPX file. * * @var string */ protected $name; /** * A description of the contents of the GPX file. * * @var string */ protected $desc; /** * The person or organization who created the GPX file. * * @var Person */ protected $author; /** * Copyright and license information governing use of the file. * * @var Copyright */ protected $copyright; /** * Links to other resources that describe this GPX file. * * @var TypedDoublyLinkedList (Link) */ protected $links; /** * The creation time of the file. * * @var DateTimeInterface */ protected $time; /** * A list of keywords classifying this GPX file. * * @var TypedDoublyLinkedList (string) */ protected $keywords; /** * A list of XML snippets describing unsupported metadata. * * @var TypedDoublyLinkedList (string) */ protected $metadataExtensions; /** * A list of waypoints. * * @var TypedDoublyLinkedList (Point) */ protected $waypoints; /** * A list of routes. * * @var TypedDoublyLinkedList (Route) */ protected $routes; /** * A list of tracks. * * @var TypedDoublyLinkedList (Track) */ protected $tracks; /** * A list of XML snippets describing unsupported elements. * * @var TypedDoublyLinkedList (string) */ protected $extensions; /** * Fetch the name of the program that created the GPX file. * * @return string|null The creator or null if not set. */ public function getCreator() { return $this->creator; } /** * Set the name of the program that created the GPX file. * * @param string|null $creator The program name or null to delete. * @return void */ public function setCreator(string $creator = null) { $this->creator = $creator; } /** * Fetch the file name. * * @return string|null The name or null if not set. */ public function getName() { return $this->name; } /** * Set the name of the file. * * @param string|null $name The file name or null to delete. * @return void */ public function setName(string $name = null) { $this->name = $name; } /** * Fetch the description of the file. * * @return string|null The description or null if not set. */ public function getDesc() { return $this->desc; } /** * Set the description of the file. * * @param string|null $desc The description or null to delete. * @return void */ public function setDesc(string $desc = null) { $this->desc = $desc; } /** * Fetch the author of the file. * * @return Person|null The author or null if not set. */ public function getAuthor() { return $this->author; } /** * Set the author of the file. * * @param Person|null $author The author or null to delete. * @return void */ public function setAuthor(Person $author = null) { $this->author = $author; } /** * Fetch the copyright details for the file. * * @return Copyright|null The copyright or null if not set. */ public function getCopyright() { return $this->copyright; } /** * Set the copyright details for the file. * * @param Copyright|null $copyright The copyright detail or null to delete. * @return void */ public function setCopyright(Copyright $copyright = null) { $this->copyright = $copyright; } /** * Fetch links to other resources. * * @param boolean $create Create the list if it does not already exist. * @return TypedDoublyLinkedList */ public function getLinks(bool $create = true) { if ($create && $this->links === null) $this->links = new TypedDoublyLinkedList('libgpx\Link'); return $this->links; } /** * Fetch the time the GPX file was created. * * @return DateTimeInterface|null A timestamp or null if not set. */ public function getTime() { return $this->time; } /** * Set the time at which the file was created. * * @param DateTimeInterface $time The creation time or null to delete. */ public function setTime(DateTimeInterface $time = null) { $this->time = $time; } /** * Fetch a list of keywords for this GPX file. * * @param boolean $create Create the list if it does not already exist. * @return TypedDoublyLinkedList The keywords */ public function getKeywords(bool $create = true) { if ($create && $this->keywords === null) $this->keywords = new TypedDoublyLinkedList('string'); return $this->keywords; } /** * Fetch a list of XML snippets describing unsupported metadata. * * @param boolean $create Create the list if it does not already exist. * @return TypedDoublyLinkedList The keywords */ public function getMetadataExtensions(bool $create = true) { if ($create && $this->metadataExtensions === null) $this->metadataExtensions = new TypedDoublyLinkedList('string'); return $this->metadataExtensions; } /** * Fetch a list of waypoints. * * @param boolean $create Create the list if it does not already exist. * @return TypedDoublyLinkedList A list of waypoints. */ public function getWaypoints(bool $create = true) { if ($create && $this->waypoints === null) $this->waypoints = new TypedDoublyLinkedList('libgpx\Point'); return $this->waypoints; } /** * Fetch a list of routes. * * @param boolean $create Create the list if it does not already exist. * @return TypedDoublyLinkedList A list of routes. */ public function getRoutes(bool $create = true) { if ($create && $this->routes === null) $this->routes = new TypedDoublyLinkedList('libgpx\Route'); return $this->routes; } /** * Fetch a list of tracks. * * @param boolean $create Create the list if it does not already exist. * @return TypedDoublyLinkedList A list of tracks. */ public function getTracks(bool $create = true) { if ($create && $this->tracks === null) $this->tracks = new TypedDoublyLinkedList('libgpx\Track'); return $this->tracks; } /** * Fetch a list of protocol extensions as raw XML. * * @param boolean $create Create the list if it does not already exist. * @return TypedDoublyLinkedList A list of protocol extensions. */ public function getExtensions(bool $create = true) { if ($create && $this->extensions === null) $this->extensions = new TypedDoublyLinkedList('string'); return $this->extensions; } /** * Fetch a bounding box that covers the feature. * * @return Bounds|null A bounding box covering the extent of the feature or * null if not applicable. */ public function getBounds() { $result = null; $lists = [ $this->waypoints, $this->routes, $this->tracks ]; foreach ($lists as $list) { if ($list === null) continue; foreach ($list as $geo) { $bounds = $geo->getBounds(); if ($bounds === null) continue; if ($result === null) { $result = $bounds; } else { $result->extend($bounds); } } } return $result; } /** * Fetch the length of all features in this GPX file. * * @return float The length in meters. */ public function getLength() { $length = 0; $lists = [ $this->routes, $this->tracks ]; foreach ($lists as $list) { if ($list === null) continue; foreach ($list as $geo) { $length += $geo->getLength(); } } return $length; } }