Skip to content

How to obtain map data for application use

Jan Kasik edited this page Feb 28, 2017 · 1 revision

Prerequisites

Let's do it!

  1. Use ogr2osm to convert source shapefile to OSM format. I also supplied custom hooks containing conversion rules with -t option. It can be found in MapDataTools repository.

    ./ogr2osm.py ne_50m_admin_0_countries.shp -o ogr2osm_ocean_translated.osm -t admin_countries.py
    
  2. We now have OSM file. The problem is, that the nodes are not "sorted" as Mapsforge plugin for Osmosis expects. The solution is to set "neutral" values to attributes where sorting is expected. We can use xapi_attrs.py script for this, which can be found in MapDataTools repository.

    ./xapi_attr.py ogr2osm_admin_translated.osm .
    
  3. In this step we can cut the map area to contain only Europe using Osmconvert tool with -b option supplying Europe's bounding box:

    osmconvert --complete-ways --drop-broken-refs -b=-31.266,27.636,39.869,81.009 ogr2osm_admin_translated_attr.osm -o=europe.osm
    
  4. Finally, we can convert OSM file to binary file requested by Mapsforge library using Mapsforge plugin for Osmosis:

    ~/apps/osmosis-latest/bin/osmosis --rx file=europe.osm --mw file=europe.map zoom-interval-conf=5,0,7
    

    If we would omit attribute conversion using custom hooks, final .map file would be empty because Mapsforge plugin won't recognize tags in this file.

Clone this wiki locally