If the location.module is installed, and the user doesn't enter a location why not have the GPS co-ords pulled from the Exif tags?

This is sort of a duplicate of http://drupal.org/node/143071 but belongs more in the Exif module.

I made a start at such functionality and it's working on our site. See http://drupal.org/node/143071#comment-310009 for quick and dirty code.

This code needs a bit of cleaning but the basic idea is working. Probably improvements:

1. Check for location.module installed/active properly.

2. Couple of configuration options to a) activate this feature, b) determine what happens on image re-submission.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

raintonr’s picture

Status: Needs work » Needs review
FileSize
13.5 KB

Here's another patch with:

- Improved checking for location.module.

- Admin menu items to enable/disable the function & start rescan.

- Cron hook to process image files in batches if scan is started. Allows GPS locations to be harvested from existing images when scan restart admin option is chosen.

raintonr’s picture

FileSize
13.49 KB

Oops... slight problem with the last patch. Completely disables Exif if locations are not present on the module. This one should be better.

neclimdul’s picture

Do you think you could make a version of your patch that's in line with the drupal patch guidelines?

http://drupal.org/patch/create

Specifically cvs -up

raintonr’s picture

FileSize
11.03 KB

Hi,

diff -up patch attached as requested.

This is between the release I originally patched (1.0) and my update. I notice some things have changed a bit in 1.1. If you don't have time to do this merge I can try and update to 1.1 and re-do my changes. Please let me know if that's required.

David Lesieur’s picture

Version: 5.x-1.1 » 6.x-1.x-dev
rapsli’s picture

can somebody help me on this? I'm working on the D6 branch -> the feature to integrate Coords into CCK. It's actually pretty simple, but: I don't know how to intepret the data:

the exif comes out as an array:
#
value (Array, 3 elements)

* 0 (String, 4 characters ) 49/1
* 1 (String, 4 characters ) 44/1
* 2 (String, 19 characters ) 2147483631/82532375

This is just the latitute. How do I have to put this together in order to make real coords?

Plus. Location CCK: In which way do the coords have to be entered? Please provide an example. I'll then make sure to get that in.

raintonr’s picture

To figure out how to get co-ords from EXIF, look in the patch, specifically at these parts:

function _exif_DMS2D($entry) {
  $value = $entry->getValue();
  $degrees = $value[0][0] / $value[0][1];
  $minutes = $value[1][0] / $value[1][1];
  $seconds = $value[2][0] / $value[2][1];

  return $degrees + $minutes/60 + $seconds/3600;
}

...

  $entry = $gps->getEntry(PelTag::GPS_LATITUDE);
  if (!$entry) return FALSE;
  $GPS_LATITUDE = _exif_DMS2D($entry);
  $entry = $gps->getEntry(PelTag::GPS_LATITUDE_REF);
  if (!$entry) return FALSE;
  if ($entry->getValue() == 'S') $GPS_LATITUDE = -$GPS_LATITUDE;

  $entry = $gps->getEntry(PelTag::GPS_LONGITUDE);
  if (!$entry) return FALSE;
  $GPS_LONGITUDE = _exif_DMS2D($entry);
  $entry = $gps->getEntry(PelTag::GPS_LONGITUDE_REF);
  if (!$entry) return FALSE;
  if ($entry->getValue() == 'W') $GPS_LONGITUDE = -$GPS_LONGITUDE;
emagus’s picture

subscribing

raintonr’s picture

@rapsli Was #7 any good or do you need more info?

emagus’s picture

Status: Needs review » Needs work
Anonymous’s picture

i'm trying to get this working with the latest D6 version. the patch is for a very old version and does not help me. can anyone give me suggestion where to tweak the module to get it working?

raintonr’s picture

I'd given up getting this inserted into the exif module and wrote a small exif_location module. Will post more details when it's fit for public consumption ;)

Anonymous’s picture

