Images with GPS tags - Nautilus integration 1/2

I just bought a new Sony Camera with build-in GPS. Unfortunately all the packaged software is for Windows only.
So I was looking for a good Linux program to quickly show the GPS data of a picture and to show the GPS position in Google maps.
Digikam has a good GPS support (integration of marble) and its good to manage many images.
You can even choose multiple images and show them on the map, or select a region on the map to search for pictures.

screenshot-digikam

But if you just want to show the GPS postition of a single image quickly, digikam is to heavyweight.
Many small tools can show the exif metadata of a picture, but the plain GPS coordinates are not very helpful to find out where a picture has been taken.

For this reason I have created a set of small scripts which do the following
1) Extract the GPS coordinates and get the name of the nearest place/city/village (thanks to geonames.org)
2) Open the GPS coordinates in Google Maps
3) Show the GPS coordinates of up to 10 pictures in a Google static map

The main script (gpsPlacenames.sh) provides the core functions and can be used on the shell.
The two helper scripts (nautilus-gps-link.sh, nautilus-gps-place.sh) are used for integrating it into nautilus and providing X window dialogs using zentity.

gpsPlacenames.sh
WARNING: wordpress adds additional single quotes (”) to each single quote when saving this article, please replace duplicate ”””” with a single instance
#!/bin/sh
#
# Script for extracting GPS tags from jpeg images and showing the names of the nearest place/city.
# Added some funtions to print out Google maps URLs
# author blog@dietzm.de
#
verbose=0
if [ "$1" == "-v" ];then
echo verbose enabled
verbose=1
shift
fi
if [ "$1" == "-vv" ];then
echo verbose with google maps link enabled
verbose=2
shift
fi
if [ -z "$1" ] ; then
echo Wrong usage !
echo This script extracts the GPS coordinates from exif tags of a jpeg image and shows the name of the nearest place/city/village
echo Usage: $0 [-v verbose | -vv verbose with google maps link] file….
echo —-
exit 1
fi
staticurl=”http://maps.google.com/maps/api/staticmap?size=640×640&sensor=false&maptype=hybrid”
dynurl=”http://maps.google.de/maps”
cache=/tmp/gpscache/
mkdir $cache &>/dev/null
nr=0
IFS=$””n””
echo # Reading file metadata …..
allcoord=`exiftool -q -fast -c %.6f -p ””lat=$gps:GPSLatitude&lng=$gps:GPSLongitude $gps:GPSLatitudeRef $gps:GPSLongitudeRef $directory/$filename”” “$@” 2>&1`
echo # Looking up place names (thanks to http://ws.geonames.org/)
echo ————————
for coord in $allcoord ;
do
#echo “# $coord”
# coord=`exiftool -c %.6f -p ””lat=$gps:GPSLatitude&lng=$gps:GPSLongitude $gps:GPSLatitudeRef $gps:GPSLongitudeRef”” “$i” 2>/dev/null`
hasgpsdata=`echo $coord | grep -v “Warning”`
if [ -z "$hasgpsdata" ]; then
# #zenity –error –text “exiftool command failed: $i ($?)”
fname=`echo $coord | cut -d ”” ”” -f 8-`
echo # “$fname -> NO GPS DATA”
continue
fi
i=`echo $coord | cut -d ”” ”” -f 4- | sed s#^./##g`
# echo $coord
ref=`echo $coord | cut -d ”” ”” -f 2`
if [ "$ref" != "North" ];then
coord=`echo $coord | sed s/lat=/lat=-/g`
fi
ref=`echo $coord | cut -d ”” ”” -f 3`
if [ "$ref" != "East" ];then
coord=`echo $coord | sed s/lng=/lng=-/g`
fi
coord=`echo $coord | cut -d ”” ”” -f 1`
cfile=`echo $cache$coord | sed s/&//g`
if [ -f $cfile ];then
used_cache=”C”
else
used_cache=”"
# echo wget http://ws.geonames.org/findNearbyPlaceName –post-data “$coord” –output-document=gpsname.txt
wget http://ws.geonames.org/findNearbyPlaceName –post-data “$coord” –output-document=”$cfile” &> /dev/null
fi
#Print out data
if [ "$verbose" != "0" ];then
cat $cfile | cut -d ””>”” -f 2 | cut -d ””<'''' -f 1 | xargs echo # "$i $used_cache-> ”
if [ "$verbose" == "2" ];then
mapscoord=`echo $coord | sed s/&lng=/,/g | sed s/lat=//g`
echo ” Google Maps link (dynamicmap) -> $dynurl?q=$mapscoord%28$i%29″
if [ $nr -lt 10 ];then
#limit number of marker points to 10
staticurl=$staticurl”&markers=color%3Ablue%7Clabel%3A$nr%7C$mapscoord”
let nr=$nr+1
fi
fi
else
cat $cfile |grep toponymName | cut -d ””>”” -f 2 | cut -d ””<'''' -f 1 | xargs echo # "$i ->”
fi
done
if [ "$verbose" == "2" -a "$nr" -ne "0" ];then
echo ————————
echo Static Google Maps URL with the first 10 images as markers:
echo “Link -> $staticurl”
fi
echo # Done

