Hi all,
I am using Jupyter Notebook on this tutorial
https://pszufe.github.io/OpenStreetMapX_Tutorial/JuliaCon2021/
I change LightGraphs into Graphs. Then there is an error when running this code:
m = get_map_data("/home/browni/LasthrimProjection/map/waghetemap.osm", use_cache=false, trim_to_connected_graph=true );
function add_graph_edge!(m::MapData, va::Int, vb::Int;symmetric=false)
Graphs.add_edge!(m.g, va, vb)
push!(m.e,(m.n[va], m.n[vb]) )
symmetric && add_graph_edge!(m, vb, va; symmetric=false)
end
wI, wJ, wV = findnz(m.w)
agent_speed = 3_000/60 # meters in minute (that is 3km/h)
wV = wV ./ agent_speed # all distances in minutes instead of meters
points = [ENU(LLA(ttc.lat[t], ttc.lon[t]), m.bounds) for t in 1:nrow(ttc)]
nodecs = nearest_node.(Ref(m), points)
for t in 1:nrow(ttc)
Graphs.add_vertex!(m.g)
vx = nv(m.g)
push!(m.n, -vx) # add vertex to MapData - negative indices are used for special purposes
#for simplicity we assume no identifier clash
m.nodes[-vx] = points[t]
m.v[-vx] = vx
vc = m.v[nodecs[t]]
add_graph_edge!(m, vc, vx; symmetric=true)
append!(wI, [vx, vc])
append!(wJ, [vc, vx])
append!(wV, [3.0, 3.0]) # getting in or out of TTC takes 3 minutes
if t>1 #build the TTC line in graph
add_graph_edge!(m, vx-1, vx; symmetric=false)
append!(wI, vx-1)
append!(wJ, vx)
append!(wV, 2.0) # TTC travels 2 minutes between stops
# this is a simplificatio of course real data
# could be used
end
end
# now we construct the updated distance matrix:
m.w = sparse(wI,wJ,wV)
@assert size(m.w,1)==size(m.w,2)
@assert size(m.w,1)==nv(m.g)
The weird thing is I try on Julia REPL
using Graphs
g = path_graph(8)
nv(g)
I get the output of 8.
Why is nv
becomes UndefVarError: nv not defined at JupyterNotebook?