How to extract a smaller geographic region using polygon

Sometimes you want to extract a sub-region of OpenStreetMap region because:
(1) does not have the region that your are interested in,
(2) you are only interested in a smaller region (e.g. is 9 MB instead of 305 MB).
(3) in specialized situation (such as disaster relief effort or special sports event), you want to minimize the size of the offline map to fit as many mobile devices as possible.

Technique: download a larger region, use "polygon" to extract the smaller region of interests. For example, Myanmar is not a sub-region extract of Asia in but you can create your own.

Download asia-latest.osm.pbf from, caution, this is a 4.3 GB download, using wget:


Create a polygon that covers your region of interest   

On a PC
Download and invoke "JOSM - Java OpenStreetMap Editor".
File..New Layer
Imagery...OpenStreetmap...zoom in to the region Myanmar (press RIGHT mouse button to drag/pan)

(1) click "Draw Nodes" in the left-hand side tool bar,
(2) draw nodes that cover Myanmar, you don't need too many points, a rough polygon will do.
Make sure the last node "completes" the polygon, i.e, the last point coincides/overlaps the first point.
(3) Move mouse to the Layers windows/panel, click to select the "Data Layer" (deep blue).
(4) File...Save As....  myanmar.osm
(5) File...Exit...Exit Now (please do not upload your polygon to the OSM world wide database server)


Download a public domain Perl code osm2poly written by Frederik Ramm, save that file as

Use Filezilla to transfer and myanmar.osm to your Ubuntu VM

Invoke VirtualBox, start the VM ubuntu-osmosis, use Filezilla to transfer and myanmar.osm to your Ubuntu VM home directory
cd ~
perl myanmar.osm > myanmar.poly

Extract Myanmar from Asia using the polygon extraction
~/osmosis/bin/osmosis --rb file=asia-latest.oem.pbf --bp file=myanmar.poly --wb file=myanmar.pbf

Convert myanmar.pbf to

~/osmosis/bin/osmosis --rb file=myanmar.pbf --mw 

(the map will show in Burmese, the official language of Myanmar)

If you want the map to show in English whenever possible, add a preferred-languages directive:

~/osmosis/bin/osmosis --rb file=myanmar.pbf --mw preferred-languages=en 
(the map will show in English whenever possible)

For other preferred languages, use ISO 639.2 2-letter-code as the parameter in the preferred-languages directive.

Data Flow:

myanmar.osm  --> myanmar.poly   [conversion using Perl code]

asia-latest.osm.pbf -->  myanmar.pbf  [osmosis region extraction using polygon myanmar.poly]

myanmar.pbf -->  [osmosis conversion from pbf to map format]

© 2016 Nicholas Fong

Last updated: 2016-12-08