Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom road colors #10

Open
jwassmer opened this issue Oct 11, 2021 · 2 comments
Open

Custom road colors #10

jwassmer opened this issue Oct 11, 2021 · 2 comments

Comments

@jwassmer
Copy link

jwassmer commented Oct 11, 2021

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!

@pszufe
Copy link
Owner

pszufe commented Oct 12, 2021

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
Copy link
Owner

pszufe commented Oct 12, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants