Open sahilm1992 opened 4 years ago
You are supposed to get the road network information from open street map and import it into the database. Then run the following script.
using PyCall
using LightGraphs
@pyimport psycopg2
@pyimport pandas as pd
host = "localhost"
port = 5432
database = "harbin"
user = "osmuser"
password = "pass"
con = psycopg2.connect(host=host,
port=port,
database=database,
user=user,
password=password)
con[:set_client_encoding]("UTF8")
bfmapways = pd.read_sql_query("select gid, osm_id, source, target, reverse from bfmap_ways;", con)
con[:close]()
reversible = bfmapways[:reverse][:values] .== 1.0
source = bfmapways[:source][:values]
target = bfmapways[:target][:values]
edgeid = bfmapways[:gid][:values]
nodes = collect(Set(source) ∪ Set(target)) |> sort
n2i = Dict(n=>i for (i, n) in enumerate(nodes))
i2n = Dict(reverse(kv) for kv in n2i)
function createGraph(source::Vector{Int}, target::Vector{Int}, reversible::AbstractVector{Bool})
g = SimpleDiGraph(length(nodes))
for (s, t, r) in zip(source, target, reversible)
if r == true
add_edge!(g, n2i[s], n2i[t])
add_edge!(g, n2i[t], n2i[s])
else
add_edge!(g, n2i[s], n2i[t])
end
end
return g
end
Hi, Will it be possible for you to share the network construction script? Which road segment is neighbor of which one?