Skip to content

Instantly share code, notes, and snippets.

@aleung
Last active September 1, 2020 05:36
Show Gist options
  • Save aleung/42776348d023b689e8c337b82a3c7cd5 to your computer and use it in GitHub Desktop.
Save aleung/42776348d023b689e8c337b82a3c7cd5 to your computer and use it in GitHub Desktop.
Generate latest offline map for OsmAnd

Install

Download OsmAndMapCreator and extract.

Install osmupdate and osmconvert into path.

cd ~/bin
wget -O - http://m.m.i24.cc/osmupdate.c | cc -x c - -o osmupdate 
wget -O - http://m.m.i24.cc/osmconvert.c | cc -x c - -lz -O3 -o osmconvert

Download full map data for the first time

Download dump of China area PBF file from http://download.geofabrik.de/asia/china-latest.osm.pbf

Create map

Put PBF file and files in this gist into working directory.

Run createmap.sh. It does these steps:

  1. Download latest patch to make map data up to date.
  2. Generate OBF map file used by OsmAnd.

Generating full China map takes 90 minutes and output OBF file is 845M. Current script uses -b parameter to filter out middle Guangdong area to reduce time.

To automatically run everyday, add a cron job:

0 13 * * 1-5 cd /home/me/workspaces/osm-mapbuild; ./update_and_create_guangdong.sh > guangdong.log 2>&1

Copy OBF file to Android

adb push obf/Guangdong_2.obf /sdcard/Android/data/net.osmand/files/
<?xml version="1.0" encoding="utf-8"?>
<batch_process>
<process_attributes mapZooms="" renderingTypesFile="" zoomWaySmoothness=""
osmDbDialect="sqlite" mapDbDialect="sqlite"/>
<!-- There are 3 subprocess :
1. Download fresh osm files from servers to 'directory_for_osm_files' (override existings).
2. Generate index files from all files in 'directory_for_osm_files' and put all indexes into 'directory_for_index_files'
3. Upload index files from 'directory_for_index_files' to googlecode.
If directory directory_for_uploaded_files is specified all uploaded files will be moved to it
All these subprocess could be ran independently ! So you can create some files check them and after that try to upload on googlecode,
or you can upload any file you have to googlecode (just put into 'directory_for_index_files')
-->
<!-- zoomWaySmoothness - 1-4, typical mapZooms - 11;12;13-14;15- -->
<process
directory_for_osm_files="osm/guangdong"
directory_for_index_files="obf"
directory_for_generation="tmp"
directory_for_srtm_files="srtm"
indexPOI="true"
indexRouting="true"
indexMap="true"
indexTransport="false"
indexAddress="false">
<!-- Add wget="C:/Program Files/GNUWin32/bin/wget.exe" to process, to use wget for download.
On linux systems if wget is in your path it can be wget="wget" or you can make own script with wget command:
wget="/path/to/script/wget.sh"
Defaultly enabled parameter of wget is: &-&-read-timeout=5 that prevents hanging of download from cloudmade/geofabrik server
-->
</process>
</batch_process>
#!/bin/bash
set -e
export LC_ALL=en_US.UTF-8
export JAVA_OPTS="-Xms4G -Xmx8G"
osm_file_china=osm/china/china-latest.osm.pbf
osm_file=osm/guangdong/guangdong.osm.pbf
mkdir -p osm/china
mkdir -p osm/guangdong
if [ ! -f $osm_file_china ]; then
curl -Ss http://download.geofabrik.de/asia/china-latest.osm.pbf > $osm_file_china
fi
osmupdate --base-url=http://download.geofabrik.de/asia/china-updates/ $osm_file_china updated-$osm_file_china || true
mv updated-$osm_file_china $osm_file_china || true
# Crop centra Guangdong: -b=111,21,115,25 (-b="x1,y1,x2,y2")
osmconvert $osm_file_china -b=111,21,115,25 --out-pbf -o=$osm_file
osmconvert $osm_file --out-statistics
~/apps/OsmAndMapCreator/utilities.sh generate-obf-files-in-batch guangdong.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment