Changeset 25801 for trunk


Ignore:
Timestamp:
Dec 6, 2013, 8:14:44 PM (10 years ago)
Author:
mistic100
Message:

feature 3009: Add 'latitude' and 'longitude' fields in images table

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_metadata.php

    r25018 r25801  
    123123      array_merge(
    124124        $update_fields,
    125         array_keys($conf['use_exif_mapping'])
     125        array_keys($conf['use_exif_mapping']),
     126        array('latitude', 'longitude')
    126127        );
    127128  }
  • trunk/include/functions_metadata.inc.php

    r25550 r25801  
    153153  if ($exif = @read_exif_data($filename))
    154154  {
    155     $exif = trigger_event('format_exif_data', $exif, $filename, $map );
     155    $exif = trigger_event('format_exif_data', $exif, $filename, $map);
     156
     157    // configured fields
    156158    foreach ($map as $key => $field)
    157159    {
     
    170172          $result[$key] = $exif[$tokens[0]][$tokens[1]];
    171173        }
     174      }
     175    }
     176
     177    // GPS data
     178    $gps_exif = array_intersect_key($exif, array_flip(array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude')));
     179    if (count($gps_exif) == 4)
     180    {
     181      if (
     182        is_array($gps_exif['GPSLatitude'])  and in_array($gps_exif['GPSLatitudeRef'], array('S', 'N')) and
     183        is_array($gps_exif['GPSLongitude']) and in_array($gps_exif['GPSLongitudeRef'], array('W', 'E'))
     184        )
     185      {
     186        $result['latitude'] = parse_exif_gps_data($gps_exif['GPSLatitude'], $gps_exif['GPSLatitudeRef']);
     187        $result['longitude'] = parse_exif_gps_data($gps_exif['GPSLongitude'], $gps_exif['GPSLongitudeRef']);
    172188      }
    173189    }
     
    187203}
    188204
     205
     206/**
     207 * Converts EXIF GPS format to a float value.
     208 * @since 2.6
     209 *
     210 * @param string[] $raw eg:
     211 *    - 41/1
     212 *    - 54/1
     213 *    - 9843/500
     214 * @param string $ref 'S', 'N', 'E', 'W'. eg: 'N'
     215 * @return float eg: 41.905468
     216 */
     217function parse_exif_gps_data($raw, $ref)
     218{
     219  foreach ($raw as &$i)
     220  {
     221    $i = explode('/', $i);
     222    $i = $i[1]==0 ? 0 : $i[0]/$i[1];
     223  }
     224  unset($i);
     225
     226  $v = $raw[0] + $raw[1]/60 + $raw[2]/3600;
     227
     228  $ref = strtoupper($ref);
     229  if ($ref == 'S' or $ref == 'W') $v= -$v;
     230
     231  return $v;
     232}
     233
    189234?>
  • trunk/install/piwigo_structure-mysql.sql

    r22879 r25801  
    197197  `md5sum` char(32) default NULL,
    198198  `added_by` smallint(5) NOT NULL default '0',
    199   `rotation` tinyint unsigned default null,
     199  `rotation` tinyint unsigned default NULL,
     200  `latitude` double(8, 6) default NULL,
     201  `longitude` double(9, 6) default NULL,
    200202  PRIMARY KEY  (`id`),
    201203  KEY `images_i2` (`date_available`),
     
    203205  KEY `images_i4` (`hit`),
    204206  KEY `images_i5` (`date_creation`),
    205   KEY `images_i1` (`storage_category_id`)
     207  KEY `images_i1` (`storage_category_id`),
     208  KEY `images_i6` (`latitude`)
    206209) ENGINE=MyISAM;
    207210
Note: See TracChangeset for help on using the changeset viewer.