# 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:** 15\
**Page:** 2

<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, 10:11pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/21 "2019-02-27T22:11:19Z")

</div>

@pszufe, @bennedich, if I’d like to know the position / location of the vehicles on the road map at any given time point, then how to proceed? I figured this might have something to do with the shape of the road for a precise prediction. But if it’s a straight line, then linear interpolation should work, right? Or do you have any suggestions?

---

<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, 10:24pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/22 "2019-02-27T22:24:43Z")

</div>

you have travel speeds depending on road class and road fragments are straight lines.  
So yes interpolation seems OK (unless you want to model queues etc but than it is far more complicated)

---

<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 28, 2019, 7:49am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/23 "2019-02-28T07:49:27Z")

</div>

@pszufe, a few questions:  
(1): without this linear interpolation, is there some other ways to do it?  
(2): travel speeds, and road class can be obtained from the osm data, right?  
(3): what is “unless you want to model queues etc but than it is far more complicated”? What do you mean  
by “queue” here? Is it the traffic queue?

---

<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 28, 2019, 9:14am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/24 "2019-02-28T09:14:24Z")

</div>

Ad. 1. and Ad.3. You definitely need to do the literature review part of you project - here is a good start [https://www.informs-sim.org/wsc17papers/includes/files/052.pdf](https://www.informs-sim.org/wsc17papers/includes/files/052.pdf)  
Ad.2. Road class - osm data, travel speeds - have a look at speeds.jl file

---

<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 28, 2019, 5:11pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/25 "2019-02-28T17:11:16Z")

</div>

@pszufe, does the travel speeds change overtime? what’s the idea? Where shall I find documentations?

---

<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 28, 2019, 5:19pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/26 "2019-02-28T17:19:27Z")

</div>

It’s up to you how you model it.  
We are working on an extension where travel speeds changes in reaction to traffic volumes.  
Int the end it is a weighted LightGraphs.jl graph and you can have whatever weights you need

---

<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 28, 2019, 5:23pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/27 "2019-02-28T17:23:01Z")

</div>

Is OpenStreetMapXSim part of your traffic modelling work?

---

<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 28, 2019, 6:09pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/28 "2019-02-28T18:09:57Z")

</div>

yes but it will be rewritten - you will not be able to use it at its current form

---

<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:** [April 14, 2019, 3:58pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/29 "2019-04-14T15:58:44Z")

</div>

@pszufe, hey, I have an issue here about the .osm file and I hope you can share with me some ideas. The .osm file I got is still big (like 668MB ) after performing the commands recommended from you. I finally tried to draw the map, and a route. It takes a rather long time to draw it. I was wondering, is there anyway to crop the map data (the .osm file) based on the range of the latitude and longitude (I suppose I can get the corresponding ranges from the real data) I have? Looking forward to your reply!

---

<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:** [April 14, 2019, 4:28pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/30 "2019-04-14T16:28:36Z")

</div>

I just found this link: [How do I export map of large area in .osm format? - OSM Help](https://help.openstreetmap.org/questions/4791/how-do-i-export-map-of-large-area-in-osm-format). So I thought ( `osmosis --rx file="bla.osm" --bbox left=##.## right=##.## top=##.## bottom=##.## --wx file="extracted_city.osm"` , where the numeric values are the lat and lon of a bounding box) would solve the above issue I mentioned. but I’m not 100% sure about which latitude and longitude formats are used here. Will dig more about it.

---

<div class="post-metadata">

**Author:** ![ImreSamu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/imresamu/32/20677_2.png) [@ImreSamu](https://discourse.julialang.org/u/ImreSamu)\
**Post date:** [April 14, 2019, 10:05pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/31 "2019-04-14T22:05:22Z")

</div>

> [@bsnyh](#):
>
> I was wondering, is there anyway to crop the map data (the .osm file) based on the range of the latitude and longitude

my2c:

I prefer the `osmium` tool for preprocessing big osm files.

- [Osmium Tool - osmcode](https://osmcode.org/osmium-tool/)

see `osmium-extract` - for creating geographical extracts from an OSM file`

- [Osmium manual pages – osmium-extract (1)](https://docs.osmcode.org/osmium/latest/osmium-extract.html)

in the example : _Extract the city of Munich using a bounding box:_

```julia
osmium extract -b 11.35,48.05,11.73,48.25 germany-latest.osm.pbf \
    -o munich.osm.pbf

```

---

<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:** [April 15, 2019, 5:58am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/32 "2019-04-15T05:58:09Z")

</div>

about the parameters `11.35, 48.05, 11.73, 48.25,` , what are these exactly?

---

<div class="post-metadata">

**Author:** ![ImreSamu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/imresamu/32/20677_2.png) [@ImreSamu](https://discourse.julialang.org/u/ImreSamu)\
**Post date:** [April 15, 2019, 8:06am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/33 "2019-04-15T08:06:15Z")

</div>

GPS coordinates - A bounding box.

in the doc: [Osmium manual pages – osmium-extract (1)](https://docs.osmcode.org/osmium/latest/osmium-extract.html)  
this part is relelvant for you:

`osmium extract --bbox LEFT,BOTTOM,RIGHT,TOP [OPTIONS] OSM-FILE`

and:

`OPTIONS -b, --bbox=LONG1,LAT1,LONG2,LAT2 Set the bounding box to cut out. Can not be used with --polygon/-p, --config/-c, or --directory/-d. The coordinates LONG1,LAT1 are from one arbitrary corner, the coordinates LONG2,LAT2 are from the opposite corner.`

so the `11.35, 48.05, 11.73, 48.25` coordinates - real meaning  
: LONG1,LAT1,LONG2,LAT2  
: and this area :

> **[geojson.io | powered by Mapbox](http://geojson.io/#id=gist:ImreSamu/0e92e8be644724ba65028ec296d3fd7b&amp;map=11/48.1501/11.5400)**
>
> A quick, simple tool for creating, viewing, and sharing spatial data.

see more:

- [Bounding Box - OpenStreetMap Wiki](https://wiki.openstreetmap.org/wiki/Bounding_Box)

---

<div class="post-metadata">

**Author:** ![ImreSamu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/imresamu/32/20677_2.png) [@ImreSamu](https://discourse.julialang.org/u/ImreSamu)\
**Post date:** [April 15, 2019, 8:39am UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/34 "2019-04-15T08:39:37Z")

</div>

You can generate BBOX with many online tools:

One example:

- go [http://geojson.io](http://geojson.io)
- Draw a rectangle ( around the city )
- call the menu : **“Meta”/“Add bboxes”**
- on the GeoJSON part: you will find the “bbox” coordinates.

like this ( Roma/Italy)

```julia
       "bbox": [
          12.368545532226562,
          41.794864268833145,
          12.623291015625,
          41.99011884096809
        ]

```

---

<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:** [April 28, 2019, 2:09pm UTC](https://discourse.julialang.org/t/whats-the-general-algorithm-to-draw-a-road-network-of-a-certain-area/20657/35 "2019-04-28T14:09:32Z")

</div>

I needed a more flexible visualization for my current project and found out that _folium_ via PyCall works just great with Julia Jupyter notebooks.  
Since there are always many Python-Julia integration issues I wrote a simple quick-start tutorial. I am quite happy with the result and believe many people observing this thread will find it very useful (the link link should be visited with Firefox):  
[https://pszufe.github.io/OpenStreetMapX\_Tutorial/](https://pszufe.github.io/OpenStreetMapX_Tutorial/).

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