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)
117 * Fetch the name of the program that created the GPX file.
119 * @return string|null The creator or null if not set.
121 public function getCreator()
123 return $this->creator;
127 * Set the name of the program that created the GPX file.
129 * @param string|null $creator The program name or null to delete.
132 public function setCreator(string $creator = null)
134 $this->creator = $creator;
138 * Fetch the file name.
140 * @return string|null The name or null if not set.
142 public function getName()
148 * Set the name of the file.
150 * @param string|null $name The file name or null to delete.
153 public function setName(string $name = null)
159 * Fetch the description of the file.
161 * @return string|null The description or null if not set.
163 public function getDesc()
169 * Set the description of the file.
171 * @param string|null $desc The description or null to delete.
174 public function setDesc(string $desc = null)
180 * Fetch the author of the file.
182 * @return Person|null The author or null if not set.
184 public function getAuthor()
186 return $this->author;
190 * Set the author of the file.
192 * @param Person|null $author The author or null to delete.
195 public function setAuthor(Person $author = null)
197 $this->author = $author;
201 * Fetch the copyright details for the file.
203 * @return Copyright|null The copyright or null if not set.
205 public function getCopyright()
207 return $this->copyright;
211 * Set the copyright details for the file.
213 * @param Copyright|null $copyright The copyright detail or null to delete.
216 public function setCopyright(Copyright $copyright = null)
218 $this->copyright = $copyright;
222 * Fetch links to other resources.
224 * @param boolean $create Create the list if it does not already exist.
225 * @return TypedDoublyLinkedList
227 public function getLinks(bool $create = true)
229 if ($create && $this->links === null)
230 $this->links = new TypedDoublyLinkedList('libgpx\Link');
235 * Fetch the time the GPX file was created.
237 * @return DateTimeInterface|null A timestamp or null if not set.
239 public function getTime()
245 * Set the time at which the file was created.
247 * @param DateTimeInterface $time The creation time or null to delete.
249 public function setTime(DateTimeInterface $time = null)
255 * Fetch a list of keywords for this GPX file.
257 * @param boolean $create Create the list if it does not already exist.
258 * @return TypedDoublyLinkedList The keywords
260 public function getKeywords(bool $create = true)
262 if ($create && $this->keywords === null)
263 $this->keywords = new TypedDoublyLinkedList('string');
264 return $this->keywords;
268 * Fetch a list of XML snippets describing unsupported metadata.
270 * @param boolean $create Create the list if it does not already exist.
271 * @return TypedDoublyLinkedList The keywords
273 public function getMetadataExtensions(bool $create = true)
275 if ($create && $this->metadataExtensions === null)
276 $this->metadataExtensions = new TypedDoublyLinkedList('string');
277 return $this->metadataExtensions;
281 * Fetch a list of waypoints.
283 * @param boolean $create Create the list if it does not already exist.
284 * @return TypedDoublyLinkedList A list of waypoints.
286 public function getWaypoints(bool $create = true)
288 if ($create && $this->waypoints === null)
289 $this->waypoints = new TypedDoublyLinkedList('libgpx\Point');
290 return $this->waypoints;
294 * Fetch a list of routes.
296 * @param boolean $create Create the list if it does not already exist.
297 * @return TypedDoublyLinkedList A list of routes.
299 public function getRoutes(bool $create = true)
301 if ($create && $this->routes === null)
302 $this->routes = new TypedDoublyLinkedList('libgpx\Route');
303 return $this->routes;
307 * Fetch a bounding box that covers the feature.
309 * @return Bounds|null A bounding box covering the extent of the feature or
310 * null if not applicable.
312 public function getBounds()
319 foreach ($lists as $list) {
320 if ($list === null) continue;
321 foreach ($list as $geo) {
322 $bounds = $geo->getBounds();
323 if ($bounds === null) continue;
324 $result = ($result === null ? $bounds : $result->extend($bounds));