OpenStreetMapXPlot.jl icon indicating copy to clipboard operation
OpenStreetMapXPlot.jl copied to clipboard

Custom road colors

Open jwassmer opened this issue 3 years ago • 2 comments

I want to color the roads of a OSM according to their edge-betweenness centrality. I used the following approach, which does not work in the end. Is there a smart way to solve my problem?

I start by plugging in my osm file aswell as computing the roads corresponding edge-betweenness.

m = get_map_data("myfile.osm", use_cache=false, trim_to_connected_graph=true) #get map-data
σ = edge_betweenness_centrality(m.g, distmx=m.w) #compute weighted edge-betweenness

Then, I bin the classes of m.class of roads depending on their edge-betweenness

Nbin = 20
for (i, val) in enumerate(σ)
    bins = range(0, stop=maximum(σ), length=Nbin)
    
    if val < 1e-10
        mx.class[i] = 1
    else
        for (j, b) in enumerate(reverse(bins))
            if val >= b
                m.class[i] = Nbin-j+1
                break
            end
        end
    end
end

Next I set the Layer colors according to some colormap.

cbar = cgrad(:cividis, Nbin, categorical = true, rev = true)

LAYER_EDGEBETWEENNESS = Dict(1 => OpenStreetMapXPlot.Style("0x"*hex(cbar[1]), 1, "-"))
for i in 2:Nbin
    push!(LAYER_EDGEBETWEENNESS, i => OpenStreetMapXPlot.Style("0x"*hex(cbar[i]), 1, "-"))
end

Last, I try to plot the map with the new classes and 'roadwayStyle'

OpenStreetMapXPlot.plotmap(m, width = 600, height = 400, roadwayStyle = LAYER_EDGEBETWEENNESS)

This does not work, because plotmap() uses the data of m.roadways instead of m.class. Is there a smart way do this? I do realise that my way is a workaround anyways, but I dont know how to approach it elseway.

Thanks a lot for your help!

jwassmer avatar Oct 11 '21 20:10 jwassmer

Hi, unfortunately it is hard-coded to the plotmap() function. However it should be fairly easy to prepare a pull request extending coloring functionality (the code of plotmap() is really simple). If you want to propose some extension, I am all for it :)

pszufe avatar Oct 12 '21 09:10 pszufe

One more idea. If you are looking for a less-effort solution you could just plot the roads as an overlay on the map. Firstly, plot the map in a standard way and then plot on it! You have an example at OpenStreetMapXPlot.jl home page.

pszufe avatar Oct 12 '21 16:10 pszufe