<!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>
proc=subprocess.Popen('exif -mt GPSLatitude '+foto,
shell=True,stdout=subprocess.PIPE)#foto: is the route to a
jpg image from a camera Sony DSC-HX5V<br>
stdout_value = proc.communicate()[0]<br>
da=stdout_value[0:len(stdout_value)-1]<br>
sp=da.split(', ')<br>
lat=float(sp[0].replace(',','.'))+float(sp[1].replace(',','.'))/60+float(sp[2].replace(',','.')[0:5])/3600<br>
print lat<br>
proc2=subprocess.Popen('exif -mt GPSLongitude '+foto,
shell=True,stdout=subprocess.PIPE)<br>
stdout_value = proc2.communicate()[0]<br>
da2=stdout_value[0:len(stdout_value)-1]<br>
sp2=da2.split(', ')<br>
lon=float(sp2[0].replace(',','.'))+float(sp2[1].replace(',','.'))/60+float(sp2[2].replace(',','.')[0:5])/3600<br>
print lon<br>
proc3=subprocess.Popen('exif -mt GPSLongitudeRef '+foto,
shell=True,stdout=subprocess.PIPE)<br>
stdout_value = proc3.communicate()[0]<br>
da3=stdout_value[0:len(stdout_value)-1]<br>
print da3<br>
if da3[0:1]=='W':<br>
lonLat='"-'+str(lon)+' '+str(lat)+'"'<br>
else:<br>
lonLat='"'+str(lon)+' '+str(lat)+'"' <br>
print lonL #in wgs84 <br>
proc4=subprocess.Popen('echo '+lonLat+' | m.proj -i
--quiet', shell=True,stdout=subprocess.PIPE)#GRASS must be
running, in my case eur50 datum.<br>
stdout_value = proc4.communicate()[0]<br>
da4=stdout_value[0:len(stdout_value)-1]<br>
print 'da4'<br>
print da4<br>
pse=da4.split(' ')<br>
XY=pse[0].replace('\t',',')<br>
print 'XY'<br>
print XY<br>
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>
# use jhead to read exif metadata<br>
EXIF=`jhead $FILENAME`<br>
<br>
# awk metadata into variables<br>
LON=`echo "$EXIF" | awk '/Longitude/ {sub(/m/,"'"'"'");
sub(/s/,"\""); print $4$5$6$3}'`<br>
LAT=`echo "$EXIF" | awk '/Latitude/ {sub(/m/,"'"'"'");
sub(/s/,"\""); print $5$6$7$4}'`<br>
ALT=`echo "$EXIF" | awk '/Altitude/ {sub(/m/,""); print $4}'`<br>
DATE=`echo "$EXIF" | awk '/Date\/Time/ {gsub(/\:/,"/");print
$3}'`<br>
TIME=`echo "$EXIF" | awk '/Date\/Time/ {print $4}'`<br>
<br>
# transform to current projection<br>
if [ ${#ALT} -lt 1 ]; then ALT=0; XYZ=42; fi<br>
PROJ=`echo "$LON $LAT $ALT" | m.proj -i`<br>
PROJ_LON=`echo $PROJ | awk 'BEGIN {FS = "|"}{print $1}'`<br>
PROJ_LAT=`echo $PROJ | awk 'BEGIN {FS = "|"}{print $2}'`<br>
if [ ${XYZ:-0} -ne 42 ]; then PROJ_ALT=`echo $PROJ | awk 'BEGIN
{FS = "|"}{print $3}'`; fi<br>
<br>
# output<br>
echo "$FILENAME|$PROJ_LON|$PROJ_LAT|$PROJ_ALT|$DATE $TIME"<br>
done<br>
</body>
</html>