Skip to content

Commit

Permalink
Merge 8b6603c into 7488809
Browse files Browse the repository at this point in the history
  • Loading branch information
NikStoyanov committed May 16, 2019
2 parents 7488809 + 8b6603c commit 47f7d03
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Manifest.toml
@@ -1 +1,51 @@
# This file is machine-generated - editing it directly is not advised

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[BinaryProvider]]
deps = ["Libdl", "SHA"]
git-tree-sha1 = "c7361ce8a2129f20b0e05a89f7070820cfed6648"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.4"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[LightXML]]
deps = ["BinaryProvider", "Libdl", "Test"]
git-tree-sha1 = "aeec7a341652d47bc773475a42952fa78eccd7cc"
uuid = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
version = "0.8.0"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3 changes: 3 additions & 0 deletions Project.toml
Expand Up @@ -3,6 +3,9 @@ uuid = "737ade88-6689-11e9-2266-a1567ed38d42"
authors = ["Nikola Stoyanov <nstoyanov.92@gmail.com>"]
version = "0.1.0"

[deps]
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"

[compat]
julia = "1.0"

Expand Down
1 change: 1 addition & 0 deletions src/Polyline.jl
Expand Up @@ -27,5 +27,6 @@ end

include("encode.jl")
include("decode.jl")
include("loadGPX.jl")

end # module
38 changes: 38 additions & 0 deletions src/loadGPX.jl
@@ -0,0 +1,38 @@
using LightXML

export parseGPX, readGPX

# Converts a file to XML Document.
function readGPX(filename::String)
return parse_file(filename)
end

#= Converts a XMLDocument to array of longitude and latitude.
Args:
gpxDoc(XMLDocument): XML document in GPX format.
Returns
Array{Float64, 2}: GPS coordinates with longitude and latitude.
=#
function parseGPX(gpxDoc::XMLDocument)

gpxPath = Array{Float64, 2}
gpxLng = zeros(0)
gpxLon = zeros(0)

xroot = root(gpxDoc)
trk = get_elements_by_tagname(xroot, "trk")[1]
trkseg = get_elements_by_tagname(trk, "trkseg")[1]
trkpt = get_elements_by_tagname(trkseg, "trkpt")

for c in child_nodes(trkseg)
if is_elementnode(c)
ad = attributes_dict(XMLElement(c))

append!(gpxLng, parse(Float64, (ad["lat"])))
append!(gpxLon, parse(Float64, (ad["lon"])))
end
end

return cat(dims=2, gpxLng, gpxLon)
end
42 changes: 42 additions & 0 deletions test/runtests.jl
@@ -1,5 +1,6 @@
using Polyline
using Test
using LightXML

pointCurrent = Polyline.coordinate{Float64}(38.5, -120.2)
precision = 10. ^5
Expand Down Expand Up @@ -34,3 +35,44 @@ end
@test isequal(encodePolyline(gps_coord),
"_p~iF~ps|U_ulLnnqC_mqNvxq`@")
end

@testset "Read GPX" begin
gpxFile = """
<?xml version="1.0" encoding="UTF-8"?>
<gpx creator="StravaGPX" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" version="1.1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3">
<metadata>
<time>2019-05-15T07:05:06Z</time>
</metadata>
<trk>
<name>Bridgewater canal - St Georges island</name>
<type>9</type>
<trkseg>
<trkpt lat="53.4717570" lon="-2.2640200">
<ele>29.2</ele>
<time>2019-05-15T07:05:06Z</time>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>76</gpxtpx:hr>
<gpxtpx:cad>0</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>
<trkpt lat="53.4717570" lon="-2.2640200">
<ele>29.2</ele>
<time>2019-05-15T07:05:07Z</time>
<extensions>
<gpxtpx:TrackPointExtension>
<gpxtpx:hr>76</gpxtpx:hr>
<gpxtpx:cad>0</gpxtpx:cad>
</gpxtpx:TrackPointExtension>
</extensions>
</trkpt>
</trkseg>
</trk>
</gpx>"""

xDoc = parse_string(gpxFile)
gpxRoute = [53.4718 -2.26402; 53.4718 -2.26402]

@test gpxRoute parseGPX(xDoc) atol=0.0001
end

0 comments on commit 47f7d03

Please sign in to comment.