I am regularly mapping things in Openstreetmap with my Garmin Nüvi 205 and a second GPS Tracker (iBlue 747a+).
It is very usefull to have a current version of the OSM map on the Garmin device, so that you see what is actually missing in the map when you are in the field.
I used to manually download the map file from http://dev.openstreetmap.de/aio/ and then uncompressing it to the garmin device. But I was getting tired of doing this repetitive task and so I wrote a script for this….
The script can be executed via the device notifier in KDE4 (more infos about device notifier can be found in an older blogpost of mine: Adding actions to the Device Notifier widget in KDE 4.3).
After selecting “Update OSM map on Garmin device” in the device notifier the script downloads the map and shows a progressbar.
When it is finished a pop-up appears and the device can be removed via device notifier.
I have attached the script (update_map.sh) and the device notifier config (update_map.desktop) to this post.
The script needs the package “pv” (pipe viewer). It can be installed in kubuntu with “apt-get install pv“.
update_map.sh (place it in /usr/local/bin)
#!/bin/bash
url=http://dev.openstreetmap.de/aio/germany/gmapsupp.img.bz2
path=$1
target_dir=$path/Garmin
target_file=$target_dir/gmapsupp.imgprogressfile=/tmp/progress_$$
echo 0 > $progressfilefunction watch_progress {
dbusRef=$1
while [ true ]
do
sleep 1
# check if dbus object exists
qdbus $dbusRef 1>/dev/null 2>&1
if [ "$?" -ne "0" ]
then
# dbus Object does not exist (anymore)
exit 0
fi# read current progress
progress=`tail -n1 $progressfile`# set progress to progressbar
qdbus $dbusRef Set “” “value” $progress
done}
if [ ! -d $target_dir ]
then
kdialog –msgbox “$target_dir does not exist!”
exit 1
fikdialog –yesno “Update OSM Map on $target_dir ?”
ret=$?if [ "$ret" -eq "0" ]
then# get file size
size=`curl -sI $url | grep Content-Length | cut -d ‘ ‘ -f 2 | sed “s/[^0-9]//g”`
kbsize=$((size/1024))kdbusRef=`kdialog –progressbar “Downloading OSM Map” 100`
watch_progress “$dbusRef” &wget -qO- $url | pv -s $kbsize -n 2>$progressfile | bunzip2 > $target_file
sync
syncqdbus $dbusRef close
rm -f $progressfileerror=0
#check return codes in pipe
for rc in ${PIPESTATUS[*]}
doif [ "$rc" -ne "0" ]
then
error=1
fi
doneif [ "$error" -ne "0" ]
then
kdialog –msgbox “There was an error updating the map”;
else
kdialog –msgbox “The map was updated successfully – You may now disconnect the device”;
fielse
kdialog –msgbox “cancelled…”
fi
update_map.desktop (place it in e.g. /usr/share/kde4/apps/solid/actions)
[Desktop Entry]
X-KDE-Solid-Predicate=[[ StorageVolume.ignored == false AND StorageVolume.usage == 'FileSystem' ] OR [ IS StorageAccess AND StorageDrive.driveType == 'Floppy' ]]
Type=Service
Actions=open;[Desktop Action open]
Name=Update OSM map on Garmin device
Exec=/usr/local/bin/update_map.sh %f
Icon=system-file-manager
X-Ubuntu-Gettext-Domain=desktop_kdebase-workspace



Posted by neuntoeter 
