-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for waypoints and routes #3
Changes from all commits
249e6f1
fb5a14d
2b82a44
c13b086
b579703
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
defmodule GpxEx.Gpx do | ||
@type t :: %__MODULE__{tracks: list(GpxEx.Track.t)} | ||
@typedoc """ | ||
A struct representing a fully parsed GPX file. | ||
|
||
defstruct tracks: nil | ||
GPX files may contain zero or more: | ||
|
||
- Tracks—ordered lists of points describing a path someone traveled. | ||
- Routes—ordered lists of waypoints representing a series of turn points | ||
leading to a destination. Whereas a track might sample the GPS location | ||
of actual movements at some interval, a route represents directions | ||
such as you might get from a routing application. | ||
- Waypoints—a point of interest or named feature on a map. | ||
""" | ||
@type t :: %__MODULE__{ | ||
tracks: list(GpxEx.Track.t()), | ||
waypoints: list(GpxEx.Waypoint.t()), | ||
routes: list(GpxEx.Route.t()) | ||
} | ||
|
||
defstruct tracks: [], waypoints: [], routes: [] | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule GpxEx.Route do | ||
@typedoc """ | ||
A struct representing a route, an idealized list of turn points that describe | ||
the directions one should follow to go from one place to another. | ||
""" | ||
@type t :: %__MODULE__{points: list(GpxEx.Waypoint.t()), name: String.t() | nil} | ||
|
||
defstruct points: [], name: nil | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule GpxEx.Waypoint do | ||
@enforce_keys [:lat, :lon] | ||
defstruct @enforce_keys ++ | ||
[ | ||
ele: nil, | ||
name: nil, | ||
symbol: nil, | ||
description: nil, | ||
url: nil | ||
] | ||
|
||
@typedoc """ | ||
A single waypoint, which may be part of a route or | ||
a standalone point-of-interest or named feature. | ||
|
||
- Lon and lat are in decimal degrees | ||
- Elevation is in meters (presumably above mean sea level) | ||
""" | ||
@type t :: %__MODULE__{ | ||
lat: float(), | ||
lon: float(), | ||
ele: float() | nil, | ||
name: String.t() | nil, | ||
symbol: String.t() | nil, | ||
description: String.t() | nil, | ||
url: String.t() | nil | ||
} | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ defmodule GpxEx.MixProject do | |
# Run "mix help deps" to learn about dependencies. | ||
defp deps do | ||
[ | ||
{:sweet_xml, "~> 0.6.0"} | ||
{:sweet_xml, "~> 0.7.0"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this library's purposes, I think 0.6.6 that we were using previously is actually compatible with 0.7.3, so we could potentially specify a broader supported range here, albeit at the cost of additional testing. 0.6.x is incompatible with a lot of libraries in the wild, including |
||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} | ||
] | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
%{ | ||
"sweet_xml": {:hex, :sweet_xml, "0.6.6", "fc3e91ec5dd7c787b6195757fbcf0abc670cee1e4172687b45183032221b66b8", [:mix], [], "hexpm", "2e1ec458f892ffa81f9f8386e3f35a1af6db7a7a37748a64478f13163a1f3573"}, | ||
"sweet_xml": {:hex, :sweet_xml, "0.7.3", "debb256781c75ff6a8c5cbf7981146312b66f044a2898f453709a53e5031b45b", [:mix], [], "hexpm", "e110c867a1b3fe74bfc7dd9893aa851f0eed5518d0d7cad76d7baafd30e4f5ba"}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0"?> | ||
<gpx xmlns="http://www.topografix.com/GPX/1/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:gpx="http://www.topografix.com/GPX/1/0" version="1.0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> | ||
<rte> | ||
<name><![CDATA[Sample route]]></name> | ||
<desc>Fake route</desc> | ||
<rtept lat="39.2" lon="-94.5"> | ||
<ele>388.1</ele> | ||
<name>Point 1</name> | ||
</rtept> | ||
<rtept lat="-19.9" lon="120.4"> | ||
<name>Point 2</name> | ||
</rtept> | ||
<rtept lat="-0.2" lon="-0.1"> | ||
<name>Point 3</name> | ||
</rtept> | ||
<rtept lat="0.4" lon="0.2"> | ||
<name>Point 4</name> | ||
<ele>-0.1</ele> | ||
</rtept> | ||
</rte> | ||
</gpx> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0"?> | ||
<gpx xmlns="http://www.topografix.com/GPX/1/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:gpx="http://www.topografix.com/GPX/1/0" version="1.0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> | ||
<wpt lat="39.2" lon="-94.5"> | ||
<name>Kansas City, MO</name> | ||
<sym>City</sym> | ||
<desc>Midwestern city</desc> | ||
<url>https://www.visitkc.com</url> | ||
<ele>308.15</ele> | ||
</wpt> | ||
<wpt lat="32.7" lon="-117.2"> | ||
<sym>City</sym> | ||
<name>San Diego, CA</name> | ||
<url>https://www.sandiego.gov/</url> | ||
<desc>Port city</desc> | ||
</wpt> | ||
<wpt lat="36.4" lon="-94.2"> | ||
<ele>395</ele> | ||
<url>http://bentonvillear.com/</url> | ||
<name>Bentonville, AR</name> | ||
<sym>Town</sym> | ||
</wpt> | ||
</gpx> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting an exception thrown when trying to query
./whatever/text()
when the element in question didn't exist, so I moved to checking for the element, then asking for its text.