For the command line version (gpsPlacenames.sh) you just need exiftool (and standard tools like wget,grep,cut,..)
gpsPlacenames.sh, here we go:
#> gpsPlacenames.sh DSC018*
# Reading file metadata .....
# Looking up place names (thanks to http://ws.geonames.org/)
------------------------
# DSC01839.JPG -> NO GPS DATA
# DSC01840.JPG -> NO GPS DATA
# DSC01813.JPG -> Zeppelinheim
# DSC01814.JPG -> Zeppelinheim
# DSC01815.JPG -> Zeppelinheim
# DSC01825.JPG -> Pozo Negro
# DSC01831.JPG -> Pozo Negro
# DSC01835.JPG -> Pozo Negro
# DSC01836.JPG -> Pozo Negro
# DSC01843.JPG -> Costa Calma

gpsPlacenames.sh -v verbose will display additional information
#> gpsPlacenames.sh -v DSC018*
verbose enabled
# Reading file metadata .....
# Looking up place names (thanks to http://ws.geonames.org/)
------------------------
# DSC01838.JPG -> NO GPS DATA
# DSC01839.JPG -> NO GPS DATA
# DSC01840.JPG -> NO GPS DATA
# DSC01813.JPG C-> Zeppelinheim Zeppelinheim 50.03333 8.61667 2804754 DE Germany P PPL 2.53043
# DSC01814.JPG C-> Zeppelinheim Zeppelinheim 50.03333 8.61667 2804754 DE Germany P PPL 2.53043
# DSC01815.JPG C-> Zeppelinheim Zeppelinheim 50.03333 8.61667 2804754 DE Germany P PPL 2.53043
# DSC01825.JPG C-> Pozo Negro Pozo Negro 28.31667 -13.88333 2512315 ES Spain P PPL 6.06183
# DSC01831.JPG C-> Pozo Negro Pozo Negro 28.31667 -13.88333 2512315 ES Spain P PPL 6.06183
# DSC01833.JPG C-> Pozo Negro Pozo Negro 28.31667 -13.88333 2512315 ES Spain P PPL 6.06183
# DSC01841.JPG C-> Costa Calma Costa Calma 28.16155 -14.22691 6544327 ES Spain P PPL 0.20955

gpsPlacenames.sh -vv verbose with Google maps support will display additional information and links Google maps.
It will print out a link to the dynamic Google maps version for each image and a combined link with the first 10 images to a static google map at the end.
#> gpsPlacenames.sh -vv DSC018*
verbose with google maps link enabled
# Reading file metadata .....
# Looking up place names (thanks to http://ws.geonames.org/)
------------------------
# DSC01807.JPG -> NO GPS DATA
# DSC01840.JPG -> NO GPS DATA
# DSC01813.JPG C-> Zeppelinheim Zeppelinheim 50.03333 8.61667 2804754 DE Germany P PPL 2.53043
Google Maps link (dynamicmap) -> http://maps.google.de/maps?q=50.049895,8.592363%28DSC01813.JPG%29
# DSC01814.JPG C-> Zeppelinheim Zeppelinheim 50.03333 8.61667 2804754 DE Germany P PPL 2.53043
Google Maps link (dynamicmap) -> http://maps.google.de/maps?q=50.049895,8.592363%28DSC01814.JPG%29
# DSC01825.JPG C-> Pozo Negro Pozo Negro 28.31667 -13.88333 2512315 ES Spain P PPL 6.06183
Google Maps link (dynamicmap) -> http://maps.google.de/maps?q=28.322073,-13.944958%28DSC01825.JPG%29
# DSC01826.JPG C-> Pozo Negro Pozo Negro 28.31667 -13.88333 2512315 ES Spain P PPL 6.06183
------------------------
Static Google Maps URL with the first 10 images as markers:
Link -> http://maps.google.com/maps/api/staticmap?size=640x640&sensor=false&maptype=hybrid&markers=color%3Ablue%7Clabel%3A0%7C50.049895,8.592363&markers=color%3Ablue%7Clabel%3A1%7C50.049895,8.592363&markers=color%3Ablue%7Clabel%3A2%7C50.049895,8.592363&markers=color%3Ablue%7Clabel%3A3%7C50.049895,8.592363&markers=color%3Ablue%7Clabel%3A4%7C50.049895,8.592363&markers=color%3Ablue%7Clabel%3A5%7C28.322073,-13.944958&markers=color%3Ablue%7Clabel%3A6%7C28.322073,-13.944958&markers=color%3Ablue%7Clabel%3A7%7C28.322073,-13.944958&markers=color%3Ablue%7Clabel%3A8%7C28.322073,-13.944958&markers=color%3Ablue%7Clabel%3A9%7C28.322073,-13.944958
# Done

Now, you can easily get the GPS place names for all you images on the command line and use the printed links to jump directly to the GPS coordinates in google maps .
Cool huuh ?

Kommentarfunktion ist deaktiviert