OpenStreetMapX, folium

I’m not sure this is the right place to post this but I’m trying to accomplish something like this: OpenStreetMapX_tutorial but with real coordinates.

Anyways, my problems is that the end result of the loop

map = flm.Map()
for k ∈ length(routes)
    path_coords = [LLA(m.nodes[n], m.bounds) for n in routes[k]]
    
    info = "Route number $k\n<BR>" *
            "Length: $(length(routes[k])) nodes\n<br>" *
            "From $(routes[k][1]) $(round.((path_coords[1].lat, path_coords[1].lon), digits=4))<br>" *
            "To $(routes[k][end]) $(round.((path_coords[end].lat, path_coords[end].lon), digits=4))"
            
    flm.PolyLine(
        [ (loc.lat, loc.lon) for loc in path_coords ],
        popup=info,
        tooltip=info,
        color=matplotlib_colors.to_hex(cmap(k/SHOW_PATHS))
    ).add_to(map)
end

is to draw just the last path. It’s as if it doesn’t mutate the map instantiated outside the loop, but rather creates a new one with every path_coords. Here is a picture where the tooltip confirms to me that it is the last set of points

If step through them manually, like so

path_coords = [LLA(m.nodes[n], m.bounds) for n in routes[1]]
info = "Route number $(1)\n<BR>" *
        "Length: $(length(routes[1])) nodes\n<br>" *
        ...
flm.PolyLine(
    [ (loc.lat, loc.lon) for loc in path_coords ],
    popup=info,
        ...
).add_to(map)

I can draw them individually on a different map each. This is the first one, for instance:


And here’s the fifth for completeness

Please let me know if this a sufficient working example…
Here’s the map Geofabrik Download Server
Here’s 10 coordinates

ptsOrig = [(40.40035, -3.70306), (40.47780807, -3.69849334), (40.4377299, -3.6800531), (40.4211153, -3.6879227), (40.41384654, -3.69493838), (40.471597, -3.682403), (40.48230943, -3.67061352), (40.4239884, -3.6864495), (40.406806, -3.691947), (40.44236981, -3.65546398)]
ptsDest = [(40.40647374, -3.68861037), (40.4766087, -3.6876792), (40.423677, -3.6848885), (40.4429993, -3.67984459), (40.42625779, -3.69331498), (40.4170684, -3.6756673), (40.40042329, -3.61914136), (40.43208461, -3.68719853), (40.4431324, -3.6743115), (40.43723621, -3.66986241)]

And the code I’ve used to make them conformable to OpenStreetMap

startEndNodes = collect(zip(
    [point_to_nodes(pt, mad) for pt in ptsOrig if inbounds(LLA(pt[1], pt[2]), mad.bounds) ],
    [point_to_nodes(pt, mad) for pt in ptsDest if inbounds(LLA(pt[1], pt[2]) , mad.bounds) ]
    ))

routes = Vector{Vector{Int}}()

for (s,e) in startEndNodes
    if s != e
        route, route_time = OpenStreetMapX.shortest_route(mad, s, e)
        if route_time < Inf
            push!(routes, route)
        end
    end
end

Please let me know if you need anything else, thanks!

for k ∈ length(routes)

This iterates only the single number routes, classic Julia footgun :slight_smile: (numbers can be iterated as single-element collections)

You need for k ∈ 1:length(routes) or for k ∈ eachindex(routes), for example.

1 Like

Thank you!