# What's the general algorithm to draw a road network of a certain area?

**URL:** <https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657>\
**Category:** General Usage\
**Created:** [February 11, 2019, 9:32am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657 "2019-02-11T09:32:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 11, 2019, 9:32am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/1 "2019-02-11T09:32:08Z")

</div>

Hi, this might be a naive question. But I would really appreciate it if someone can give me some hints. I was wondering, how do people usually plot the road network of a certain area in a map? Of course, certain coding function is called, but how? Thank you so much for your time and attention.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [February 11, 2019, 10:35am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/2 "2019-02-11T10:35:16Z")

</div>

You can checkout [GitHub - pszufe/OpenStreetMapXPlot.jl: Plotting functionality for the OpenStreetMapX.jl (Supports PyPlot.jl and Plots.jl with GR backend)](https://github.com/pszufe/OpenStreetMapXPlot.jl) that is the plotting frontend of [https://github.com/pszufe/OpenStreetMapX.jl](https://github.com/pszufe/OpenStreetMapX.jl) and uses data from OpenStreetMap.

@pszufe is an expert here, so he might have some more advice to share.

---

<div class="post-metadata">

**Author:** ![pszufe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pszufe/32/23452_2.png) [@pszufe](https://discourse.julialang.org/u/pszufe)\
**Post date:** [February 11, 2019, 11:45am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/3 "2019-02-11T11:45:25Z")

</div>

[OpenStreetMapX.jl](https://github.com/pszufe/OpenStreetMapX.jl/) allows you to process data in Open Street Map format (if you do not know how to get this data - it is described in project website). In particular a map in OpenStreetMapX.jl is represnted as a LightGraphs.jl graph.

For plotting you can use [OpenStreetMapXPlot.jl](https://github.com/pszufe/OpenStreetMapXPlot.jl/) - this is particularly useful for coloring routes or marking nodes on the map.

For interactive plotting the best tools out there seems to be [LeafletJS](https://leafletjs.com/). There is a Julia wrapper for it [LeafletJS.jl](https://github.com/yeesian/LeafletJS.jl) but unfortunately it is unmaintained. What I usually do to process map data/analytics with Julia and if I need interactivity I use R-Leaflet integration.

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 11, 2019, 12:35pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/4 "2019-02-11T12:35:49Z")

</div>

I think I have tried the OpenStreetMapx.jl, with my osm map data. But the data is too large, and the map finally obtained does not look very good. Someone told me that I need to leave out certain information from the data, and eventually I tried the other way around, by using a python package osmnx and then tried to call this python function from juilia. I’d prefer to mainly use Julia though.

Is there a standard way to process the huge osm file obtained from the open street map website?

---

<div class="post-metadata">

**Author:** ![pszufe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pszufe/32/23452_2.png) [@pszufe](https://discourse.julialang.org/u/pszufe)\
**Post date:** [February 11, 2019, 4:04pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/5 "2019-02-11T16:04:52Z")

</div>

Use the [osmfilter](https://wiki.openstreetmap.org/wiki/Osmfilter) utility first. I do vehicle traffic modellig/agent-based simulations and usually this command works for me:

```
osmfilter myfile.osm --keep="highway=motorway highway=motorway_link highway=trunk highway=trunk_link highway=primary highway=primary_link highway=secondary highway=secondary_link highway=tertiary highway=tertiary_link highway=unclassified highway=residential" --drop-author -o=myfileout.osm 

```

After running this command your file will be around 6x smaller.  
Of course you might need different filtering depending on your needs.

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 11, 2019, 7:42pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/6 "2019-02-11T19:42:15Z")

</div>

@pszufe, One more question. How did you actually draw the edges, I mean, what’s the underlying principle? What I understand is that, if it’s a straight line, then it’s fairly easy to draw, because we basically can know the location of each point along this line. On the other hand, if it’s a curved line, then how did you know the shape / function of the line to draw it? I hope this is not a naive question to ask. I think this has something to do with the open street map data format.

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 11, 2019, 7:56pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/7 "2019-02-11T19:56:57Z")

</div>

Because I was thinking to model / visualize the movement of a vehicle along the road network. It would be much easier if each edge of the road network is a straight line, since in this case, I can just use linear function as the line/edge along any given two points. On the other hand, if it’s not a straight line, then things would be really complicated. I wonder how you handle this when you draw/plot the map.

---

<div class="post-metadata">

**Author:** ![pszufe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pszufe/32/23452_2.png) [@pszufe](https://discourse.julialang.org/u/pszufe)\
**Post date:** [February 11, 2019, 8:12pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/8 "2019-02-11T20:12:37Z")

</div>

@bsnyh - have a look at OpenStreetMapXPlot.jl source code. There are straight lines - just a lot of them. You can easily use OpenStreetMapXPlot.jl to render images of animation frames (with vehicle location), than you can use some other tool to combine the frames into a movie.

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 18, 2019, 6:26am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/9 "2019-02-18T06:26:26Z")

</div>

so, all of them are straight lines, not some kind of curves? If so, then linear interpolation would work.

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 18, 2019, 6:44am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/10 "2019-02-18T06:44:11Z")

</div>

the frames you’re talking about, do you mean geo-dataframes?

---

<div class="post-metadata">

**Author:** ![pszufe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pszufe/32/23452_2.png) [@pszufe](https://discourse.julialang.org/u/pszufe)\
**Post date:** [February 19, 2019, 2:48am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/11 "2019-02-19T02:48:43Z")

</div>

1. yes they are straight lines and you can use simple interpolation
2. I mean simply [animation frames](https://en.wikipedia.org/wiki/Animation), you could generate subsequent frames, save the to files and combine into a movie.

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 27, 2019, 5:39pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/12 "2019-02-27T17:39:43Z")

</div>

```julia
julia> m=OpenStreetMapX.get_map_data("/home/Desktop/country.osm")
ERROR: MethodError: no method matching get_map_data(::String)
Closest candidates are:
  get_map_data(::String, ::String; road_levels, use_cache) at /home/.julia/packages/OpenStreetMapX/lK8gq/src/parseMap.jl:82
Stacktrace:
 [1] top-level scope at none:0

julia> using Pkg

julia> Pkg.installed()
Dict{String,Union{Nothing, VersionNumber}} with 7 entries:
  "Juno" => v"0.5.3"
  "OpenStreetMapX" => v"0.1.1"
  "IJulia" => v"1.14.1"
  "Plots" => v"0.22.5"
  "Atom" => v"0.7.12"
  "PyCall" => v"1.18.5"
  "OpenStreetMapXPlot" => v"0.1.0"

julia> methods(get_map_data)
# 1 method for generic function "get_map_data":
[1] get_map_data(datapath::String, filename::String; road_levels, use_cache) in OpenStreetMapX at /home/.julia/packages/OpenStreetMapX/lK8gq/src/parseMap.jl:82

```

I’m using Julia 1.0.2. That might be the issue. In this case, I think I will need to install Julia 1.0.3, right?

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 27, 2019, 5:56pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/13 "2019-02-27T17:56:07Z")

</div>

No. It does not work for Julia version 1.0.3 either. This is strange.

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 27, 2019, 5:58pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/14 "2019-02-27T17:58:55Z")

</div>

```julia
  | | |_| | | | (_| | | Version 1.0.3 (2018-12-18)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

[Info: Recompiling stale cache file /home/.julia/compiled/v1.0/OpenStreetMapX/rxMhI.ji for OpenStreetMapX [5c67c38e-c187-11e8-2be6-e3a6a3a5610f]
julia> using Pkg

julia> Pkg.installed()
Dict{String,Union{Nothing, VersionNumber}} with 7 entries:
  "Juno" => v"0.5.3"
  "OpenStreetMapX" => v"0.1.1"
  "IJulia" => v"1.14.1"
  "Plots" => v"0.22.5"
  "Atom" => v"0.7.12"
  "PyCall" => v"1.18.5"
  "OpenStreetMapXPlot" => v"0.1.0"

julia> m = OpenStreetMapX.get_map_data("/home/devel/Desktop/sweden.osm")
ERROR: MethodError: no method matching get_map_data(::String)
Closest candidates are:
  get_map_data(::String, ::String; road_levels, use_cache) at /home/.julia/packages/OpenStreetMapX/lK8gq/src/parseMap.jl:82
Stacktrace:
 [1] top-level scope at none:0

```

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 27, 2019, 6:16pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/15 "2019-02-27T18:16:41Z")

</div>

I’m using Linux Ubuntu.

---

<div class="post-metadata">

**Author:** ![cchderrick](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@cchderrick](https://discourse.julialang.org/u/cchderrick)\
**Post date:** [February 27, 2019, 6:23pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/16 "2019-02-27T18:23:29Z")

</div>

Generally, the error stack provide some good info on the error.

```julia
Closest candidates are:
  get_map_data(::String, ::String; road_levels, use_cache)

```

So it suggesting that it need to take 2 strings as input. And going to the manual:  
[get\_map\_data](https://pszufe.github.io/OpenStreetMapX.jl/stable/reference/#OpenStreetMapX.get_map_data-Tuple%7BString,Union%7BNothing,%20String%7D%7D)

It needs the path and filename in 2 separate strings.

So probably something like this

```julia
m = OpenStreetMapX.get_map_data("/home/devel/Desktop","sweden.osm")

```

---

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [February 27, 2019, 6:27pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/17 "2019-02-27T18:27:04Z")

</div>

What are the programming tools to use to combine them into a movie?

---

<div class="post-metadata">

**Author:** ![pszufe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pszufe/32/23452_2.png) [@pszufe](https://discourse.julialang.org/u/pszufe)\
**Post date:** [February 27, 2019, 7:26pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/18 "2019-02-27T19:26:08Z")

</div>

However, there is one thing that the stack trace does not show this time.

I have registered OpenStreetMapX as an official Julia package. In the registration process I was forced to change package ID to the one assigned in the registration process (package id in the form `d3d4fdd0-c191-11e8-3358-a3629b56487d`). Now I am getting feedback from people who have problem updating OpenStreetMapX.

I propose to remove the package and then install it again (maybe there is a more elegant solution but I do not know it):  
Press `]` to go to the package manager:

```julia

(v1.0) pkg> rm OpenStreetMapXPlot

(v1.0) pkg> rm OpenStreetMapX

(v1.0) pkg> add OpenStreetMapX

(v1.0) pkg> add https://github.com/pszufe/OpenStreetMapXPlot.jl

```

Now you should be able to work with the new API (that contains `get_map_data(::String)` function)

---

<div class="post-metadata">

**Author:** ![pszufe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pszufe/32/23452_2.png) [@pszufe](https://discourse.julialang.org/u/pszufe)\
**Post date:** [February 27, 2019, 7:38pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/19 "2019-02-27T19:38:31Z")

</div>

Regarding the animation follow the steps

1. Use `Plots.jl ` `GR.jl` backend (this is the default in `OpenStreetMapXPlot`) because despite of long compilation time it has very fast rendering
2. `Plots.jl` has the function `savefig()` for rendering output to file ([https://docs.juliaplots.org/latest/output/](https://docs.juliaplots.org/latest/output/))
3. There is lots of software that is able to combine frame images, several years ago I have used ffmpeg and got excellent results (for example see [this StackOverflow post](https://stackoverflow.com/questions/24961127/how-to-create-a-video-from-images-with-ffmpeg))

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 27, 2019, 7:51pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/20 "2019-02-27T19:51:01Z")

</div>

Perhaps you can use `@animate` or `@gif` to create animations more easily? [Documentation here](https://docs.juliaplots.org/latest/animations/), and [example code and resulting animation here](https://discourse.julialang.org/t/julia-slower-in-windows/21027/17).

[Next page](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657.md?page=2)
