Skip to content

Commit a1f3368

Browse files
committed
Move geodesy code to independent package
1 parent f32988a commit a1f3368

16 files changed

+77
-423
lines changed

REQUIRE

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
julia 0.3-
1+
julia 0.3
22
Compat
3-
LightXML
3+
Reexport
4+
Geodesy
5+
Graphs
46
LibExpat
7+
LightXML
58
Winston
6-
Graphs

docs/examples.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Define map boundary and crop:
1616

1717
.. code-block:: python
1818
19-
bounds = OpenStreetMap.Bounds(42.365, 42.3675, -71.1, -71.094)
19+
bounds = Bounds(42.365, 42.3675, -71.1, -71.094)
2020
2121
cropMap!(nodes, bounds, highways=hwys, buildings=builds, features=feats, delete_nodes=false)
2222
@@ -42,9 +42,9 @@ Convert map nodes to ENU coordinates:
4242

4343
.. code-block:: python
4444
45-
reference = OpenStreetMap.centerBounds(bounds)
46-
nodesENU = lla2enu(nodes, reference)
47-
boundsENU = lla2enu(bounds, reference)
45+
reference = center(bounds)
46+
nodesENU = ENU(nodes, reference)
47+
boundsENU = ENU(bounds, reference)
4848
4949
Create transportation network:
5050

@@ -58,8 +58,8 @@ Route planning:
5858

5959
.. code-block:: python
6060
61-
loc_start = OpenStreetMap.ENU(-5000, 5500, 0)
62-
loc_end = OpenStreetMap.ENU(5500, -4000, 0)
61+
loc_start = ENU(-5000, 5500, 0)
62+
loc_end = ENU(5500, -4000, 0)
6363
6464
node0 = nearestNode(nodesENU, loc_start, network.v_inv)
6565
node1 = nearestNode(nodesENU, loc_end, network.v_inv)

docs/workers.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ Converting Map Coordinate Systems
4646

4747
OpenStreetMap.jl is capable of converting map data between LLA, ECEF, and ENU coordinates (see "Data Types") for definitions of these standard coordinates. Because point location data is ONLY stored in the ``nodes`` dictionary (type ``Dict{Int,Point-Type}``), only this object needs to be converted. Note that Bounds objects also need to be converted, although they don't technically store map data. The following functions can be used to convert between coordinate systems:
4848

49-
* ``lla2ecef(nodes::Dict{Int,LLA})``
50-
* ``ecef2lla(nodes::Dict{Int,ECEF})``
51-
* ``ecef2enu(nodes::Dict{Int,ECEF}, reference::LLA)``
52-
* ``lla2enu(nodes::Dict{Int,LLA}, reference::LLA)``
49+
* ``ECEF(nodes::Dict{Int,LLA})``
50+
* ``LLA(nodes::Dict{Int,ECEF})``
51+
* ``ENU(nodes::Dict{Int,ECEF}, reference::LLA)``
52+
* ``ENU(nodes::Dict{Int,LLA}, reference::LLA)``
5353

5454
East-North-Up coordinates require an additional input parameter, ``reference``, which gives the origin of the ENU coordinate system. LLA and ECEF coordinates both have their origins fixed at the center of the earth.
5555

src/OpenStreetMap.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
module OpenStreetMap
88

9+
using Reexport
10+
@reexport using Geodesy
911
using LightXML
1012
using LibExpat
1113
using Winston
@@ -15,9 +17,8 @@ using Compat
1517
export parseMapXML, getOSMData, getBounds
1618
export plotMap, cropMap!
1719
export findIntersections, nearestNode, segmentHighways, highwaySegments
18-
export lla2enu, lla2ecef, ecef2lla, ecef2enu
1920
export roadways, walkways, cycleways, classify
20-
export createGraph, shortestRoute, fastestRoute, distance, routeEdges
21+
export createGraph, shortestRoute, fastestRoute, routeEdges
2122
export nodesWithinRange, nodesWithinDrivingDistance, nodesWithinDrivingTime
2223
export findHighwaySets, findIntersectionClusters, replaceHighwayNodes!
2324
export simCityGrid
@@ -42,4 +43,6 @@ include("routing.jl")
4243

4344
include("simulate.jl")
4445

46+
include("deprecated.jl")
47+
4548
end # module OpenStreetMap

src/crop.jl

+3-49
Original file line numberDiff line numberDiff line change
@@ -105,53 +105,6 @@ function crop!(nodes::Dict, bounds::Bounds, features::Dict{Int,Feature})
105105
return nothing
106106
end
107107

