pszufe / OpenStreetMapX.jl

OpenStreetMap (*.osm) support for Julia 1.0 and up
MIT License
118 stars 24 forks source link

MethodError in reading a .osm file #40

Closed kavir1698 closed 3 years ago

kavir1698 commented 3 years ago

I have downloaded a city osm from here and I tried reading it.

This gives me an empty MapData:

julia> zurich = get_map_data(map_path, only_intersections=true,use_cache=false)

MapData(OpenStreetMapX.Bounds{LLA}(0.0, 0.0, 0.0, 0.0), Dict{Int64,ENU}(), OpenStreetMapX.Way[], Dict{Int64,Set{Int64}}(), {0, 0} directed simple Int64 graph, Dict{Int64,Int64}(), Int64[], Tuple{Int64,Int64}[], 0×0 SparseArrays.SparseMatrixCSC{Float64,Int64} with 0 stored entries, Int64[])

And this gives me an error:

zurich = get_map_data(map_path, only_intersections=false,use_cache=false)

ERROR: MethodError: no method matching get_edges(::Dict{Any,Any}, ::Array{OpenStreetMapX.Way,1})
Closest candidates are:
  get_edges(::Dict{Int64,T}, ::Array{OpenStreetMapX.Way,1}) where T<:Union{ECEF, ENU} at C:\Users\Ali\.julia\packages\OpenStreetMapX\pfbvr\src\routing.jl:5
Stacktrace:
 [1] MapData(::OpenStreetMapX.OSMData, ::Set{Int64}, ::Bool; trim_to_connected_graph::Bool, remove_nodes::Set{Int64}) at C:\Users\Ali\.julia\packages\OpenStreetMapX\pfbvr\src\parseMap.jl:162
 [2] get_map_data(::String, ::Nothing; road_levels::Set{Int64}, use_cache::Bool, only_intersections::Bool, trim_to_connected_graph::Bool) at C:\Users\Ali\.julia\packages\OpenStreetMapX\pfbvr\src\parseMap.jl:102
 [3] top-level scope at REPL[76]:

I am using OpenStreetMapX v0.2.3 and Julia 1.5.2

pszufe commented 3 years ago

What file have you downloaded? Note that you need XML .osm file and on this web page I only see files in the binary .pbf format.

kavir1698 commented 3 years ago

I downloaded a .pbf file and then converted it to .osm using the osmconvert tool (provided by OpenStreeMap org).

pszufe commented 3 years ago

OpenStreetMapX relies on map bounds being defined in the file. Somehow in your files those bounds are missing. Try adding them manually.

osmconvert zurich.osm.pbf --drop-author --drop-version -b=8.40,47.25,8.70,47.50 -o=zurichF.osm

Note that I did not manage to replicate your error - I was just observing an empty MapData object.

Let me know if this works for you.

kavir1698 commented 3 years ago

Thanks for your help. Adding the bounds solved the issue in both cases. I just don't see where you found those exact numbers for bounds.

pszufe commented 3 years ago

I just don't see where you found those exact numbers for bounds

I guessed. These are just any numbers that seemed to be more or less OK - you need to pick up more exact numbers.