<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    On 15/05/2011 6:31 pm, Juan Miguel Garijo wrote:
    <blockquote cite="mid:239677.69358.qm@web26903.mail.ukl.yahoo.com"
      type="cite">
      <style type="text/css"><!-- DIV {margin:0px;} --></style>
      <div style="font-family: times new roman,new york,times,serif;
        font-size: 12pt;">
        <div><span title="Responder al remitente (r)" style=""
            name="btnTbl_compose:reply_to_sender"
            id="btnTbl_compose:reply_to_sender" cellpadding="0"
            class="comboButton colorBTK4 comboButtondown"><span
              id="btnTbl_compose:reply_to_sender_outter"
              class="buttonOutter buttonOutter-menu buttonOutter-menu
              buttonOutterflatRight colorBT1 colorBTK4 buttonOutterdown"
              style="">Hello,<br>
              This is my 'amateur' solution:<br>
              <br>
              def getXYfromFoto(foto):<br>
              &nbsp; proc=subprocess.Popen('exif -mt GPSLatitude '+foto,
              shell=True,stdout=subprocess.PIPE)#foto: is the route to a
              jpg image from a camera Sony&nbsp; DSC-HX5V<br>
              &nbsp; stdout_value = proc.communicate()[0]<br>
              &nbsp; da=stdout_value[0:len(stdout_value)-1]<br>
              &nbsp; sp=da.split(', ')<br>
              &nbsp;
lat=float(sp[0].replace(',','.'))+float(sp[1].replace(',','.'))/60+float(sp[2].replace(',','.')[0:5])/3600<br>
              &nbsp; print lat<br>
              &nbsp; proc2=subprocess.Popen('exif -mt GPSLongitude '+foto,
              shell=True,stdout=subprocess.PIPE)<br>
              &nbsp; stdout_value = proc2.communicate()[0]<br>
              &nbsp; da2=stdout_value[0:len(stdout_value)-1]<br>
              &nbsp; sp2=da2.split(', ')<br>
              &nbsp;
lon=float(sp2[0].replace(',','.'))+float(sp2[1].replace(',','.'))/60+float(sp2[2].replace(',','.')[0:5])/3600<br>
              &nbsp; print lon<br>
              &nbsp; proc3=subprocess.Popen('exif -mt GPSLongitudeRef '+foto,
              shell=True,stdout=subprocess.PIPE)<br>
              &nbsp; stdout_value = proc3.communicate()[0]<br>
              &nbsp; da3=stdout_value[0:len(stdout_value)-1]<br>
              &nbsp; print da3<br>
              &nbsp; if da3[0:1]=='W':<br>
              &nbsp;&nbsp;&nbsp; lonLat='"-'+str(lon)+' '+str(lat)+'"'<br>
              &nbsp; else:<br>
              &nbsp;&nbsp;&nbsp; lonLat='"'+str(lon)+' '+str(lat)+'"' <br>
              &nbsp; print lonL #in wgs84 <br>
              &nbsp; proc4=subprocess.Popen('echo '+lonLat+' | m.proj -i
              --quiet', shell=True,stdout=subprocess.PIPE)#GRASS must be
              running, in my case eur50 datum.<br>
              &nbsp; stdout_value = proc4.communicate()[0]<br>
              &nbsp; da4=stdout_value[0:len(stdout_value)-1]<br>
              &nbsp; print 'da4'<br>
              &nbsp; print da4<br>
              &nbsp; pse=da4.split(' ')<br>
              &nbsp; XY=pse[0].replace('\t',',')<br>
              &nbsp; print 'XY'<br>
              &nbsp; print XY<br>
              &nbsp; return XY# in UTM eu50 30N<br>
              <br>
              hope usefull for you<br>
              Juan M. Garijo<br>
            </span></span></div>
      </div>
    </blockquote>
    Here is the solution I ended up with. It uses `jhead` rather than
    `exiftool` as for the 200 images I have to process I found it to be
    ~2x faster. It means jumping through some extra hoops with awk to
    get the lat/long formatting in a way m.proj will accept and some
    more to get the dates with / instead of :. The output is ready to
    pipe into GRASS using something like:<br>
    <br>
    v.in.ascii in=exif.txt out=photos x=2 y=3 z=4 columns='filename
    varchar(40),x double precision,y double precision, z double
    precision, date varchar(19)'<br>
    <br>
    #!/bin/bash<br>
    <br>
    for FILENAME in "$@"; do<br>
    &nbsp;&nbsp;&nbsp; # use jhead to read exif metadata<br>
    &nbsp;&nbsp;&nbsp; EXIF=`jhead $FILENAME`<br>
    <br>
    &nbsp;&nbsp;&nbsp; # awk metadata into variables<br>
    &nbsp;&nbsp;&nbsp; LON=`echo "$EXIF" | awk '/Longitude/ {sub(/m/,"'"'"'");
    sub(/s/,"\""); print $4$5$6$3}'`<br>
    &nbsp;&nbsp;&nbsp; LAT=`echo "$EXIF" | awk '/Latitude/ {sub(/m/,"'"'"'");
    sub(/s/,"\""); print $5$6$7$4}'`<br>
    &nbsp;&nbsp;&nbsp; ALT=`echo "$EXIF" | awk '/Altitude/ {sub(/m/,""); print $4}'`<br>
    &nbsp;&nbsp;&nbsp; DATE=`echo "$EXIF" | awk '/Date\/Time/ {gsub(/\:/,"/");print
    $3}'`<br>
    &nbsp;&nbsp;&nbsp; TIME=`echo "$EXIF" | awk '/Date\/Time/ {print $4}'`<br>
    &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; # transform to current projection<br>
    &nbsp;&nbsp;&nbsp; if [ ${#ALT} -lt 1 ]; then ALT=0; XYZ=42; fi<br>
    &nbsp;&nbsp;&nbsp; PROJ=`echo "$LON $LAT $ALT" | m.proj -i`<br>
    &nbsp;&nbsp;&nbsp; PROJ_LON=`echo $PROJ | awk 'BEGIN {FS = "|"}{print $1}'`<br>
    &nbsp;&nbsp;&nbsp; PROJ_LAT=`echo $PROJ | awk 'BEGIN {FS = "|"}{print $2}'`<br>
    &nbsp;&nbsp;&nbsp; if [ ${XYZ:-0} -ne 42 ]; then PROJ_ALT=`echo $PROJ | awk 'BEGIN
    {FS = "|"}{print $3}'`; fi<br>
    <br>
    &nbsp;&nbsp;&nbsp; # output<br>
    &nbsp;&nbsp;&nbsp; echo "$FILENAME|$PROJ_LON|$PROJ_LAT|$PROJ_ALT|$DATE $TIME"<br>
    done<br>
  </body>
</html>