google maps - Reverse Geocoding in Bash using GPS Position from exiftool -


i writing bash script renames jpg files based on exif tags. original files named this:

img_2110.jpg img_2112.jpg img_2113.jpg img_2114.jpg 

i need rename them this:

2015-06-07_11-21-38_iphone6plus_usa-ca-los_angeles_img_2110.jpg 2015-06-07_11-22-41_iphone6plus_usa-ca-los_angeles_img_2112.jpg 2015-06-13_19-05-10_iphone6plus_morocco-fez_img_2113.jpg 2015-06-13_19-12-55_iphone6plus_morocco-fez_img_2114.jpg 

my bash script uses exiftool parse exif header , rename files. files not contain exif create date, using file modification time.

#!/bin/bash ifs=$'\n'  in *.*;     mod=`stat -f %sm -t %y-%m-%d_%h-%m-%s $i`     model=$( exiftool -f -s3 -"model" "${i}" )     datetime=$( exiftool -f -s3 -"datetimeoriginal" "${i}" )     stamp=${datetime//:/-}"_"${model// /}     echo ${stamp// /_}$i done 

i stuck on location. need determine country , city using gps information exif tag. exiftool provides field called "gps position." of fields, seems useful determine location.

gps position : 40 deg 44' 49.36" n, 73 deg 56' 28.18" w 

google provides public api geolocation, requires latitude/longitude coordinates in format:

40.7470444°, -073.9411611° 

the api returns quite bit of information (click link see results):

https://maps.googleapis.com/maps/api/geocode/json?latlng=40.7470444,-073.9411611

my question is:

  1. how format gps position latitude/longitude value provide acceptable input service such google geolocation?

  2. how parse json results extract country , city, in way consistent many different kinds of locations? curl, , then? ideally, i’d handle usa locations 1 way, , non-usa locations, another. usa locations formatted usa-state-city, whereas non-usa locations formatted country-city.

i need in bash script. i've looked @ pygeocoder , gpsbabel not seem trick. there few free web tools available don't provide api (http://www.earthpoint.us/convert.aspx).

for #1, awk should not complicated:

awk '/gps position/{   lat=$4; lat+=strtonum($6)/60; lat+=strtonum($7)/3600; if($8!="n,")lat=-lat;   lon=$9; lon+=strtonum($11)/60; lon+=strtonum($12)/3600; if($13!="e")lon=-lon;   printf "%.7f %.7f\n",lat,lon   }' 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -