Is a .osm file of size 668.7 MB too big for the following operations?

Hi, I was trying the following code, but with no lucks. It seems like my computer has no responses. The code:

> using OpenStreetMapX
> mx = get_map_data("test/data/reno_east3.osm",use_cache=false);
> using Random 
> Random.seed!(0)
> node_ids = collect(keys(mx.nodes)) 
> routes = Vector{Vector{Int}}()
> visits = Dict{Int,Int}()
> for i in 1:5000
>     a,b = [point_to_nodes(generate_point_in_bounds(mx), mx) for i in 1:2]
>     route, route_time = OpenStreetMapX.shortest_route(mx,a,b)
>     if route_time < Inf # when we select points neaer edges no route might be found
>         push!(routes, route)
>         for n in route
>             visits[n] = get(visits, n,0)+1
>         end 
>     end
> end

Could anyone give me some suggestions please? @pszufe

Have you checked the code never leaves this line? Have you printed something in the next line to check this?

I think if it is too big depends on your computer specs, but if it was “too big” the process would be killed by exhausting memory or your computer would begin to use swap. Have you checked some process monitor while running the code to see how Julia is behaving? (high CPU use? high mem use? started using swap?)

1 Like

the code leaves the line you mentioned. I believe the issue is at the for loop part.

This code comes from my tutorial.

Definitely 700MB is not too big. The only actual limitation is the memory size and I have been working with larger map files.
However for a file of this size finding the routes might take some time. You should first try to run a shorter loop (maybe 5 iterations instead of 5000) and measure the time.

When I need many routes over a large map I do the following things

  • either use a larger granularity of the map (use OSM filter to leave out only major roads)
  • or use @disrtibuted macro with an AWS EC2 instance (or a cluster depending on scale)
1 Like

@bsnyh You are not helping yourself saying “loop part”, while having an not indented code that does have more than one loop.

I have to admit I do not understand why the variable i of the first loop is used nowhere (why do not use underscore then?), and why a new i is used in the list comprehension to generate the points two times (instead of generating one time, and then appending, what would have a better performance probably).

Thank you for your reply. The first i in the loop is not used anywhere, and it is mainly a counter. The second i is used in the list comprehension to generate a pair of points and then to converts these two points to nodes identifiers, which are a and b.

You have two variables named i which shouldn’t be a problem because of scoping, but is generally considered bad form. I would put some print statements in your code to see if it’s making progress at all.

2 Likes

I have changed the for loop from for i in 1:5000 to for i in 1:500, and still does not quite work out.

it’s working, after changing the returned value of the OpenStreetMapX.shortest_route(mx,a,b) function. @pszufe, from my understanding, nodes are abstract representations of points, and nodes are created artificially, right? Are nodes here the same as vertices of graphs?

@pszufe, why does it return Inf, if the points are selected near edges?

@pszufe, why does it return Inf, if the points are selected near edges?

I suppose this is the reason: https://github.com/pszufe/OpenStreetMapX.jl/blob/500652a1f71ce551224ce560a609dc44c1b9c866/src/nodes.jl#L25

1 Like

Regarding Inf. For computations we always use some fragment of the map. Hence, you might quite often have a situation where for 2 randomly chosen nodes in the road system no path exists between them (simply because they are close to the edge of the map). When there is not path between 2 nodes the library returns Inf for the distance.

1 Like

I have updated the tutorial to be more self-contained (it uses the test OSM file that is together with the OpenStreetMapX library) and have corrected the ugly style of the loop inside the comprehension.

@bsnyh Regarding nodes: Within OpenStreetMapX, the road system is represented as a weighted directed graph using the LightGraphs.jl package. The graph nodes represent intersection. If you want to see it on map - you can decrease the loop count in the tutorial to say 5 instead of 5000 and then in the last plot remove the minimum visit count per node. This will plot circles for each node visited when traveling between two points. This will give you good understanding where are the nodes on the map.

Regarding “does not work” - try running the loop once (i.e. 1:1) and write what happens). Check your memory and CPU loads. Finding a single route takes between 1 and few hundred milliseconds depending on map complexity.

1 Like

the code runs in about 10 seconds for me.

ProgressMeter.jl can be a nice tool for such cases. You may want to check it out.

import Pkg
cd("C:\\temp\\")
Pkg.activate(".")
using Random 
using OpenStreetMapX
using ProgressMeter

function mine(itrs)
pt=splitdir(pathof(OpenStreetMapX))[1]
mx = get_map_data(joinpath(pt,"..","test","data","reno_east3.osm"),use_cache=false);
 
Random.seed!(0)
node_ids = collect(keys(mx.nodes)) 
routes = Vector{Vector{Int}}()
visits = Dict{Int,Int}()
p = Progress(itrs, 1)   # minimum update interval: 1 second
for i=1:itrs 
    a,b = [point_to_nodes(generate_point_in_bounds(mx), mx) for i in 1:2]
    route, route_time = OpenStreetMapX.shortest_route(mx,a,b)
    if route_time < Inf # when we select points neaer edges no route might be found
        push!(routes, route)
        for n in route
            visits[n] = get(visits, n,0)+1
        end 
    end
    next!(p)
    end    
    routes,visits
end

r,v=mine(5000);
1 Like

Thank you so much for your kind reply. I was wondering, how to draw the map using matplotlib module? From your tutorial, I guess it’s because you are using Jupyter. That’s why you get the map printed out simply by entering the map m. I’m using Atom editor instead and I’m digging on folium and matplotlib currently.

For plotting with matplotlib I am providing OpenStreetMapXPlot.jl library that is using PyPlot.jl

1 Like

@pszufe, Thank you a lot. I will try to see if I can contribute. My ultimate goal is to create a simple animation. It looks like matplotlib can not draw map as gracefully as the python package folium, right? I also had some experiences with the unfolding maps http://unfoldingmaps.org, do not exactly know which one is the most appropriate for my task.

Use Timestamped-GeoJSON with folium see the example with animated houses here:
https://nbviewer.jupyter.org/github/python-visualization/folium/blob/master/examples/Plugins.ipynb#Timestamped-GeoJSON
use a car icon as a marker and node coordinates for locations.
It seem to be quite easy to do. Once you write the code you submit it here - I can add it to the tutorial

1 Like

Hi, pszufe, I was fascinated by the graph representations in the following open street routing machine link using open street map data. https://github.com/Project-OSRM/osrm-backend/wiki/Graph-representation I was thinking to implement it using Julia, and was wondering, could you provide any starting point references? Is this graph representation sort of similar to your OpenStreetMapX? — Regards, bsnyh.

Such pictures can be done with folium and my tutorial that you are using already.

1 Like