i am happy for code in any condition. waiting for a solution to this problem to send a site live.

emagus’s picture

great news raintonr. waiting patiently

spl13’s picture

subscribing - waiting for exif_location

rapsli’s picture

applied a patch to head. let's get this one here moving on next. Anybody willing to volonteer for a patch? I'm more than welcome to apply it.

mathmeye’s picture

Hi Rapsli,

Works only for me if I prepend "gps_" to "gpslatitude" and "gps_gpslongitude" in lines 240 and 243 respectively.

    if ($key == 'gps_gpslatitude') {
      $value = _exif_DMS2D($value, $data['gpslatituderef']);
    } 
    elseif ($key == 'gps_gpslongitude') {
      $value = _exif_DMS2D($value, $data['gpslongituderef']);
    } 
raintonr’s picture

rapsli’s picture

Status: Needs work » Closed (duplicate)
raintonr’s picture

Status: Closed (duplicate) » Active
FileSize
1016 bytes

Actually, this isn't a duplicate.

I spoke about making a exif_location module though, please see attached tar file. Think it would be nice to bundle this with exif module.

Testing of this was hardly thorough, but works for me. YMMV.

raintonr’s picture

Anyone tried #20? Thoughts on integrating or bundling with the EXIF module?

rapsli’s picture

let me have a look at this next week when there's more time.

TUc’s picture

I tried the code in #20. Worked like a charm.

emagus’s picture

How did you do it? What fields do you have to add, and what else has to be done? I just can't get it to work...

TUc’s picture

The problem is that, currently, you have to account for a few different issues:

1) The $op in hook_nodeapi that should handle the storage of EXIF information in the $node object. IMO, this should be "presave".
2) The correct key usage in the function _exif_reformat(): "gps_gpslatitude" and "gps_gpslongitude" instead of "gps_latitude" and "gps_longitude".
3) The correct execution order of anything in hook_nodeapi() in exif_location module relative to the code in (1) above.

It isn't that complicated, but it requires a few hacks in Exif module.

I want to work on this, but I have no idea of the latest code status for Exif module. It seems dispersed.

@rapsli: are you willing to make a new release soon that incorporates al these changes?

rapsli’s picture

Status: Active » Needs review

this is still experimental, as I didn't get around testing it. Just had a brief look at it. Let's find out, how well the community is working. It's committed to HEAD.

rapsli’s picture

Status: Needs review » Fixed

committed this to 6.1 branch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mawosch’s picture

Version: 6.x-1.x-dev » 6.x-1.3

I try to use the "Exif Location" Sub-Module.
The Location Module is installed and coordinate input is activated for the nodetype. While creating the node I can see the lat and lon fields. In Exif-Module settings the nodetype is active too.
But after uploading a picture with GPS data, the coordinate is not in the Location module. Do I have to create additional CCK fields? Forgotten settings?

Can anybody give me a How-To of bringing GPS data from the filefield picture to the location field via "Exif Location"?

If I understand that and it works here, I can write a README for the "Exif Location" Sub-Module.

rapsli’s picture

Status: Closed (fixed) » Active
ispboy’s picture

my solution:
vi "exif/exif.class.php"

goto line 77 nearby, replace:

if ($tagName['section'] != 'iptc') {

with:

      if ($tagName['section'] == 'gps') {
        $info[$tagName['section'] .'_'. $tagName['tag']] = $arSmallExif[$tagName['tag']];
      }
      elseif ($tagName['section'] != 'iptc') {

finished. it works!

addtionally, for the photo without gps information, it would display warnning! so
modify the exif.module, line 282

function _exif_DMS2D($value, $ref) {
  if (!$value) {
    return 0;
  }

  • rapsli committed a20e371 on 8.x-1.x
    #178370 added location exif
    
    
jphautin’s picture

Issue summary: View changes
Status: Active » Fixed
jphautin’s picture

Status: Fixed » Closed (fixed)