Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

042 compat #79

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ before_install:
- "sh -e /etc/init.d/xvfb start"
script:
- julia -e 'versioninfo(); Pkg.init(); Pkg.clone(pwd())'
- julia -e 'Pkg.checkout("Geodesy")'
- julia -e 'Pkg.checkout("Cairo")'
- julia -e 'Pkg.checkout("JuliaParser")'
- julia -e 'Pkg.checkout("IniFile")'
- julia -e 'Pkg.checkout("Tk")'
- julia -e 'Pkg.checkout("Winston")'
- julia -e 'Pkg.test("OpenStreetMap", coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("OpenStreetMap")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
Expand Down
15 changes: 7 additions & 8 deletions src/crop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
### Copyright 2014 ###

### Crop map elements without copying data ###
function cropMap!(nodes::Union(Dict{Int,LLA},Dict{Int,ENU}),
bounds::Bounds;
highways::Union(Nothing,Dict{Int,Highway})=nothing,
buildings::Union(Nothing,Dict{Int,Building})=nothing,
features::Union(Nothing,Dict{Int,Feature})=nothing,
function cropMap!(nodes::@compat(Union{Dict{Int,LLA},Dict{Int,ENU}}), bounds::Bounds;
highways::@compat(Union{@compat(Void),Dict{Int,Highway}}) = nothing,
buildings::@compat(Union{@compat(Void),Dict{Int,Building}}) = nothing,
features::@compat(Union{@compat(Void),Dict{Int,Feature}}) = nothing,
delete_nodes::Bool=true)

if !isa(highways, Nothing)
if !isa(highways, @compat(Void))
crop!(nodes, bounds, highways)
end
if !isa(buildings, Nothing)
if !isa(buildings, @compat(Void))
crop!(nodes, bounds, buildings)
end
if !isa(features, Nothing)
if !isa(features, @compat(Void))
crop!(nodes, bounds, features)
end

Expand Down
8 changes: 3 additions & 5 deletions src/highways.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ end
function findHighwaySets( highways::Dict{Int,Highway} )
clusters = HighwaySet[]

street_names = (String,String,Int)[]
street_names = @compat Tuple{@compat(AbstractString), @compat(AbstractString), Int}[]

for (key, highway) in highways
if length(highway.name) > 0 && highway.oneway
push!(street_names,(highway.name,highway.class,key))
Expand All @@ -82,13 +82,11 @@ function findHighwaySets( highways::Dict{Int,Highway} )
end
end
end

if length(cluster) > 1
push!(clusters,HighwaySet(Set(cluster)))
end
end

return clusters
end


26 changes: 12 additions & 14 deletions src/nodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


### Find the nearest node to a given location ###
function nearestNode{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T}, loc::T)
function nearestNode{T<:@compat(Union{ENU,ECEF})}(nodes::Dict{Int,T}, loc::T)
min_dist = Inf
best_ind = 0

Expand All @@ -21,7 +21,7 @@ end


### Find nearest node in a list of nodes ###
function nearestNode{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T},
function nearestNode{T<:@compat(Union{ENU,ECEF})}(nodes::Dict{Int,T},
loc::T,
node_list::Vector{Int})
min_dist = Inf
Expand All @@ -40,15 +40,15 @@ end


