source: extensions/AMetaData/JpegMetaData/Readers/GpsReader.class.php @ 6729

Last change on this file since 6729 was 6729, checked in by grum, 14 years ago

feature:1777

  • Weight of the metadata database can becomes very heavy
  • Property svn:executable set to *
File size: 5.4 KB
Line 
1<?php
2/*
3 * --:: JPEG MetaDatas ::-------------------------------------------------------
4 *
5 *  Author    : Grum
6 *   email    : grum at piwigo.org
7 *   website  : http://photos.grum.fr
8 *
9 *   << May the Little SpaceFrog be with you ! >>
10 *
11 *
12 * +-----------------------------------------------------------------------+
13 * | JpegMetaData - a PHP based Jpeg Metadata manager                      |
14 * +-----------------------------------------------------------------------+
15 * | Copyright(C) 2010  Grum - http://www.grum.fr                          |
16 * +-----------------------------------------------------------------------+
17 * | This program is free software; you can redistribute it and/or modify  |
18 * | it under the terms of the GNU General Public License as published by  |
19 * | the Free Software Foundation                                          |
20 * |                                                                       |
21 * | This program is distributed in the hope that it will be useful, but   |
22 * | WITHOUT ANY WARRANTY; without even the implied warranty of            |
23 * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
24 * | General Public License for more details.                              |
25 * |                                                                       |
26 * | You should have received a copy of the GNU General Public License     |
27 * | along with this program; if not, write to the Free Software           |
28 * | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
29 * | USA.                                                                  |
30 * +-----------------------------------------------------------------------+
31 *
32 *
33 * -----------------------------------------------------------------------------
34 *
35 * The GpsReader class is dedicated to read GPS tags from a sub IFD structure
36 *
37 * ======> See IfdReader.class.php to know more about an IFD structure <========
38 *
39 * -----------------------------------------------------------------------------
40 *
41 * .. Notes ..
42 *
43 *
44 * The GpsReader class is derived from the IfdReader class.
45 *
46 * ========> See IfdReader.class.php to know more about common methods <========
47 *
48 * -----------------------------------------------------------------------------
49 */
50
51  require_once(JPEG_METADATA_DIR."TagDefinitions/GpsTags.class.php");
52  require_once(JPEG_METADATA_DIR."Readers/MakerNotesReader.class.php");
53
54  class GpsReader extends IfdReader
55  {
56    protected $schema = Schemas::EXIF;
57
58    function __destruct()
59    {
60      parent::__destruct();
61    }
62
63    /**
64     * initialize the definition of the GPS tags
65     */
66    protected function initializeTagDef()
67    {
68      $this->tagDef = new GpsTags();
69    }
70
71    /**
72     * this function do the interpretation of specials tags and overrides the
73     * IfdReader function
74    */
75    protected function processSpecialTag($tagId, $values, $type, $valuesOffset=0)
76    {
77      switch($tagId)
78      {
79        case 0x0000: // Version
80          $returned=sprintf("%d.%d.%d.%d", $values[0], $values[1], $values[2], $values[3]);
81          break;
82        case 0x0001: // GPSLatitudeRef
83        case 0x0003: // GPSLongitudeRef
84        case 0x0013: // GPSDestLatitudeRef
85        case 0x0015: // GPSDestLongitudeRef
86          $tag=$this->tagDef->getTagById($tagId);
87          $key=substr($values, 0, 1);
88          if(array_key_exists($key, $tag['tagValues.special']))
89          {
90            $returned=$tag['tagValues.special'][$key];
91          }
92          else
93          {
94            $returned="";
95          }
96          break;
97        case 0x0002: // GPSLatitude
98        case 0x0004: // GPSLongitude
99        case 0x0014: // GPSDestLatitude
100        case 0x0016: // GPSDestLongitude
101          /*
102           * converted in degrees, minutes and seconds
103           */
104          $returned=ConvertData::toDMS($values[0], $values[1], $values[2]);
105          break;
106        case 0x0006: // GPSAltitude
107        case 0x000D: // GPSSpeed
108        case 0x000F: // GPSTrack
109        case 0x0011: // GPSImgDirection
110        case 0x0018: // GPSDestBearing
111        case 0x001A: // GPSDestDistance
112          if($values[1]==0) $values[1]=1;
113          $returned=round($values[0]/$values[1],2);
114          break;
115        case 0x0008: // GPSSatellites
116        case 0x0012: // GPSMapDatum
117        case 0x001B: // GPSProcessingMethod => not sure about the string format...
118        case 0x001C: // GPSAreaInformation => not sure about the string format...
119          $returned=ConvertData::toStrings($values);
120          break;
121        case 0x0009: // GPSStatus
122        case 0x000A: // GPSMeasureMode
123        case 0x000C: // GPSSpeedRef
124        case 0x0019: // GPSDestDistanceRef
125        case 0x000E: // GPSTrackRef
126        case 0x0010: // GPSImgDirectionRef
127        case 0x0017: // GPSDestBearingRef
128          $tag=$this->tagDef->getTagById(0x0009);
129          $key=substr($values,0,1);
130          if(array_key_exists($key, $tag['tagValues.special']))
131          {
132            $returned=$tag['tagValues.special'][$key];
133          }
134          else
135          {
136            $returned=$tag['tagValues.special']['unknown'];
137          }
138          break;
139        case 0x001D: // GPSDateStamp
140          $returned=ConvertData::toDateTime($values);
141          break;
142        default:
143          $returned="Not yet implemented;".ConvertData::toHexDump($tagId, ByteType::USHORT)." => ".ConvertData::toHexDump($values, $type);
144          break;
145      }
146      return($returned);
147    }
148
149  }
150
151
152?>
Note: See TracBrowser for help on using the repository browser.