From 77cd0be2ae279617f3142c57aef69338b96692b4 Mon Sep 17 00:00:00 2001 From: Sean Garborg Date: Thu, 15 Jan 2015 10:08:04 -0700 Subject: [PATCH 1/3] Load packages outside of timed test files --- test/runtests.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 9fb3002..b83e7b1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,3 +1,6 @@ +using OpenStreetMap +using Base.Test + tests = [ "read_data", "simcity", From f32988afeeb45c8660b77861990e60a7dcf534e7 Mon Sep 17 00:00:00 2001 From: Sean Garborg Date: Thu, 15 Jan 2015 10:16:12 -0700 Subject: [PATCH 2/3] Don't import anything you aren't extending --- src/OpenStreetMap.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenStreetMap.jl b/src/OpenStreetMap.jl index 8b55ade..28948ad 100644 --- a/src/OpenStreetMap.jl +++ b/src/OpenStreetMap.jl @@ -6,11 +6,11 @@ module OpenStreetMap -import LightXML -import LibExpat -import Winston -import Graphs -import Compat +using LightXML +using LibExpat +using Winston +using Graphs +using Compat export parseMapXML, getOSMData, getBounds export plotMap, cropMap! From a1f33685b0783eef02af1fea6527490d4335ce56 Mon Sep 17 00:00:00 2001 From: Sean Garborg Date: Mon, 19 Jan 2015 11:26:10 -0700 Subject: [PATCH 3/3] Move geodesy code to independent package --- REQUIRE | 8 +- docs/examples.rst | 12 +-- docs/workers.rst | 8 +- src/OpenStreetMap.jl | 7 +- src/crop.jl | 52 +----------- src/deprecated.jl | 5 ++ src/parseMap.jl | 4 +- src/routing.jl | 50 ++--------- src/transforms.jl | 187 ++++++------------------------------------ src/types.jl | 82 ------------------ test/coordinates.jl | 49 ----------- test/crop_map.jl | 3 - test/intersections.jl | 6 +- test/plots.jl | 10 +-- test/routes.jl | 16 ++-- test/runtests.jl | 1 - 16 files changed, 77 insertions(+), 423 deletions(-) create mode 100644 src/deprecated.jl delete mode 100644 test/coordinates.jl diff --git a/REQUIRE b/REQUIRE index 2b19ef4..b9f1d70 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,6 +1,8 @@ -julia 0.3- +julia 0.3 Compat -LightXML +Reexport +Geodesy +Graphs LibExpat +LightXML Winston -Graphs diff --git a/docs/examples.rst b/docs/examples.rst index 34a2eb5..6abc6d7 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -16,7 +16,7 @@ Define map boundary and crop: .. code-block:: python - bounds = OpenStreetMap.Bounds(42.365, 42.3675, -71.1, -71.094) + bounds = Bounds(42.365, 42.3675, -71.1, -71.094) cropMap!(nodes, bounds, highways=hwys, buildings=builds, features=feats, delete_nodes=false) @@ -42,9 +42,9 @@ Convert map nodes to ENU coordinates: .. code-block:: python - reference = OpenStreetMap.centerBounds(bounds) - nodesENU = lla2enu(nodes, reference) - boundsENU = lla2enu(bounds, reference) + reference = center(bounds) + nodesENU = ENU(nodes, reference) + boundsENU = ENU(bounds, reference) Create transportation network: @@ -58,8 +58,8 @@ Route planning: .. code-block:: python - loc_start = OpenStreetMap.ENU(-5000, 5500, 0) - loc_end = OpenStreetMap.ENU(5500, -4000, 0) + loc_start = ENU(-5000, 5500, 0) + loc_end = ENU(5500, -4000, 0) node0 = nearestNode(nodesENU, loc_start, network.v_inv) node1 = nearestNode(nodesENU, loc_end, network.v_inv) diff --git a/docs/workers.rst b/docs/workers.rst index c194cc0..88337f2 100644 --- a/docs/workers.rst +++ b/docs/workers.rst @@ -46,10 +46,10 @@ Converting Map Coordinate Systems 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: -* ``lla2ecef(nodes::Dict{Int,LLA})`` -* ``ecef2lla(nodes::Dict{Int,ECEF})`` -* ``ecef2enu(nodes::Dict{Int,ECEF}, reference::LLA)`` -* ``lla2enu(nodes::Dict{Int,LLA}, reference::LLA)`` +* ``ECEF(nodes::Dict{Int,LLA})`` +* ``LLA(nodes::Dict{Int,ECEF})`` +* ``ENU(nodes::Dict{Int,ECEF}, reference::LLA)`` +* ``ENU(nodes::Dict{Int,LLA}, reference::LLA)`` 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. diff --git a/src/OpenStreetMap.jl b/src/OpenStreetMap.jl index 28948ad..583bafd 100644 --- a/src/OpenStreetMap.jl +++ b/src/OpenStreetMap.jl @@ -6,6 +6,8 @@ module OpenStreetMap +using Reexport +@reexport using Geodesy using LightXML using LibExpat using Winston @@ -15,9 +17,8 @@ using Compat export parseMapXML, getOSMData, getBounds export plotMap, cropMap! export findIntersections, nearestNode, segmentHighways, highwaySegments -export lla2enu, lla2ecef, ecef2lla, ecef2enu export roadways, walkways, cycleways, classify -export createGraph, shortestRoute, fastestRoute, distance, routeEdges +export createGraph, shortestRoute, fastestRoute, routeEdges export nodesWithinRange, nodesWithinDrivingDistance, nodesWithinDrivingTime export findHighwaySets, findIntersectionClusters, replaceHighwayNodes! export simCityGrid @@ -42,4 +43,6 @@ include("routing.jl") include("simulate.jl") +include("deprecated.jl") + end # module OpenStreetMap diff --git a/src/crop.jl b/src/crop.jl index 4cfc4f6..f8fc40d 100644 --- a/src/crop.jl +++ b/src/crop.jl @@ -105,53 +105,6 @@ function crop!(nodes::Dict, bounds::Bounds, features::Dict{Int,Feature}) return nothing end -### Check whether a location is within bounds ### -function inBounds{T<:Union(LLA,ENU)}(loc::T, bounds::Bounds{T}) - x, y = getX(loc), getY(loc) - - bounds.min_x <= x <= bounds.max_x && - bounds.min_y <= y <= bounds.max_y -end - -function onBounds{T<:Union(LLA,ENU)}(loc::T, bounds::Bounds{T}) - x, y = getX(loc), getY(loc) - - x == bounds.min_x || x == bounds.max_x || - y == bounds.min_y || y == bounds.max_y -end - -function boundaryPoint{T<:Union(LLA,ENU)}(p1::T, p2::T, bounds::Bounds) - x1, y1 = getX(p1), getY(p1) - x2, y2 = getX(p2), getY(p2) - - x, y = x1, y1 - - # checks assume inBounds(p1) != inBounds(p2) - if x1 < bounds.min_x < x2 || x1 > bounds.min_x > x2 - x = bounds.min_x - y = y1 + (y2 - y1) * (bounds.min_x - x1) / (x2 - x1) - elseif x1 < bounds.max_x < x2 || x1 > bounds.max_x > x2 - x = bounds.max_x - y = y1 + (y2 - y1) * (bounds.max_x - x1) / (x2 - x1) - end - - p3 = T(XY(x, y)) - inBounds(p3, bounds) && return p3 - - if y1 < bounds.min_y < y2 || y1 > bounds.min_y > y2 - x = x1 + (x2 - x1) * (bounds.min_y - y1) / (y2 - y1) - y = bounds.min_y - elseif y1 < bounds.max_y < y2 || y1 > bounds.max_y > y2 - x = x1 + (x2 - x1) * (bounds.max_y - y1) / (y2 - y1) - y = bounds.max_y - end - - p3 = T(XY(x, y)) - inBounds(p3, bounds) && return p3 - - error("Failed to find boundary point.") -end - function cropHighway!(nodes::Dict, bounds::Bounds, highway::Highway, valids::BitVector) prev_id, prev_valid = highway.nodes[1], valids[1] ni = 1 @@ -164,8 +117,9 @@ function cropHighway!(nodes::Dict, bounds::Bounds, highway::Highway, valids::Bit end if valid != prev_valid prev_node, node = nodes[prev_id], nodes[id] - if !(onBounds(prev_node, bounds) || onBounds(node, bounds)) - new_node = boundaryPoint(prev_node, node, bounds) + if !(Geodesy.onBounds(prev_node, bounds) || + Geodesy.onBounds(node, bounds)) + new_node = Geodesy.boundaryPoint(prev_node, node, bounds) new_id = addNewNode(nodes, new_node) insert!(highway.nodes, ni + !valid, new_id) ni += 1 diff --git a/src/deprecated.jl b/src/deprecated.jl new file mode 100644 index 0000000..0b27cf9 --- /dev/null +++ b/src/deprecated.jl @@ -0,0 +1,5 @@ +Base.@deprecate lla2ecef ECEF +Base.@deprecate ecef2lla LLA +Base.@deprecate ecef2enu ENU +Base.@deprecate lla2enu ENU +Base.@deprecate centerBounds(bounds::Bounds) center(bounds) diff --git a/src/parseMap.jl b/src/parseMap.jl index ae4b1c4..30652bd 100644 --- a/src/parseMap.jl +++ b/src/parseMap.jl @@ -181,7 +181,7 @@ function collectValues(handler::LibExpat.XPStreamHandler, name::String) if attr.oneway_reverse reverse!(attr.way_nodes) end - osm.highways[attr.id] = Highway(attr.class, attr.lanes, + osm.highways[attr.id] = Highway(attr.class, attr.lanes, (attr.oneway && !attr.oneway_override), attr.sidewalk, attr.cycleway, attr.bicycle, attr.name, copy(attr.way_nodes)) @@ -207,7 +207,7 @@ end function getOSMData(filename::String; args...) osm = OSMdata() - + callbacks = LibExpat.XPCallbacks() callbacks.start_element = parseElement callbacks.end_element = collectValues diff --git a/src/routing.jl b/src/routing.jl index 69471ce..6f89295 100644 --- a/src/routing.jl +++ b/src/routing.jl @@ -143,55 +143,21 @@ end ### Get distance between two nodes ### # ENU Coordinates -function distance(nodes::Dict{Int,ENU}, node0, node1) +function Geodesy.distance{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T}, node0, node1) loc0 = nodes[node0] loc1 = nodes[node1] return distance(loc0, loc1) end -function distance(loc0::ENU, loc1::ENU) - x0 = loc0.east - y0 = loc0.north - z0 = loc0.up - - x1 = loc1.east - y1 = loc1.north - z1 = loc1.up - - return distance(x0, y0, z0, x1, y1, z1) -end - -# ECEF Coordinates -function distance(nodes::Dict{Int,ECEF}, node0, node1) - loc0 = nodes[node0] - loc1 = nodes[node1] - - return distance(loc0, loc1) -end - -function distance(loc0::ECEF, loc1::ECEF) - x0 = loc0.x - y0 = loc0.y - z0 = loc0.z - - x1 = loc1.x - y1 = loc1.y - z1 = loc1.z - - return distance(x0, y0, z0, x1, y1, z1) -end - -# Cartesian coordinates -function distance(x0, y0, z0, x1, y1, z1) - return sqrt((x1-x0)^2 + (y1-y0)^2 + (z1-z0)^2) -end - ### Compute the distance of a route ### -function distance(nodes, route) - dist = 0 - for n = 2:length(route) - dist += distance(nodes, route[n-1], route[n]) +function Geodesy.distance{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T}, route::Vector{Int}) + dist = 0.0 + prev_point = nodes[route[1]] + for i = 2:length(route) + point = nodes[route[i]] + dist += distance(prev_point, point) + prev_point = point end return dist diff --git a/src/transforms.jl b/src/transforms.jl index d34044c..c7423a7 100644 --- a/src/transforms.jl +++ b/src/transforms.jl @@ -8,192 +8,53 @@ ### Conversion from LLA to ECEF coordinates ### ############################################### -# For single-point calculations -function lla2ecef(lla::LLA) - datum = WGS84() # Get WGS84 datum - - lla2ecef(lla, datum) -end - -# For multi-point loops -function lla2ecef(lla::LLA, d::WGS84) - lat = lla.lat - lon = lla.lon - alt = lla.alt - - N = d.a / sqrt(1 - d.e*d.e * sind(lat)^2) # Radius of curvature (meters) - - x = (N + alt) * cosd(lat) * cosd(lon) - y = (N + alt) * cosd(lat) * sind(lon) - z = (N * (1 - d.e*d.e) + alt) * sind(lat) - - return ECEF(x, y, z) -end - # For dictionary of nodes -function lla2ecef(nodes::Dict{Int,LLA}) - nodesECEF = Dict{Int,ECEF}() - datum = WGS84() +function Geodesy.ECEF(nodes::Dict{Int,LLA}, datum::Ellipsoid = WGS84) + r = Dict{Int,ECEF}() + sizehint!(r, ceil(Int, 1.5*length(nodes))) for (key, node) in nodes - nodesECEF[key] = lla2ecef(node, datum) + r[key] = ECEF(node, datum) end - return nodesECEF + return r end ############################################### ### Conversion from ECEF to LLA coordinates ### ############################################### -# For single-point calculations -function ecef2lla(ecef::ECEF) - datum = WGS84() # Get WGS84 datum - - return ecef2lla(ecef, datum) -end - -# For multi-point loops -function ecef2lla(ecef::ECEF, d::WGS84) - x = ecef.x - y = ecef.y - z = ecef.z - - p = sqrt(x*x + y*y) - theta = atan2(z*d.a, p*d.b) - lambda = atan2(y, x) - phi = atan2(z + d.e_prime^2 * d.b * sin(theta)^3, p - d.e*d.e*d.a*cos(theta)^3) - - N = d.a / sqrt(1 - d.e*d.e * sin(phi)^2) # Radius of curvature (meters) - h = p / cos(phi) - N - - return LLA(phi*180/pi, lambda*180/pi, h) -end - -# For dictionary of nodes -function ecef2lla(nodes::Dict{Int,ECEF}) - nodesLLA = Dict{Int,LLA}() - datum = WGS84() - - for (key, node) in nodes - nodesLLA[key] = ecef2lla(node, datum) - end - - return nodesLLA -end - -############################################### -### Conversion from ECEF to ENU coordinates ### -############################################### - -# Given a reference point for linarization -function ecef2enu(ecef::ECEF, lla_ref::LLA) - # Reference point to linearize about - phi = lla_ref.lat - lambda = lla_ref.lon - - ecef_ref = lla2ecef(lla_ref) - ecef_vec = [ecef.x - ecef_ref.x; ecef.y - ecef_ref.y; ecef.z - ecef_ref.z] - - # Compute rotation matrix - R = [-sind(lambda) cosd(lambda) 0; - -cosd(lambda)*sind(phi) -sind(lambda)*sind(phi) cosd(phi); - cosd(lambda)*cosd(phi) sind(lambda)*cosd(phi) sind(phi)] - ned = R * ecef_vec - - # Extract elements from vector - east = ned[1] - north = ned[2] - up = ned[3] - - return ENU(east, north, up) -end - -# Given Bounds object for linearization -function ecef2enu(ecef::ECEF, bounds::Bounds{LLA}) - lla_ref = centerBounds(bounds) - - return ecef2enu(ecef, lla_ref) -end - # For dictionary of nodes -function ecef2enu(nodes::Dict{Int,ECEF}, bounds::Bounds{LLA}) - nodesENU = Dict{Int,ENU}() - lla_ref = centerBounds(bounds) +function Geodesy.LLA(nodes::Dict{Int,ECEF}, datum::Ellipsoid = WGS84) + r = Dict{Int,LLA}() + sizehint!(r, ceil(Int, 1.5*length(nodes))) for (key, node) in nodes - nodesENU[key] = ecef2enu(node, lla_ref) + r[key] = LLA(node, datum) end - return nodesENU + return r end -############################################## -### Conversion from LLA to ENU coordinates ### -############################################## +##################################### +### Conversion to ENU coordinates ### +##################################### -# For single-point calculations, given bounds -function lla2enu(lla::LLA, bounds::Bounds{LLA}) - ecef = lla2ecef(lla) - enu = ecef2enu(ecef, bounds) - return enu -end - -# For single-point calculations, given reference point -function lla2enu(lla::LLA, lla_ref::LLA) - ecef = lla2ecef(lla) - enu = ecef2enu(ecef, lla_ref) - return enu -end - -# For multi-point loops, given reference point in LLA -function lla2enu(lla::LLA, datum::WGS84, lla_ref::LLA) - ecef = lla2ecef(lla, datum) - enu = ecef2enu(ecef, lla_ref) - return enu -end - -# For dictionary of LLA nodes, given Bounds -function lla2enu(nodes::Dict{Int,LLA}, bounds::Bounds{LLA}) - lla_ref = centerBounds(bounds) - - return lla2enu(nodes, lla_ref) -end - -# For dictionary of LLA nodes, given reference point -function lla2enu(nodes::Dict{Int,LLA}, lla_ref::LLA) - nodesENU = Dict{Int,ENU}() - datum = WGS84() +# Given a reference point +function Geodesy.ENU{T<:Union(LLA,ECEF)}(nodes::Dict{Int,T}, + lla_ref::LLA, + datum::Ellipsoid = WGS84) + r = Dict{Int,ENU}() + sizehint!(r, ceil(Int, 1.5*length(nodes))) for (key, node) in nodes - nodesENU[key] = lla2enu(node, datum, lla_ref) + r[key] = ENU(node, lla_ref, datum) end - return nodesENU + return r end -# For Bounds objects -function lla2enu(bounds::Bounds{LLA}, lla_ref::LLA=centerBounds(bounds)) - top_left_LLA = LLA(bounds.max_y, bounds.min_x) - bottom_right_LLA = LLA(bounds.min_y, bounds.max_x) - - top_left_ENU = lla2enu(top_left_LLA, lla_ref) - bottom_right_ENU = lla2enu(bottom_right_LLA, lla_ref) - - return Bounds{ENU}(bottom_right_ENU.north, - top_left_ENU.north, - top_left_ENU.east, - bottom_right_ENU.east) -end - -######################## -### Helper Functions ### -######################## - -### Get center point of Bounds region ### -function centerBounds{T}(bounds::Bounds{T}) - y_ref = (bounds.min_y + bounds.max_y) / 2 - x_ref = (bounds.min_x + bounds.max_x) / 2 - - return T(XY(x_ref, y_ref)) +# Given Bounds +function Geodesy.ENU(nodes::Dict, bounds::Bounds{LLA}, datum::Ellipsoid = WGS84) + ENU(nodes, center(bounds), datum) end diff --git a/src/types.jl b/src/types.jl index c80ae9f..bf50047 100644 --- a/src/types.jl +++ b/src/types.jl @@ -44,20 +44,6 @@ type HighwaySet # Multiple highways representing a single "street" with a common highways::Set{Int} end -type Bounds{T} - min_y::Float64 - max_y::Float64 - min_x::Float64 - max_x::Float64 -end -function Bounds(min_lat, max_lat, min_lon, max_lon) - if !(-90 <= min_lat <= max_lat <= 90 && -180 <= min_lon <= max_lon <= 180) - throw(ArgumentError("Bounds out of range of LLA coordinate system. " * - "Perhaps you're looking for Bounds{ENU}(...)")) - end - Bounds{LLA}(min_lat, max_lat, min_lon, max_lon) -end - # Transporation network graph data and helpers to increase routing speed type Network g # Graph object @@ -66,74 +52,6 @@ type Network class::Vector{Int} # Road class of each edge end -################### -### Point Types ### -################### - -### Point in Latitude-Longitude-Altitude (LLA) coordinates -# Used to store node data in OpenStreetMap XML files -type LLA - lat::Float64 - lon::Float64 - alt::Float64 -end -LLA(lat, lon) = LLA(lat, lon, 0.0) - -### Point in Earth-Centered-Earth-Fixed (ECEF) coordinates -# Global cartesian coordinate system rotating with the Earth -type ECEF - x::Float64 - y::Float64 - z::Float64 -end - -### Point in East-North-Up (ENU) coordinates -# Local cartesian coordinate system -# Linearized about a reference point -type ENU - east::Float64 - north::Float64 - up::Float64 -end -ENU(x, y) = ENU(x, y, 0.0) - -### Helper for creating other point types -type XYZ - x::Float64 - y::Float64 - z::Float64 -end -XY(x, y) = XYZ(x, y, 0.0) - -LLA(xyz::XYZ) = LLA(xyz.y, xyz.x, xyz.z) -ENU(xyz::XYZ) = ENU(xyz.x, xyz.y, xyz.z) - -### Point translators -getX(lla::LLA) = lla.lon -getY(lla::LLA) = lla.lat - -getX(enu::ENU) = enu.east -getY(enu::ENU) = enu.north - -### World Geodetic Coordinate System of 1984 (WGS 84) -# Standardized coordinate system for Earth -# Global ellipsoidal reference surface -type WGS84 - a::Float64 - b::Float64 - e::Float64 - e_prime::Float64 - N - - function WGS84() - a = 6378137.0 # Semi-major axis - b = 6356752.31424518 # Semi-minor axis - e = sqrt((a*a - b*b) / (a*a)) # Eccentricity - e_prime = sqrt((a*a - b*b) / (b*b)) # Second eccentricity - new(a, b, e, e_prime) - end -end - ### Rendering style data type Style color::Uint32 diff --git a/test/coordinates.jl b/test/coordinates.jl deleted file mode 100644 index 8f3fc19..0000000 --- a/test/coordinates.jl +++ /dev/null @@ -1,49 +0,0 @@ -# Test Coordinate Transforms -module TestCoordinates - -using OpenStreetMap -using Base.Test - -# Point in LLA -lat = 42.3673; -lon = -71.0960; -alt = 0; -P_lla = OpenStreetMap.LLA(lat, lon, alt) - -@test P_lla.lat == lat -@test P_lla.lon == lon -@test P_lla.alt == alt - -# Reference point in LLA -lat0 = 42.36299; -lon0 = -71.09183; -alt0 = 0; -P_ref_lla = OpenStreetMap.LLA(lat0, lon0, alt0) - -# lla2ecef -P_ecef = lla2ecef(P_lla) - -@test_approx_eq P_ecef.x 1529073.1560519305 -@test_approx_eq P_ecef.y -4465040.019013103 -@test_approx_eq P_ecef.z 4275835.339260309 - -# lla2enu -P_enu = lla2enu(P_lla, P_ref_lla) - -@test_approx_eq P_enu.east -343.49374908345493 -@test_approx_eq_eps P_enu.north 478.7648554687071 1e-8 -@test_approx_eq_eps P_enu.up -0.027242884564486758 1e-8 - -##### -# Bounds object -bounds = OpenStreetMap.Bounds(42.365, 42.3695, -71.1, -71.094) -bounds_enu = lla2enu(bounds) - -@test_approx_eq bounds_enu.min_y -249.92653559014204 -@test_approx_eq bounds_enu.max_y 249.9353534127322 -@test_approx_eq bounds_enu.min_x -247.1091823451915 -@test_approx_eq bounds_enu.max_x 247.1268196141778 - -@test_throws ArgumentError OpenStreetMap.Bounds(-90.1, 90.1, -181.1, 181.1) - -end # module TestCoordinates diff --git a/test/crop_map.jl b/test/crop_map.jl index c4a94f2..3263410 100644 --- a/test/crop_map.jl +++ b/test/crop_map.jl @@ -11,9 +11,6 @@ MAP_FILENAME = "tech_square.osm" bounds = Bounds(42.3637, 42.3655, -71.0919, -71.0893) -bounds_ENU = lla2enu(bounds) -@test_approx_eq_eps aspectRatio(bounds) aspectRatio(bounds_ENU) 5e-3 - nodes, hwys, builds, feats = getOSMData(MAP_FILENAME) cropMap!(nodes, bounds, highways=hwys, buildings=builds, features=feats, delete_nodes=true) @test length(nodes) == 198 diff --git a/test/intersections.jl b/test/intersections.jl index 93e68d8..d5e6fe5 100644 --- a/test/intersections.jl +++ b/test/intersections.jl @@ -6,16 +6,14 @@ using OpenStreetMap using Base.Test using Compat -import OpenStreetMap: Bounds, centerBounds - MAP_FILENAME = "tech_square.osm" bounds = Bounds(42.3637, 42.3655, -71.0919, -71.0893) -bounds_ENU = lla2enu(bounds) +bounds_ENU = ENU(bounds) nodesLLA, hwys, builds, feats = getOSMData(MAP_FILENAME) -nodes = lla2enu(nodesLLA,centerBounds(bounds)) +nodes = ENU(nodesLLA, center(bounds)) # Find intersections in map intersections = findIntersections(hwys) diff --git a/test/plots.jl b/test/plots.jl index ee3917c..f667e55 100644 --- a/test/plots.jl +++ b/test/plots.jl @@ -28,9 +28,9 @@ p = plotMap(nodesLLA, highways=hwys, buildings=builds, features=feats, bounds=bo @test Winston.getattr(p, "xrange") == (-71.0939, -71.0891) @test Winston.getattr(p, "yrange") == (42.3626, 42.3659) -lla_ref = OpenStreetMap.centerBounds(boundsLLA) -nodesENU = OpenStreetMap.lla2enu(nodesLLA, lla_ref) -boundsENU = OpenStreetMap.lla2enu(boundsLLA, lla_ref) +lla_ref = center(boundsLLA) +nodesENU = ENU(nodesLLA, lla_ref) +boundsENU = ENU(boundsLLA, lla_ref) p2 = plotMap(nodesENU, highways=hwys, buildings=builds, features=feats, bounds=boundsENU, width=500, feature_classes=feat_classes, building_classes=bldg_classes, cycleways=cycles, walkways=peds, roadways=roads, km=true, fontsize=4) @@ -39,9 +39,9 @@ p2 = plotMap(nodesENU, highways=hwys, buildings=builds, features=feats, bounds=b @test Winston.getattr(p2, "ylabel") == "North (km)" @test Winston.getattr(p2.x1, "draw_axis") == true @test Winston.getattr(p2.x1, "draw_grid") == false -@test_approx_eq_eps Winston.getattr(p2, "xrange")[1] -0.1976986338592228 1e-6 +@test_approx_eq_eps Winston.getattr(p2, "xrange")[1] -0.19770898045741428 1e-6 @test_approx_eq_eps Winston.getattr(p2, "xrange")[2] 0.19770898045628862 1e-6 -@test_approx_eq_eps Winston.getattr(p2, "yrange")[1] -0.1832797798024081 1e-6 +@test_approx_eq_eps Winston.getattr(p2, "yrange")[1] -0.18328257005093138 1e-6 @test_approx_eq_eps Winston.getattr(p2, "yrange")[2] 0.18328541309049148 1e-6 end # module TestPlots diff --git a/test/routes.jl b/test/routes.jl index 4414629..ecad4b3 100644 --- a/test/routes.jl +++ b/test/routes.jl @@ -13,7 +13,7 @@ bounds = getBounds(parseMapXML(MAP_FILENAME)) cropMap!(nodes, bounds, highways=hwys, buildings=builds, features=feats, delete_nodes=true) # Convert Nodes to ENU Coordinates -nodesENU = lla2enu(nodes, OpenStreetMap.centerBounds(bounds)) +nodesENU = ENU(nodes, center(bounds)) # Form transportation network roads = roadways(hwys) @@ -22,8 +22,8 @@ network = createGraph(nodesENU, hwys, roads, Set(1:8)) @test Graphs.num_vertices(network.g) == 155 @test Graphs.num_edges(network.g) == 273 -loc_start = OpenStreetMap.ENU(-5000, 5500, 0) -loc_end = OpenStreetMap.ENU(5500, -4000, 0) +loc_start = ENU(-5000, 5500, 0) +loc_end = ENU(5500, -4000, 0) node0 = nearestNode(nodesENU, loc_start, collect(keys(network.v))) node1 = nearestNode(nodesENU, loc_end, collect(keys(network.v))) @@ -46,7 +46,7 @@ shortest_route, shortest_distance = shortestRoute(network, node0, node1) # Fastest Route fastest_route, fastest_time = fastestRoute(network, node0, node1) -fastest_distance = OpenStreetMap.distance(nodesENU, fastest_route) +fastest_distance = distance(nodesENU, fastest_route) @test length(fastest_route) == 22 @test_approx_eq fastest_distance 724.5817003198007 @test fastest_route[1] == node0 @@ -111,8 +111,8 @@ _, r_fastest_segment_time = fastestRoute(r_segment_network, node1, node0) loc0 = nodesENU[node0] filteredENU = filter((k,v)->haskey(network.v,k), nodesENU) local_indices = nodesWithinRange(filteredENU, loc0, 100.0) -@test length(local_indices) == 4 -for index in [61317384, 23, 61317383, 17] +@test length(local_indices) == 3 +for index in [61317384, 23, 61317383] @test index in local_indices end @@ -142,7 +142,7 @@ end # Nodes within driving time node_indices, distances = nodesWithinDrivingTime(network, start_index, 50.0) @test length(node_indices) == length(distances) -@test length(node_indices) == 31 +@test length(node_indices) == 30 for index in [61318572, 33, 270134895, 575440057, 61323886, 473951349, 986189343] @test index in node_indices end @@ -153,7 +153,7 @@ end # Test nodes within driving time, with multi-start node_indices, distances = nodesWithinDrivingTime(network, local_indices, 50.0) @test length(node_indices) == length(distances) -@test length(node_indices) == 42 +@test length(node_indices) == 41 for index in [575444707, 270134899, 30, 270134936, 986189343] @test index in node_indices end diff --git a/test/runtests.jl b/test/runtests.jl index b83e7b1..2af7ee7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,6 @@ tests = [ "simcity", "crop_map", "classes", - "coordinates", "intersections", "routes", "plots" ]