Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/drew/metadata/exif/GpsDescriptor.java


1   /*
2    * Created by dnoakes on 12-Nov-2002 22:27:52 using IntelliJ IDEA.
3    */
4   package com.drew.metadata.exif;
5   
6   import com.drew.lang.Rational;
7   import com.drew.metadata.Directory;
8   import com.drew.metadata.MetadataException;
9   import com.drew.metadata.TagDescriptor;
10  
11  /**
12   *
13   */
14  public class GpsDescriptor extends TagDescriptor
15  {
16      public GpsDescriptor(Directory directory)
17      {
18          super(directory);
19      }
20  
21      public String getDescription(int tagType) throws MetadataException
22      {
23          switch (tagType) {
24              case GpsDirectory.TAG_GPS_ALTITUDE:
25                  return getGpsAltitudeDescription();
26              case GpsDirectory.TAG_GPS_ALTITUDE_REF:
27                  return getGpsAltitudeRefDescription();
28              case GpsDirectory.TAG_GPS_STATUS:
29                  return getGpsStatusDescription();
30              case GpsDirectory.TAG_GPS_MEASURE_MODE:
31                  return getGpsMeasureModeDescription();
32              case GpsDirectory.TAG_GPS_SPEED_REF:
33                  return getGpsSpeedRefDescription();
34              case GpsDirectory.TAG_GPS_TRACK_REF:
35              case GpsDirectory.TAG_GPS_IMG_DIRECTION_REF:
36              case GpsDirectory.TAG_GPS_DEST_BEARING_REF:
37                  return getGpsDirectionReferenceDescription(tagType);
38              case GpsDirectory.TAG_GPS_TRACK:
39              case GpsDirectory.TAG_GPS_IMG_DIRECTION:
40              case GpsDirectory.TAG_GPS_DEST_BEARING:
41                  return getGpsDirectionDescription(tagType);
42              case GpsDirectory.TAG_GPS_DEST_DISTANCE_REF:
43                  return getGpsDestinationReferenceDescription();
44              case GpsDirectory.TAG_GPS_TIME_STAMP:
45                  return getGpsTimeStampDescription();
46                  // three rational numbers -- displayed in HH"MM"SS.ss
47              case GpsDirectory.TAG_GPS_LONGITUDE:
48                  return getGpsLongitudeDescription();
49              case GpsDirectory.TAG_GPS_LATITUDE:
50                  return getGpsLatitudeDescription();
51              default:
52                  return _directory.getString(tagType);
53          }
54      }
55  
56      private String getGpsLatitudeDescription() throws MetadataException
57      {
58          if (!_directory.containsTag(GpsDirectory.TAG_GPS_LATITUDE)) return null;
59          return getHoursMinutesSecondsDescription(GpsDirectory.TAG_GPS_LATITUDE);
60      }
61  
62      private String getGpsLongitudeDescription() throws MetadataException
63      {
64          if (!_directory.containsTag(GpsDirectory.TAG_GPS_LONGITUDE)) return null;
65          return getHoursMinutesSecondsDescription(GpsDirectory.TAG_GPS_LONGITUDE);
66      }
67  
68      private String getHoursMinutesSecondsDescription(int tagType) throws MetadataException
69      {
70          Rational[] components = _directory.getRationalArray(tagType);
71          // TODO create an HoursMinutesSecods class ??
72          int deg = components[0].intValue();
73          float min = components[1].floatValue();
74          float sec = components[2].floatValue();
75          // carry fractions of minutes into seconds -- thanks Colin Briton
76          sec += (min % 1) * 60;
77          return String.valueOf(deg) + "\"" + String.valueOf((int)min) + "'" + String.valueOf(sec);
78      }
79  
80      private String getGpsTimeStampDescription() throws MetadataException
81      {
82          // time in hour, min, sec
83          if (!_directory.containsTag(GpsDirectory.TAG_GPS_TIME_STAMP)) return null;
84          int[] timeComponents = _directory.getIntArray(GpsDirectory.TAG_GPS_TIME_STAMP);
85          StringBuffer sbuffer = new StringBuffer();
86          sbuffer.append(timeComponents[0]);
87          sbuffer.append(":");
88          sbuffer.append(timeComponents[1]);
89          sbuffer.append(":");
90          sbuffer.append(timeComponents[2]);
91          sbuffer.append(" UTC");
92          return sbuffer.toString();
93      }
94  
95      private String getGpsDestinationReferenceDescription()
96      {
97          if (!_directory.containsTag(GpsDirectory.TAG_GPS_DEST_DISTANCE_REF)) return null;
98          String destRef = _directory.getString(GpsDirectory.TAG_GPS_DEST_DISTANCE_REF).trim();
99          if ("K".equalsIgnoreCase(destRef)) {
100             return "kilometers";
101         } else if ("M".equalsIgnoreCase(destRef)) {
102             return "miles";
103         } else if ("N".equalsIgnoreCase(destRef)) {
104             return "knots";
105         } else {
106             return "Unknown (" + destRef + ")";
107         }
108     }
109 
110     private String getGpsDirectionDescription(int tagType)
111     {
112         if (!_directory.containsTag(tagType)) return null;
113         String gpsDirection = _directory.getString(tagType).trim();
114         return gpsDirection + " degrees";
115     }
116 
117     private String getGpsDirectionReferenceDescription(int tagType)
118     {
119         if (!_directory.containsTag(tagType)) return null;
120         String gpsDistRef = _directory.getString(tagType).trim();
121         if ("T".equalsIgnoreCase(gpsDistRef)) {
122             return "True direction";
123         } else if ("M".equalsIgnoreCase(gpsDistRef)) {
124             return "Magnetic direction";
125         } else {
126             return "Unknown (" + gpsDistRef + ")";
127         }
128     }
129 
130     private String getGpsSpeedRefDescription()
131     {
132         if (!_directory.containsTag(GpsDirectory.TAG_GPS_SPEED_REF)) return null;
133         String gpsSpeedRef = _directory.getString(GpsDirectory.TAG_GPS_SPEED_REF).trim();
134         if ("K".equalsIgnoreCase(gpsSpeedRef)) {
135             return "kph";
136         } else if ("M".equalsIgnoreCase(gpsSpeedRef)) {
137             return "mph";
138         } else if ("N".equalsIgnoreCase(gpsSpeedRef)) {
139             return "knots";
140         } else {
141             return "Unknown (" + gpsSpeedRef + ")";
142         }
143     }
144 
145     private String getGpsMeasureModeDescription()
146     {
147         if (!_directory.containsTag(GpsDirectory.TAG_GPS_MEASURE_MODE)) return null;
148         String gpsSpeedMeasureMode = _directory.getString(GpsDirectory.TAG_GPS_MEASURE_MODE).trim();
149         if ("2".equalsIgnoreCase(gpsSpeedMeasureMode)) {
150             return "2-dimensional measurement";
151         } else if ("3".equalsIgnoreCase(gpsSpeedMeasureMode)) {
152             return "3-dimensional measurement";
153         } else {
154             return "Unknown (" + gpsSpeedMeasureMode + ")";
155         }
156     }
157 
158     private String getGpsStatusDescription()
159     {
160         if (!_directory.containsTag(GpsDirectory.TAG_GPS_STATUS)) return null;
161         String gpsStatus = _directory.getString(GpsDirectory.TAG_GPS_STATUS).trim();
162         if ("A".equalsIgnoreCase(gpsStatus)) {
163             return "Measurement in progess";
164         } else if ("V".equalsIgnoreCase(gpsStatus)) {
165             return "Measurement Interoperability";
166         } else {
167             return "Unknown (" + gpsStatus + ")";
168         }
169     }
170 
171     private String getGpsAltitudeRefDescription() throws MetadataException
172     {
173         if (!_directory.containsTag(GpsDirectory.TAG_GPS_ALTITUDE_REF)) return null;
174         int alititudeRef = _directory.getInt(GpsDirectory.TAG_GPS_ALTITUDE_REF);
175         if (alititudeRef == 0) {
176             return "Sea level";
177         } else {
178             return "Unknown (" + alititudeRef + ")";
179         }
180     }
181 
182     private String getGpsAltitudeDescription() throws MetadataException
183     {
184         if (!_directory.containsTag(GpsDirectory.TAG_GPS_ALTITUDE)) return null;
185         String alititude = _directory.getRational(GpsDirectory.TAG_GPS_ALTITUDE).toSimpleString(true);
186         return alititude + " metres";
187     }
188 }