# Simulate the transportation on the map using Julia

**URL:** <https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [January 12, 2019, 5:31pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564 "2019-01-12T17:31:57Z")\
**Posts on this page:** 17\
**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:** [January 12, 2019, 5:31pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/1 "2019-01-12T17:31:57Z")

</div>

I’m doing a project, part of which requires to simulate the transportation on the map of a certain area. After searching from the internet, I found the following two links related to map data simulation/visualisation.

> [@Package for map visualizations?](https://discourse.julialang.org/t/package-for-map-visualizations/1875):
>
> Is there a Julia package with resources for plotting map visualizations - something similar to R’s ggmap, perhaps? I’ve scanned through the Gadfly and Plots documentation and [pkg.julialang.org](http://pkg.julialang.org) and didn’t see anything obvious. I’m interested in making visualizations similar to this: [http://i.imgur.com/Tub0BMD.jpg](http://i.imgur.com/Tub0BMD.jpg)

> [@Plotting data on a map in Julia](https://discourse.julialang.org/t/plotting-data-on-a-map-in-julia/4655):
>
> Is there any way to plot data with latitude/longitude on a map in Julia? I am used to folium in Python and ggmap in R: [https://github.com/python-visualization/folium](https://github.com/python-visualization/folium)[https://github.com/dkahle/ggmap](https://github.com/dkahle/ggmap) but I am trying to eliminate my dependencies on other languages as much as I can.

I was wondering, are there useful updates as it’s already 2019. The other option is to write the code using Python and then execute these code using Julia. I, of course, really enjoy Julia and would like to see if it’s possible to do everything in Julia. Any comments are greatly appreciated.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 12, 2019, 5:33pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/2 "2019-01-12T17:33:06Z")

</div>

The title of this post doesn’t seem to correspond with the question. Are they related?

---

<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:** [January 14, 2019, 11:09am UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/3 "2019-01-14T11:09:14Z")

</div>

I have updated it.

---

<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:** [January 14, 2019, 11:15am UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/4 "2019-01-14T11:15:49Z")

</div>

If you are using OpenStreetMap then you might consider [https://github.com/pszufe/OpenStreetMapX.jl](https://github.com/pszufe/OpenStreetMapX.jl) + [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). In particular they were designed to support visualization of agent-based simulations on maps. There is a scheduled presentation of these packages on Jan 17, 19 @ Fields Institure by @pszufe if you would have a chance to participate, see [here](http://www.fields.utoronto.ca/talks/Smart-cities-agent-based-simulations-spatial-transportation-systems) for the details.

---

<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:** [January 15, 2019, 11:17am UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/5 "2019-01-15T11:17:55Z")

</div>

Thanks, bkamins. your suggestions are very helpful. I’m checking on those two packages. Probably can not go for the presentation though.

---

<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:** [January 15, 2019, 7:04pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/6 "2019-01-15T19:04:51Z")

</div>

I tried the two packages. They work really well. The only thing is, it takes a huge long time to run. I think it’s because of the huge size of the input Open Street Map (.osm) file, which is like 1.5 GB. (“crying…”) Is there a better way?

---

<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:** [January 15, 2019, 8:41pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/7 "2019-01-15T20:41:51Z")

</div>

@bsnyh use the OSMFilter ([Osmfilter - OpenStreetMap Wiki](https://wiki.openstreetmap.org/wiki/Osmfilter)) utility to filter out unnecessary information from the .osm file (there is really lot to filter out like contributor name or not-road-related data).

Moreover, note the loading time is long only for the first time. With the default settings the OpenStreetMapX creates a \*.osm.cache file that keeps a copy of the Julia object representing the map (using the serialization mechanism).

This library is currently under further development and you are welcome to comment/propose features.

---

<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:** [January 15, 2019, 8:50pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/8 "2019-01-15T20:50:24Z")

</div>

Thank you. I will definitely contribute if time allows.

---

<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:** [January 17, 2019, 9:49pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/9 "2019-01-17T21:49:42Z")

</div>

![Screenshot%20from%202019-01-17%2022-37-22](https://global.discourse-cdn.com/julialang/original/3X/4/c/4cd9c64c084a3de36653092d7bac03feaa002db3.jpeg)  
I’m not sure this is what I need. Sigh. Can anyone help me? Is this because of the format of the .osm file ?

---

<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:** [January 19, 2019, 2:34am UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/10 "2019-01-19T02:34:28Z")

</div>

Hi @bsnyh,  
it would always be easier to help when you provide the source code.  
However, most likely, you have either:

- accidentally filtered out road information from your \*.osm data
- use white color for plotting roads

If you post the code and provide a link to some (perhaps smaller) file I can help you.

---

<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:** [January 19, 2019, 4:29pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/11 "2019-01-19T16:29:48Z")

</div>

@pszufe, thank you so much for your help. I plan to do some animations in the above generated image, like the movement of a car etc, and maybe show some nodes/points of interest, and show the selected route. Do you have good recommendations? I did not do much with the code. Just plug in the input file and call two functions. will paste the code here soon.

---

<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:** [January 19, 2019, 4:37pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/12 "2019-01-19T16:37:29Z")

</div>

> using OpenStreetMapX  
> using OpenStreetMapXPlot
> 
> map\_data = OpenStreetMapX.get\_map\_data(“/home/devel/Desktop”, “v.osm”)  
> OpenStreetMapXPlot.plotmap(map\_data.nodes, OpenStreetMapX.ENU(map\_data.bounds), roadways=map\_data.roadways, roadwayStyle=OpenStreetMapXPlot.LAYER\_STANDARD, width=3000, height=3000)

---

<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:** [January 19, 2019, 4:50pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/14 "2019-01-19T16:50:03Z")

</div>

not sure how to pass part of the .osm file to you. Could you kindly let me know?

---

<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:** [January 19, 2019, 7:15pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/15 "2019-01-19T19:15:12Z")

</div>

Regarding the animations on maps there are two options:

- use animations API from `Plots.jl` [Animations · Plots](https://docs.juliaplots.org/latest/animations/)
- use OpenStreetMapX to process data required for animations (nodes, lattitudes, longitutdes) and use a seperate library such as leafletjs for vizualization. The problem is that `LeafletJS.jl` seems to be unmaintaned. However leafletjs works like a charm from R and there is no problem with working with the OpenStreetMap nodedis

The second approach could be more robust but seems to require development export.

Note on sharing the OSM file: go to [https://www.openstreetmap.org/](https://www.openstreetmap.org/) , click “Manually select the different area” and now on the “Overpass API” link right click and select “Copy link location”. Another option is just uploading the OSM file somewhere (e.g. to GitHub pages).

---

<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:** [January 19, 2019, 8:09pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/16 "2019-01-19T20:09:54Z")

</div>

@pszufe, thank you so much. Please see the following link for the .osm file. [part of the .osm file · Issue #1 · bsnyh/osm · GitHub](https://github.com/bsnyh/osm/issues/1) test.osm. I have tried to convert / delete some not useful information from the original .osm file.  
test.zip is the zip version of a part of the .osm file I got finally after conversion. Thank you again. If you know a good way to get only the road-related information from the file, please let me know.

---

<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:** [January 20, 2019, 1:32pm UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/17 "2019-01-20T13:32:50Z")

</div>

@pszufe, I’m very eager to learn. 😉

---

<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:** [January 21, 2019, 12:49am UTC](https://discourse.julialang.org/t/simulate-the-transportation-on-the-map-using-julia/19564/18 "2019-01-21T00:49:49Z")

</div>

Your `test.osm` file is not readable (the contents seems to be corrupted)

You should test your `osmfilter` command on some smaller files and find a set of parameters that work. Check the filtered output files on some external software such [JOSM](https://josm.openstreetmap.de/) (your `osm` file cannot be opened by JOSM).

Here is a sample osmfilter command:  
`osmfilter mymap.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" -o=mymap.osm`

Once you find a set of `osmfileter` parameters that seems perfect for routing (for your case) - paste it here so others can see it.

Last, but not least - it would be better if you could describe a set of repeatable steps (starting from the export link described by my previous post) rather than using your own files. It seems that there might be problems that your data does not conform to the OSM standard and it is not a Julia-related issue (and probably might need a discussion on OSM forum).
