Skip to content

Commit d9dda71

Browse files
committed
[FEAT] Add GeoLocation constructor from EdgePoint
1 parent 33898b9 commit d9dda71

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LightOSM"
22
uuid = "d1922b25-af4e-4ba3-84af-fe9bea896051"
33
authors = ["Jack Chan <jchan2@deloitte.com.au>"]
4-
version = "0.2.7"
4+
version = "0.2.8"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

src/graph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function graph_from_object(osm_data_object::Union{XMLDocument,Dict};
5555
g.dijkstra_states = Vector{Vector{U}}(undef, length(g.nodes))
5656
end
5757

58-
add_kdtree!(g)
58+
add_kdtree_and_rtree!(g)
5959
@info "Created OSMGraph object with kwargs: `network_type=$network_type`, `weight_type=$weight_type`, `graph_type=$graph_type`, `precompute_dijkstra_states=$precompute_dijkstra_states`, `largest_connected_component=$largest_connected_component`"
6060
return g
6161
end

src/types.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
"""
22
Representation of a geospatial coordinates.
33
4+
# Fields
45
- `lat::Float64`: Latitude.
56
- `lon::Float64`: Longitude.
67
- `alt::Float64`: Altitude.
8+
9+
# Constructors
10+
GeoLocation(lat, lon)
11+
GeoLocation(point::Vector{<:Real})
12+
GeoLocation(point_vector::Vector{<:Vector{<:Real}})
13+
GeoLocation(g::OSMGraph, ep::EdgePoint)
714
"""
815
@with_kw_noshow struct GeoLocation
916
lat::Float64
1017
lon::Float64
1118
alt::Float64 = 0.0
1219
end
13-
1420
GeoLocation(lat::AbstractFloat, lon::AbstractFloat)::GeoLocation = GeoLocation(lat=lat, lon=lon)
1521
GeoLocation(lat::Real, lon::Real)::GeoLocation = GeoLocation(lat=float(lat), lon=float(lon))
1622
GeoLocation(point::Vector{<:AbstractFloat})::GeoLocation = GeoLocation(point...)
@@ -20,6 +26,9 @@ GeoLocation(point_vector::Vector{<:Vector{<:Real}})::Vector{GeoLocation} = [GeoL
2026
function Base.:(==)(loc1::GeoLocation, loc2::GeoLocation)
2127
return loc1.lat == loc2.lat && loc1.lon == loc2.lon && loc1.alt == loc2.alt
2228
end
29+
function Base.isapprox(loc1::GeoLocation, loc2::GeoLocation)
30+
return loc1.lat loc2.lat && loc1.lon loc2.lon && loc1.alt loc2.alt
31+
end
2332
function Base.hash(loc::GeoLocation, h::UInt)
2433
for field in fieldnames(GeoLocation)
2534
h = hash(getproperty(loc, field), h)
@@ -30,6 +39,7 @@ end
3039
"""
3140
OpenStreetMap node.
3241
42+
# Fields
3343
`T<:Integer`
3444
- `id::T`: OpenStreetMap node id.
3545
- `nodes::Vector{T}`: Node's GeoLocation.
@@ -44,6 +54,7 @@ end
4454
"""
4555
OpenStreetMap way.
4656
57+
# Fields
4758
`T<:Integer`
4859
- `id::T`: OpenStreetMap way id.
4960
- `nodes::Vector{T}`: Ordered list of node ids making up the way.
@@ -75,6 +86,7 @@ end
7586
"""
7687
OpenStreetMap turn restriction (relation).
7788
89+
# Fields
7890
`T<:Integer`
7991
- `id::T`: OpenStreetMap relation id.
8092
- `type::String`: Either a `via_way` or `via_node` turn restriction.
@@ -101,6 +113,7 @@ end
101113
"""
102114
Container for storing OpenStreetMap node, way, relation and graph related obejcts.
103115
116+
# Fields
104117
`U <: Integer,T <: Integer,W <: Real`
105118
- `nodes::Dict{T,Node{T}}`: Mapping of node ids to node objects.
106119
- `node_coordinates::Vector{Vector{W}}`: Vector of node coordinates [[lat, lon]...], indexed by graph vertices.
@@ -155,6 +168,7 @@ end
155168
"""
156169
OpenStreetMap building polygon.
157170
171+
# Fields
158172
`T<:Integer`
159173
- `id::T`: OpenStreetMap building way id.
160174
- `nodes::Vector{T}`: Ordered list of node ids making up the building polyogn.
@@ -169,6 +183,7 @@ end
169183
"""
170184
OpenStreetMap building.
171185
186+
# Fields
172187
`T<:Integer`
173188
- `id::T`: OpenStreetMap building way id a simple polygon, relation id if a multi-polygon
174189
- `is_relation::Bool`: True if building is a a multi-polygon / relation.
@@ -196,3 +211,11 @@ abstract type DijkstraDict <: Dijkstra end
196211
abstract type AStar <: PathAlgorithm end
197212
abstract type AStarVector <: AStar end
198213
abstract type AStarDict <: AStar end
214+
215+
"""
216+
Additional GeoLocation methods that require types defined above.
217+
"""
218+
GeoLocation(g::OSMGraph, ep::EdgePoint)::GeoLocation = GeoLocation(
219+
lon = g.nodes[ep.n1].location.lon + (g.nodes[ep.n2].location.lon - g.nodes[ep.n1].location.lon) * ep.pos,
220+
lat = g.nodes[ep.n1].location.lat + (g.nodes[ep.n2].location.lat - g.nodes[ep.n1].location.lat) * ep.pos
221+
)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ const TEST_OSM_URL = "https://raw.githubusercontent.com/DeloitteOptimalReality/L
2222
@testset "Graph" begin include("graph.jl") end
2323
@testset "Traversal" begin include("traversal.jl") end
2424
@testset "Subgraph" begin include("subgraph.jl") end
25+
@testset "Types" begin include("types.jl") end
2526
end

test/types.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
g = basic_osm_graph_stub()
2+
3+
@testset "GeoLocation tests" begin
4+
ep = LightOSM.EdgePoint(1003, 1004, 0.4)
5+
expected_response = GeoLocation(lon=145.3326838, lat=-38.0754037)
6+
actual_response = GeoLocation(g, ep)
7+
@test expected_response actual_response
8+
end

0 commit comments

Comments
 (0)