Skip to content

Commit 43964c3

Browse files
committed
better handling of coordinate parsing
1 parent ede73b4 commit 43964c3

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "KML"
22
uuid = "1284bf3a-1e3d-4f4e-a7a9-b9d235a28f35"
33
authors = ["Josh Day <emailjoshday@gmail.com> and contributors"]
4-
version = "0.2.4"
4+
version = "0.2.5"
55

66
[deps]
77
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"

src/parsing.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,10 @@ function autosetfield!(o::Union{Object,KMLElement}, sym::Symbol, x::String)
104104
T <: Number && return setfield!(o, sym, parse(T, x))
105105
T <: AbstractString && return setfield!(o, sym, x)
106106
T <: Enums.AbstractKMLEnum && return setfield!(o, sym, T(x))
107-
# if sym == :coordinates
108-
# val = occursin('\n', x) ?
109-
# [Tuple(parse.(Float64, split(s, ','))) for s in split(x, '\n')] :
110-
# Tuple(parse.(Float64, split(x, ',')))
111-
# return setfield!(o, sym, val)
112-
# end
113107
if sym == :coordinates
114108
val = [Tuple(parse.(Float64, split(v, ','))) for v in split(x)]
115-
if length(val) == 1
109+
# coordinates can be a tuple or a vector of tuples, so we need to do this:
110+
if fieldtype(typeof(o), sym) <: Union{Nothing, Tuple}
116111
val = val[1]
117112
end
118113
return setfield!(o, sym, val)

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,13 @@ end
5555
file2 = read(temp, KMLFile)
5656
@test file == file2
5757
end
58+
59+
@testset "coordinates" begin
60+
# `coordinates` are tuple
61+
s = "<Point><coordinates>1,2,3</coordinates></Point>"
62+
@test KML.object(XML.parse(s, XML.Node)[1]) isa Point
63+
64+
# `coordinates` are vector of tuples
65+
s = "<LineString><coordinates>1,2,3</coordinates></LineString>"
66+
@test KML.object(XML.parse(s, XML.Node)[1]) isa LineString
67+
end

0 commit comments

Comments
 (0)