108-
### Check whether a location is within bounds ###
109-
function inBounds{T<:Union(LLA,ENU)}(loc::T, bounds::Bounds{T})
110-
x, y = getX(loc), getY(loc)
111-
112-
bounds.min_x <= x <= bounds.max_x &&
113-
bounds.min_y <= y <= bounds.max_y
114-
end
115-
116-
function onBounds{T<:Union(LLA,ENU)}(loc::T, bounds::Bounds{T})
117-
x, y = getX(loc), getY(loc)
118-
119-
x == bounds.min_x || x == bounds.max_x ||
120-
y == bounds.min_y || y == bounds.max_y
121-
end
122-
123-
function boundaryPoint{T<:Union(LLA,ENU)}(p1::T, p2::T, bounds::Bounds)
124-
x1, y1 = getX(p1), getY(p1)
125-
x2, y2 = getX(p2), getY(p2)
126-
127-
x, y = x1, y1
128-
129-
# checks assume inBounds(p1) != inBounds(p2)
130-
if x1 < bounds.min_x < x2 || x1 > bounds.min_x > x2
131-
x = bounds.min_x
132-
y = y1 + (y2 - y1) * (bounds.min_x - x1) / (x2 - x1)
133-
elseif x1 < bounds.max_x < x2 || x1 > bounds.max_x > x2
134-
x = bounds.max_x
135-
y = y1 + (y2 - y1) * (bounds.max_x - x1) / (x2 - x1)
136-
end
137-
138-
p3 = T(XY(x, y))
139-
inBounds(p3, bounds) && return p3
140-
141-
if y1 < bounds.min_y < y2 || y1 > bounds.min_y > y2
142-
x = x1 + (x2 - x1) * (bounds.min_y - y1) / (y2 - y1)
143-
y = bounds.min_y
144-
elseif y1 < bounds.max_y < y2 || y1 > bounds.max_y > y2
145-
x = x1 + (x2 - x1) * (bounds.max_y - y1) / (y2 - y1)
146-
y = bounds.max_y
147-
end
148-
149-
p3 = T(XY(x, y))
150-
inBounds(p3, bounds) && return p3
151-
152-
error("Failed to find boundary point.")
153-
end
154-
155108
function cropHighway!(nodes::Dict, bounds::Bounds, highway::Highway, valids::BitVector)
156109
prev_id, prev_valid = highway.nodes[1], valids[1]
157110
ni = 1
@@ -164,8 +117,9 @@ function cropHighway!(nodes::Dict, bounds::Bounds, highway::Highway, valids::Bit
164117
end
165118
if valid != prev_valid
166119
prev_node, node = nodes[prev_id], nodes[id]
167-
if !(onBounds(prev_node, bounds) || onBounds(node, bounds))
168-
new_node = boundaryPoint(prev_node, node, bounds)
120+
if !(Geodesy.onBounds(prev_node, bounds) ||
121+
Geodesy.onBounds(node, bounds))
122+
new_node = Geodesy.boundaryPoint(prev_node, node, bounds)
169123
new_id = addNewNode(nodes, new_node)
170124
insert!(highway.nodes, ni + !valid, new_id)
171125
ni += 1

src/deprecated.jl

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Base.@deprecate lla2ecef ECEF
2+
Base.@deprecate ecef2lla LLA
3+
Base.@deprecate ecef2enu ENU
4+
Base.@deprecate lla2enu ENU
5+
Base.@deprecate centerBounds(bounds::Bounds) center(bounds)

src/parseMap.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function collectValues(handler::LibExpat.XPStreamHandler, name::String)
181181
if attr.oneway_reverse
182182
reverse!(attr.way_nodes)
183183
end
184-
osm.highways[attr.id] = Highway(attr.class, attr.lanes,
184+
osm.highways[attr.id] = Highway(attr.class, attr.lanes,
185185
(attr.oneway && !attr.oneway_override),
186186
attr.sidewalk, attr.cycleway, attr.bicycle,
187187
attr.name, copy(attr.way_nodes))
@@ -207,7 +207,7 @@ end
207207

208208
function getOSMData(filename::String; args...)
209209
osm = OSMdata()
210-
210+
211211
callbacks = LibExpat.XPCallbacks()
212212
callbacks.start_element = parseElement
213213
callbacks.end_element = collectValues

src/routing.jl

+8-42
Original file line numberDiff line numberDiff line change
@@ -143,55 +143,21 @@ end
143143

144144
### Get distance between two nodes ###
145145
# ENU Coordinates
146-
function distance(nodes::Dict{Int,ENU}, node0, node1)
146+
function Geodesy.distance{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T}, node0, node1)
147147
loc0 = nodes[node0]
148148
loc1 = nodes[node1]
149149

150150
return distance(loc0, loc1)
151151
end
152152

153-
function distance(loc0::ENU, loc1::ENU)
154-
x0 = loc0.east
155-
y0 = loc0.north
156-
z0 = loc0.up
157-
158-
x1 = loc1.east
159-
y1 = loc1.north
160-
z1 = loc1.up
161-
162-
return distance(x0, y0, z0, x1, y1, z1)
163-
end
164-
165-
# ECEF Coordinates
166-
function distance(nodes::Dict{Int,ECEF}, node0, node1)
167-
loc0 = nodes[node0]
168-
loc1 = nodes[node1]
169-
170-
return distance(loc0, loc1)
171-
end
172-
173-
function distance(loc0::ECEF, loc1::ECEF)
174-
x0 = loc0.x
175-
y0 = loc0.y
176-
z0 = loc0.z
177-
178-
x1 = loc1.x
179-
y1 = loc1.y
180-
z1 = loc1.z
181-
182-
return distance(x0, y0, z0, x1, y1, z1)
183-
end
184-
185-
# Cartesian coordinates
186-
function distance(x0, y0, z0, x1, y1, z1)
187-
return sqrt((x1-x0)^2 + (y1-y0)^2 + (z1-z0)^2)
188-
end
189-
190153
### Compute the distance of a route ###
191-
function distance(nodes, route)
192-
dist = 0
193-
for n = 2:length(route)
194-
dist += distance(nodes, route[n-1], route[n])
154+
function Geodesy.distance{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T}, route::Vector{Int})
155+
dist = 0.0
156+
prev_point = nodes[route[1]]
157+
for i = 2:length(route)
158+
point = nodes[route[i]]
159+
dist += distance(prev_point, point)
160+
prev_point = point
195161
end
196162

197163
return dist

0 commit comments

Comments
 (0)