Skip navigation.

Displaying iPhone Photographs in Quantum GIS

I have been playing with the Quantum GIS software and using it to record some botanical field information I have been collecting.  After I had played around with the PHP scripts on this page:  http://www.bdug.org.au/node/193  I thought it would be interesting to see a visual representation of where the photos had been taken, much like people had done in Google Earth etc.  I could also use it to see what photographs I had taken with the iPhone out on my survey site.  

I used this PHP script to extract the required data from each years worth of photographs:

<code>

<?php
function getGps($exifCoord, $hemi) {
//  function code from:  http://stackoverflow.com/questions/2526304/php-extract-gps-exif-data
    $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
    $minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
    $seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
    $flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
    return $flip * ($degrees + $minutes / 60 + $seconds / 3600);
}

function gps2Num($coordPart) {
//  function code from:  http://stackoverflow.com/questions/2526304/php-extract-gps-exif-data
    $parts = explode('/', $coordPart);
    if (count($parts) <= 0)
        return 0;
    if (count($parts) == 1)
        return $parts[0];
    return floatval($parts[0]) / floatval($parts[1]);
}

// initialise recursive directory iteration.  You will need to edit this line to suite your photo store folder    
$dir = new RecursiveDirectoryIterator("/parkview/pictures/2012/");
// You will need to edit the next line with where you would like the iPhone photograph metadata file to be placed.
$FILE="/home/parkview/iphone-jpgfile-2012.txt";
$DEL=";";  // CSV file delimiter.  I rarely use a semicolon in my file names
$i=0;

// write out DATA header
$DATA="Date".$DEL."FileName".$DEL."Phone Type".$DEL."Latitude".$DEL."Longitude";
file_put_contents($FILE,$DATA."\n",FILE_APPEND);

foreach(new RecursiveIteratorIterator($dir) as $file) {
  // find photo files and extract EXIF information   
  if (preg_match('/(.jpg|.jpeg|.tif|.tiff)$/i', $file->getFilename())) {
    $exif = exif_read_data($file->getPathname());
    if ((preg_match('/(EXIF|IFD0)/', $exif['SectionsFound'])) && (preg_match('/iPhone/', $exif['Model']))) {
            $DATA=date('Y-M-d H:i', $exif['FileDateTime']);
            $DATA.="$DEL".$exif['FileName'];
            $DATA.="$DEL".realpath($file->getPathname());
            $DATA.="$DEL".substr_replace($exif['Model'],'',0,7);
              //  code from:  http://stackoverflow.com/questions/2526304/php-extract-gps-exif-data
            $DATA.="$DEL".getGps($exif["GPSLongitude"], $exif['GPSLongitudeRef']);
            $DATA.="$DEL".getGps($exif["GPSLatitude"], $exif['GPSLatitudeRef']);
            // now write out the record to the file
            echo $DATA."\n";
            file_put_contents($FILE,$DATA."\n",FILE_APPEND);
            $i++;
    }
  }
}
print("Total number of iPhone jpeg images: ".$i."\n");
?>

</code>

A copy of all my photographs are backed up and stored on a local FreeBSD server.  The above script was written for and run from that server.  The resultant metadata text CSV file was then winSCP'ed back to the Windows PC.

I then used the QGIS 'Add Delimited Text Layer' (located at the bottom Left Hand corner): QGIS Adding CSV File    add on to import the iPhoto metadata file.  I could then save the csv layer as a Shapefile, by right clicking on the layer and selecting 'Save as...'  I did this for each of the years worth of data.  I could have used the script to find all the iPhone photographs in one hit. It could have added a separate column in for the year, and then have QGIS 'Style' the data points to a different colour per year, however at the moment, I wanted each years worth of photographs in separate Shapefile layers.  Here is a screen shot of QGIS displaying thousands of iPhone photo data points:  

QGIS iPhone Photograph Example  

To get the QGIS data point to hyperlink to the photograph, I used the QGIS eVis documentation from here to configure the eVis event browser.  This is accessed by the icon down near the bottom left hand corner of the screen:   QGIS eVis Event Browser Icon 

I Just had to fill out the 'Options' TAB:

QGIS Event OptionsTab 

and the 'Configure External Applications' TAB:

QGIS Event Config External Applications Tab 

Here I just had to browse down to the location of my photo viewer of choice, Irfanview.  This means that any jpg referenced data point will open in the eVis Event Browser.  You can use this technique to open or view just about any kind of data from within QGIS. Below is a test of the technique.  1) I have enabled the 'eVis Event ID Tool'.  2) I have clicked on a data point and 3) the Browser window automatic opened up displaying the photograph.  You can clearly see the different places and years that I took some of the photos:

Example of QGIS Hyperlinking  

 

Note: for newbie QGIS buffs (like me), the QGIS Australian layers above have been extracted from the following sources:

  •  http://www.naturalearthdata.com/ Natural Earth Data Maps (Large scale data, 1:10m - World, Cultural, Physical, Raster).  I just cut and pasted the Australian features I needed from the world maps, into separate Shapefile layers.