1

This is how you can rename all Jpegs in a folder by geolocation and date:

exiftool '-filename<${gpslatitude;} ${gpslongitude} ${datetimeoriginal}' -d "%Y-%m-%d %H.%M.%S%%-c.%%e" *.JPG

this results in very long filenames like

53 33 36.95000000 N 9 58 29.37000000 E 2015-11-04 19.22.49.JPG

How can I use the short locations instead? So it would result in

53.560308 9.975458 2015-11-04 19.22.49.JPG

Or even better, Is it possible to get and add the City of the geolocation and add it to the name?

  • See option -coordFormat in man exiftool: e.g. -coordFormat "%.6f" – ridgy Nov 23 '16 at 13:01
1

This will result in a shorter version:

exiftool -coordFormat '%.4f' '-filename<${gpslatitude;} ${gpslongitude} ${datetimeoriginal}_$filename' -d "%Y-%m-%d_%H.%M.%S%%-c.%%e" *.JPG

But it still adds the compass point N,E,S or W

If you want to add the city, this could be added with a loop, using the nominatim API:

#!/bin/bash
#exiftool '-filename<${datetimeoriginal}_$filename' -d "%Y-%m-%d_%H.%M.%S%%-c.%%e" *.JPG
for f in *.JPG; do
  echo "$f"
  LAT="$(exiftool -coordFormat '%.4f' "$f"|egrep 'Latitude\s+:'|cut -d\  -f 23)"
  if [ "$LAT" == "" ]; then 
    echo 'no geo coordinates';
  else
    LON="$(exiftool -coordFormat '%.4f' "$f"|egrep 'Longitude\s+:'|cut -d\  -f 22)"
    URL='http://nominatim.openstreetmap.org/reverse?format=xml&lat='$LAT'&lon='$LON'&zoom=18&addressdetails=1'
    RES="$(curl -s "$URL"|egrep "<(city|village|town|ruins|state_district|country)")"
    LOC="$(echo "$RES"|grep '<city>'|sed 's/^.*<city>//g'|sed 's/<\/city>.*$//g')"
    if [ "$LOC" == "" ]; then 
      LOC="$(echo "$RES"|grep '<city_district>'|sed 's/^.*<city_district>//g'|sed 's/<\/city_district>.*$//g')"
    fi
    if [ "$LOC" == "" ]; then 
      LOC="$(echo "$RES"|grep '<village>'|sed 's/^.*<village>//g'|sed 's/<\/village>.*$//g')"
    fi
    if [ "$LOC" == "" ]; then 
      LOC="$(echo "$RES"|grep '<town>'|sed 's/^.*<town>//g'|sed 's/<\/town>.*$//g')"
    fi
    if [ "$LOC" == "" ]; then 
      LOC="$(echo "$RES"|grep '<ruins>'|sed 's/^.*<ruins>//g'|sed 's/<\/ruins>.*$//g')"
    fi
    if [ "$LOC" == "" ]; then 
      LOC="$(echo "$RES"|grep '<state_district>'|sed 's/^.*<state_district>//g'|sed 's/<\/state_district>.*$//g')"
    fi
    if [ "$LOC" == "" ]; then 
      LOC="$(echo "$RES"|grep '<country>'|sed 's/^.*<country>//g'|sed 's/<\/country>.*$//g')"
    fi
    if [ "$LOC" == "" ]; then
      echo "no city found at $URL";
    else 
      BASE="${f%.*}"
      mv -v "$f" "$BASE-$LOC.JPG"
    fi
  fi
done

When you are done, you can count your images by location with

ls -1|cut -d- -f 4|sort|uniq -c|sort -n
  • The exiftool manpage says: If the hemisphere is known, a reference direction (N, S, E or W) is appended to each printed coordinate, but adding a "+" to the format specifier (eg. "%+.6f") prints a signed coordinate instead – ridgy Nov 25 '16 at 13:03
  • 1
    Instead of Google maps you may also use the Nominatim API from the OpenStreetMap Project – ridgy Nov 25 '16 at 13:09
  • @ridgy: thanks, I added a solution with Nominatim – rubo77 Nov 26 '16 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.