5 * Copyright 2018 Andy Street <andy@street.me.uk>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 use \DateTimeInterface;
32 * @see https://www.topografix.com/gpx.asp
34 * @author Andy Street <andy@street.me.uk>
36 class GPX implements Geographic
40 * The program that created the GPX file.
47 * The name of the GPX file.
54 * A description of the contents of the GPX file.
61 * The person or organization who created the GPX file.
68 * Copyright and license information governing use of the file.
75 * Links to other resources that describe this GPX file.
77 * @var TypedDoublyLinkedList (Link)
82 * The creation time of the file.
84 * @var DateTimeInterface
89 * A list of keywords classifying this GPX file.
91 * @var TypedDoublyLinkedList (string)
96 * A list of XML snippets describing unsupported metadata.
98 * @var TypedDoublyLinkedList (string)
100 protected $metadataExtensions;
103 * A list of waypoints.
105 * @var TypedDoublyLinkedList (Point)
107 protected $waypoints;
112 * @var TypedDoublyLinkedList (Route)
119 * @var TypedDoublyLinkedList (Track)
124 * Fetch the name of the program that created the GPX file.
126 * @return string|null The creator or null if not set.
128 public function getCreator()
130 return $this->creator;
134 * Set the name of the program that created the GPX file.
136 * @param string|null $creator The program name or null to delete.
139 public function setCreator(string $creator = null)
141 $this->creator = $creator;
145 * Fetch the file name.
147 * @return string|null The name or null if not set.
149 public function getName()
155 * Set the name of the file.
157 * @param string|null $name The file name or null to delete.
160 public function setName(string $name = null)
166 * Fetch the description of the file.
168 * @return string|null The description or null if not set.
170 public function getDesc()
176 * Set the description of the file.
178 * @param string|null $desc The description or null to delete.
181 public function setDesc(string $desc = null)
187 * Fetch the author of the file.
189 * @return Person|null The author or null if not set.
191 public function getAuthor()
193 return $this->author;
197 * Set the author of the file.
199 * @param Person|null $author The author or null to delete.
202 public function setAuthor(Person $author = null)
204 $this->author = $author;
208 * Fetch the copyright details for the file.
210 * @return Copyright|null The copyright or null if not set.
212 public function getCopyright()
214 return $this->copyright;
218 * Set the copyright details for the file.
220 * @param Copyright|null $copyright The copyright detail or null to delete.
223 public function setCopyright(Copyright $copyright = null)
225 $this->copyright = $copyright;
229 * Fetch links to other resources.
231 * @param boolean $create Create the list if it does not already exist.
232 * @return TypedDoublyLinkedList
234 public function getLinks(bool $create = true)
236 if ($create && $this->links === null)
237 $this->links = new TypedDoublyLinkedList('libgpx\Link');
242 * Fetch the time the GPX file was created.
244 * @return DateTimeInterface|null A timestamp or null if not set.
246 public function getTime()
252 * Set the time at which the file was created.
254 * @param DateTimeInterface $time The creation time or null to delete.
256 public function setTime(DateTimeInterface $time = null)
262 * Fetch a list of keywords for this GPX file.
264 * @param boolean $create Create the list if it does not already exist.
265 * @return TypedDoublyLinkedList The keywords
267 public function getKeywords(bool $create = true)
269 if ($create && $this->keywords === null)
270 $this->keywords = new TypedDoublyLinkedList('string');
271 return $this->keywords;
275 * Fetch a list of XML snippets describing unsupported metadata.
277 * @param boolean $create Create the list if it does not already exist.
278 * @return TypedDoublyLinkedList The keywords
280 public function getMetadataExtensions(bool $create = true)
282 if ($create && $this->metadataExtensions === null)
283 $this->metadataExtensions = new TypedDoublyLinkedList('string');
284 return $this->metadataExtensions;
288 * Fetch a list of waypoints.
290 * @param boolean $create Create the list if it does not already exist.
291 * @return TypedDoublyLinkedList A list of waypoints.
293 public function getWaypoints(bool $create = true)
295 if ($create && $this->waypoints === null)
296 $this->waypoints = new TypedDoublyLinkedList('libgpx\Point');
297 return $this->waypoints;
301 * Fetch a list of routes.
303 * @param boolean $create Create the list if it does not already exist.
304 * @return TypedDoublyLinkedList A list of routes.
306 public function getRoutes(bool $create = true)
308 if ($create && $this->routes === null)
309 $this->routes = new TypedDoublyLinkedList('libgpx\Route');
310 return $this->routes;
314 * Fetch a list of tracks.
316 * @param boolean $create Create the list if it does not already exist.
317 * @return TypedDoublyLinkedList A list of tracks.
319 public function getTracks(bool $create = true)
321 if ($create && $this->tracks === null)
322 $this->tracks = new TypedDoublyLinkedList('libgpx\Track');
323 return $this->tracks;
327 * Fetch a bounding box that covers the feature.
329 * @return Bounds|null A bounding box covering the extent of the feature or
330 * null if not applicable.
332 public function getBounds()
340 foreach ($lists as $list) {
341 if ($list === null) continue;
342 foreach ($list as $geo) {
343 $bounds = $geo->getBounds();
344 if ($bounds === null) continue;
345 $result = ($result === null ? $bounds : $result->extend($bounds));