### Find nearest node serving as a vertex in a routing network ###
function nearestNode{T<:Union(ENU,ECEF)}( nodes::Dict{Int,T},
function nearestNode{T<:@compat(Union{ENU,ECEF})}( nodes::Dict{Int,T},
loc::T,
network::Network )
return nearestNode(nodes,loc,collect(keys(network.v)))
end


### Find all nodes within range of a location ###
function nodesWithinRange{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T},
function nodesWithinRange{T<:@compat(Union{ENU,ECEF})}(nodes::Dict{Int,T},
loc::T,
range::Float64=Inf)
if range == Inf
Expand All @@ -63,10 +63,10 @@ function nodesWithinRange{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T},
end
return indices
end


### Find nodes within range of a location using a subset of nodes ###
function nodesWithinRange{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T},
function nodesWithinRange{T<:@compat(Union{ENU,ECEF})}(nodes::Dict{Int,T},
loc::T,
node_list::Vector{Int},
range::Float64=Inf)
Expand All @@ -85,7 +85,7 @@ end


### Find vertices of a routing network within range of a location ###
function nodesWithinRange{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T},
function nodesWithinRange{T <: @compat(Union{ENU,ECEF}) }(nodes::Dict{Int,T},
loc::T,
network::Network,
range::Float64=Inf)
Expand All @@ -94,9 +94,9 @@ end


### Add a new node ###
function addNewNode!{T<:Union(LLA,ENU)}(nodes::Dict{Int,T},
loc::T,
start_id::Int=abs(int(hash(loc))) )
function addNewNode!{T <: @compat(Union{LLA,ENU}) }(nodes::Dict{Int,T},
loc::T,
start_id::Int = reinterpret(@compat(Int), hash(loc)) )
id = start_id
while id <= typemax(Int)
if !haskey(nodes, id)
Expand All @@ -107,12 +107,12 @@ function addNewNode!{T<:Union(LLA,ENU)}(nodes::Dict{Int,T},
end

msg = "Unable to add new node to map, $(typemax(Int)) nodes is the current limit."
throw(OverflowError(msg))
throw(error(msg))
end


### Compute centroid of list of nodes ###
function centroid{T<:Union(LLA,ENU)}(nodes::Dict{Int,T}, node_list::Vector{Int})
function centroid{T<:@compat(Union{LLA,ENU})}(nodes::Dict{Int,T}, node_list::Vector{Int})
sum_1 = 0
sum_2 = 0
sum_3 = 0
Expand All @@ -135,5 +135,3 @@ function centroid{T<:Union(LLA,ENU)}(nodes::Dict{Int,T}, node_list::Vector{Int})
return ENU(sum_1/length(node_list),sum_2/length(node_list),sum_3/length(node_list))
end
end


30 changes: 15 additions & 15 deletions src/parseMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ end

### PARSE XML ELEMENTS ###

function parse_node(attr::OSMattributes, attrs_in::Dict{String,String})
function parse_node(attr::OSMattributes, attrs_in::Dict{@compat(AbstractString),@compat(AbstractString)})
attr.visible = true
attr.element = :Node
if haskey(attrs_in, "id")
attr.id = int(attrs_in["id"])
attr.id = @compat( parse(Int,attrs_in["id"]) )
attr.lat = float(attrs_in["lat"])
attr.lon = float(attrs_in["lon"])
end
end

function parse_way(attr::OSMattributes, attrs_in::Dict{String,String})
function parse_way(attr::OSMattributes, attrs_in::Dict{@compat(AbstractString),@compat(AbstractString)})
attr.visible = true
attr.element = :Way
if haskey(attrs_in, "id")
attr.id = int(attrs_in["id"])
attr.id = @compat( parse(Int,attrs_in["id"]) )
end
end

function parse_nd(attr::OSMattributes, attrs_in::Dict{String,String})
function parse_nd(attr::OSMattributes, attrs_in::Dict{@compat(AbstractString),@compat(AbstractString)})
if haskey(attrs_in, "ref")
push!(attr.way_nodes, int64(attrs_in["ref"]))
push!(attr.way_nodes, @compat( parse(Int64,attrs_in["ref"]) ) )
end
end

function parse_tag(attr::OSMattributes, attrs_in::Dict{String,String})
function parse_tag(attr::OSMattributes, attrs_in::Dict{@compat(AbstractString),@compat(AbstractString)})
if haskey(attrs_in, "k") && haskey(attrs_in, "v")
k, v = attrs_in["k"], attrs_in["v"]
if k == "name"
Expand All @@ -97,7 +97,7 @@ end

### PARSE OSM ENTITIES ###

function parse_highway(attr::OSMattributes, k::String, v::String)
function parse_highway(attr::OSMattributes, k::@compat(AbstractString), v::@compat(AbstractString))
if k == "highway"
attr.class = v
if v == "services" # Highways marked "services" are not traversable
Expand Down Expand Up @@ -126,29 +126,29 @@ function parse_highway(attr::OSMattributes, k::String, v::String)
elseif k == "bicycle"
attr.bicycle = v
elseif k == "lanes" && length(v)==1 && '1' <= v[1] <= '9'
attr.lanes = int(v)
attr.lanes = @compat parse(Int,v)
else
return
end
attr.parent = :Highway
end

function parse_building(attr::OSMattributes, v::String)
function parse_building(attr::OSMattributes, v::@compat(AbstractString))
attr.parent = :Building
if isempty(attr.class)
attr.class = v
end
end

function parse_feature(attr::OSMattributes, k::String, v::String)
function parse_feature(attr::OSMattributes, k::@compat(AbstractString), v::@compat(AbstractString))
attr.parent = :Feature
attr.class = k
attr.detail = v
end

### LibExpat.XPStreamHandlers ###

function parseElement(handler::LibExpat.XPStreamHandler, name::String, attrs_in::Dict{String,String})
function parseElement(handler::LibExpat.XPStreamHandler, name::@compat(AbstractString), attrs_in::Dict{@compat(AbstractString),@compat(AbstractString)})
attr = handler.data.attr::OSMattributes
if attr.visible
if name == "nd"
Expand All @@ -165,7 +165,7 @@ function parseElement(handler::LibExpat.XPStreamHandler, name::String, attrs_in:
end # no work done for "relations" yet
end

function collectValues(handler::LibExpat.XPStreamHandler, name::String)
function collectValues(handler::LibExpat.XPStreamHandler, name::@compat(AbstractString))
# println(typeof(name))
osm = handler.data::OSMdata
attr = osm.attr::OSMattributes
Expand Down Expand Up @@ -193,7 +193,7 @@ function collectValues(handler::LibExpat.XPStreamHandler, name::String)
end

### Parse the data from an openStreetMap XML file ###
function parseMapXML(filename::String)
function parseMapXML(filename::@compat(AbstractString))

# Parse the file
street_map = LightXML.parse_file(filename)
Expand All @@ -205,7 +205,7 @@ function parseMapXML(filename::String)
return street_map
end

function getOSMData(filename::String; args...)
function getOSMData(filename::@compat(AbstractString); args...)
osm = OSMdata()

callbacks = LibExpat.XPCallbacks()
Expand Down
48 changes: 26 additions & 22 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

### Functions for plotting using the Winston package ###

typealias Styles Union(Style, Dict{Int,Style})
typealias Styles @compat(Union{Style, Dict{Int,Style}})

### Generic Map Plot ###
function plotMap(nodes::Union(Dict{Int,LLA},Dict{Int,ENU});
highways::Union(Nothing,Dict{Int,Highway})=nothing,
buildings::Union(Nothing,Dict{Int,Building})=nothing,
features::Union(Nothing,Dict{Int,Feature})=nothing,
bounds::Union(Nothing,Bounds)=nothing,
intersections::Union(Nothing,Dict{Int,Intersection})=nothing,
function plotMap(nodes::@compat(Union{Dict{Int,LLA},Dict{Int,ENU}}) ;
highways::@compat(Union{@compat(Void),Dict{Int,Highway}}) = nothing,
buildings::@compat(Union{@compat(Void),Dict{Int,Building}}) = nothing,
features::@compat(Union{@compat(Void),Dict{Int,Feature}}) = nothing,
bounds::@compat(Union{@compat(Void),Bounds}) = nothing,
intersections::@compat(Union{@compat(Void),Dict{Int,Intersection}}) = nothing,
roadways=nothing,
cycleways=nothing,
walkways=nothing,
feature_classes::Union(Nothing,Dict{Int,Int})=nothing,
building_classes::Union(Nothing,Dict{Int,Int})=nothing,
route::Union(Nothing,Vector{Int},Vector{Vector{Int}})=nothing,
feature_classes::@compat(Union{@compat(Void),Dict{Int,Int}}) = nothing,
building_classes::@compat(Union{@compat(Void),Dict{Int,Int}}) = nothing,
route::@compat(Union{@compat(Void),Vector{Int},Vector{Vector{Int}}}) = nothing,
highway_style::Styles=Style(0x007CFF, 1.5, "-"),
building_style::Styles=Style(0x000000, 1, "-"),
feature_style::Styles=Style(0xCC0000, 2.5, "."),
route_style::Union(Style,Vector{Style})=Style(0xFF0000, 3, "-"),
route_style::@compat(Union{Style,Vector{Style}}) = Style(0xFF0000, 3, "-"),
intersection_style::Style=Style(0x000000, 3, "."),
width::Integer=500,
fontsize::Integer=0,
Expand All @@ -39,12 +39,16 @@ function plotMap(nodes::Union(Dict{Int,LLA},Dict{Int,ENU});
end

# Waiting for Winston to add capability to force equal scales. For now:
height = isa(bounds, Nothing) ? width : int(width / aspectRatio(bounds))
if VERSION.minor < 4
height = isa(bounds, @compat(Void)) ? width : int(width / aspectRatio(bounds))
else
height = isa(bounds, @compat(Void)) ? width : round(Int, width / aspectRatio(bounds))
end

# Create the figure
fignum = Winston.figure(name="OpenStreetMap Plot", width=width, height=height)

if isa(bounds, Nothing)
if isa(bounds, @compat(Void))
p = Winston.FramedPlot("xlabel", xlab, "ylabel", ylab)
else # Limit plot to specified bounds
Winston.xlim(bounds.min_x, bounds.max_x)
Expand All @@ -62,8 +66,8 @@ function plotMap(nodes::Union(Dict{Int,LLA},Dict{Int,ENU});
end

# Iterate over all buildings and draw
if !isa(buildings, Nothing)
if !isa(building_classes, Nothing)
if !isa(buildings, @compat(Void))
if !isa(building_classes, @compat(Void))
if isa(building_style, Dict{Int,Style})
drawWayLayer(p, nodes, buildings, building_classes, building_style, km, realtime)
else
Expand All @@ -81,23 +85,23 @@ function plotMap(nodes::Union(Dict{Int,LLA},Dict{Int,ENU});
end

# Iterate over all highways and draw
if !isa(highways, Nothing)
if !isa(highways, @compat(Void))
if !(nothing == roadways == cycleways == walkways)
if !isa(roadways, Nothing)
if !isa(roadways, @compat(Void))
if isa(highway_style, Dict{Int,Style})
drawWayLayer(p, nodes, highways, roadways, highway_style, km, realtime)
else
drawWayLayer(p, nodes, highways, roadways, LAYER_STANDARD, km, realtime)
end
end
if !isa(cycleways, Nothing)
if !isa(cycleways, @compat(Void))
if isa(highway_style, Dict{Int,Style})
drawWayLayer(p, nodes, highways, cycleways, highway_style, km, realtime)
else
drawWayLayer(p, nodes, highways, cycleways, LAYER_CYCLE, km, realtime)
end
end
if !isa(walkways, Nothing)
if !isa(walkways, @compat(Void))
if isa(highway_style, Dict{Int,Style})
drawWayLayer(p, nodes, highways, walkways, highway_style, km, realtime)
else
Expand All @@ -116,8 +120,8 @@ function plotMap(nodes::Union(Dict{Int,LLA},Dict{Int,ENU});
end

# Iterate over all features and draw
if !isa(features, Nothing)
if !isa(feature_classes, Nothing)
if !isa(features, @compat(Void))
if !isa(feature_classes, @compat(Void))
if isa(feature_style, Dict{Int,Style})
drawFeatureLayer(p, nodes, features, feature_classes, feature_style, km, realtime)
else
Expand Down Expand Up @@ -150,7 +154,7 @@ function plotMap(nodes::Union(Dict{Int,LLA},Dict{Int,ENU});
end

# Iterate over all intersections and draw
if !isa(intersections, Nothing)
if !isa(intersections, @compat(Void))
coords = Array(Float64, length(intersections), 2)
k = 1
for key in keys(intersections)
Expand Down
Loading