Skip to content

Instantly share code, notes, and snippets.

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


Download OsmAndMapCreator and extract.

Install osmupdate and osmconvert into path.

cd ~/bin
wget -O - | cc -x c - -o osmupdate 
wget -O - | cc -x c - -lz -O3 -o osmconvert

Download full map data for the first time

Download dump of China area PBF file from

Create map

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

Run 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; ./ > 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"?>
<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- -->
<!-- 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:
Defaultly enabled parameter of wget is: &-&-read-timeout=5 that prevents hanging of download from cloudmade/geofabrik server
set -e
export LC_ALL=en_US.UTF-8
export JAVA_OPTS="-Xms4G -Xmx8G"
mkdir -p osm/china
mkdir -p osm/guangdong
if [ ! -f $osm_file_china ]; then
curl -Ss > $osm_file_china
osmupdate --base-url= $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/ 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