source: josm/trunk/src/com/drew/metadata/exif/GpsDescriptor.java@ 6127

Last change on this file since 6127 was 6127, checked in by bastiK, 11 years ago

applied #8895 - Upgrade metadata-extractor to v. 2.6.4 (patch by ebourg)

File size: 9.2 KB
Line 
1/*
2 * Copyright 2002-2012 Drew Noakes
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * http://drewnoakes.com/code/exif/
19 * http://code.google.com/p/metadata-extractor/
20 */
21package com.drew.metadata.exif;
22
23import com.drew.lang.GeoLocation;
24import com.drew.lang.Rational;
25import com.drew.lang.annotations.NotNull;
26import com.drew.lang.annotations.Nullable;
27import com.drew.metadata.TagDescriptor;
28
29import java.text.DecimalFormat;
30
31/**
32 * Provides human-readable string representations of tag values stored in a <code>GpsDirectory</code>.
33 *
34 * @author Drew Noakes http://drewnoakes.com
35 */
36public class GpsDescriptor extends TagDescriptor<GpsDirectory>
37{
38 public GpsDescriptor(@NotNull GpsDirectory directory)
39 {
40 super(directory);
41 }
42
43 @Nullable
44 public String getDescription(int tagType)
45 {
46 switch (tagType) {
47 case GpsDirectory.TAG_GPS_VERSION_ID:
48 return getGpsVersionIdDescription();
49 case GpsDirectory.TAG_GPS_ALTITUDE:
50 return getGpsAltitudeDescription();
51 case GpsDirectory.TAG_GPS_ALTITUDE_REF:
52 return getGpsAltitudeRefDescription();
53 case GpsDirectory.TAG_GPS_STATUS:
54 return getGpsStatusDescription();
55 case GpsDirectory.TAG_GPS_MEASURE_MODE:
56 return getGpsMeasureModeDescription();
57 case GpsDirectory.TAG_GPS_SPEED_REF:
58 return getGpsSpeedRefDescription();
59 case GpsDirectory.TAG_GPS_TRACK_REF:
60 case GpsDirectory.TAG_GPS_IMG_DIRECTION_REF:
61 case GpsDirectory.TAG_GPS_DEST_BEARING_REF:
62 return getGpsDirectionReferenceDescription(tagType);
63 case GpsDirectory.TAG_GPS_TRACK:
64 case GpsDirectory.TAG_GPS_IMG_DIRECTION:
65 case GpsDirectory.TAG_GPS_DEST_BEARING:
66 return getGpsDirectionDescription(tagType);
67 case GpsDirectory.TAG_GPS_DEST_DISTANCE_REF:
68 return getGpsDestinationReferenceDescription();
69 case GpsDirectory.TAG_GPS_TIME_STAMP:
70 return getGpsTimeStampDescription();
71 case GpsDirectory.TAG_GPS_LONGITUDE:
72 // three rational numbers -- displayed in HH"MM"SS.ss
73 return getGpsLongitudeDescription();
74 case GpsDirectory.TAG_GPS_LATITUDE:
75 // three rational numbers -- displayed in HH"MM"SS.ss
76 return getGpsLatitudeDescription();
77 case GpsDirectory.TAG_GPS_DIFFERENTIAL:
78 return getGpsDifferentialDescription();
79 default:
80 return super.getDescription(tagType);
81 }
82 }
83
84 @Nullable
85 private String getGpsVersionIdDescription()
86 {
87 return convertBytesToVersionString(_directory.getIntArray(GpsDirectory.TAG_GPS_VERSION_ID), 1);
88 }
89
90 @Nullable
91 public String getGpsLatitudeDescription()
92 {
93 GeoLocation location = _directory.getGeoLocation();
94
95 if (location == null)
96 return null;
97
98 return GeoLocation.decimalToDegreesMinutesSecondsString(location.getLatitude());
99 }
100
101 @Nullable
102 public String getGpsLongitudeDescription()
103 {
104 GeoLocation location = _directory.getGeoLocation();
105
106 if (location == null)
107 return null;
108
109 return GeoLocation.decimalToDegreesMinutesSecondsString(location.getLongitude());
110 }
111
112 @Nullable
113 public String getGpsTimeStampDescription()
114 {
115 // time in hour, min, sec
116 int[] timeComponents = _directory.getIntArray(GpsDirectory.TAG_GPS_TIME_STAMP);
117 if (timeComponents==null)
118 return null;
119 StringBuilder description = new StringBuilder();
120 description.append(timeComponents[0]);
121 description.append(":");
122 description.append(timeComponents[1]);
123 description.append(":");
124 description.append(timeComponents[2]);
125 description.append(" UTC");
126 return description.toString();
127 }
128
129 @Nullable
130 public String getGpsDestinationReferenceDescription()
131 {
132 final String value = _directory.getString(GpsDirectory.TAG_GPS_DEST_DISTANCE_REF);
133 if (value==null)
134 return null;
135 String distanceRef = value.trim();
136 if ("K".equalsIgnoreCase(distanceRef)) {
137 return "kilometers";
138 } else if ("M".equalsIgnoreCase(distanceRef)) {
139 return "miles";
140 } else if ("N".equalsIgnoreCase(distanceRef)) {
141 return "knots";
142 } else {
143 return "Unknown (" + distanceRef + ")";
144 }
145 }
146
147 @Nullable
148 public String getGpsDirectionDescription(int tagType)
149 {
150 Rational angle = _directory.getRational(tagType);
151 // provide a decimal version of rational numbers in the description, to avoid strings like "35334/199 degrees"
152 String value = angle != null
153 ? new DecimalFormat("0.##").format(angle.doubleValue())
154 : _directory.getString(tagType);
155 if (value==null || value.trim().length()==0)
156 return null;
157 return value.trim() + " degrees";
158 }
159
160 @Nullable
161 public String getGpsDirectionReferenceDescription(int tagType)
162 {
163 final String value = _directory.getString(tagType);
164 if (value==null)
165 return null;
166 String gpsDistRef = value.trim();
167 if ("T".equalsIgnoreCase(gpsDistRef)) {
168 return "True direction";
169 } else if ("M".equalsIgnoreCase(gpsDistRef)) {
170 return "Magnetic direction";
171 } else {
172 return "Unknown (" + gpsDistRef + ")";
173 }
174 }
175
176 @Nullable
177 public String getGpsSpeedRefDescription()
178 {
179 final String value = _directory.getString(GpsDirectory.TAG_GPS_SPEED_REF);
180 if (value==null)
181 return null;
182 String gpsSpeedRef = value.trim();
183 if ("K".equalsIgnoreCase(gpsSpeedRef)) {
184 return "kph";
185 } else if ("M".equalsIgnoreCase(gpsSpeedRef)) {
186 return "mph";
187 } else if ("N".equalsIgnoreCase(gpsSpeedRef)) {
188 return "knots";
189 } else {
190 return "Unknown (" + gpsSpeedRef + ")";
191 }
192 }
193
194 @Nullable
195 public String getGpsMeasureModeDescription()
196 {
197 final String value = _directory.getString(GpsDirectory.TAG_GPS_MEASURE_MODE);
198 if (value==null)
199 return null;
200 String gpsSpeedMeasureMode = value.trim();
201 if ("2".equalsIgnoreCase(gpsSpeedMeasureMode)) {
202 return "2-dimensional measurement";
203 } else if ("3".equalsIgnoreCase(gpsSpeedMeasureMode)) {
204 return "3-dimensional measurement";
205 } else {
206 return "Unknown (" + gpsSpeedMeasureMode + ")";
207 }
208 }
209
210 @Nullable
211 public String getGpsStatusDescription()
212 {
213 final String value = _directory.getString(GpsDirectory.TAG_GPS_STATUS);
214 if (value==null)
215 return null;
216 String gpsStatus = value.trim();
217 if ("A".equalsIgnoreCase(gpsStatus)) {
218 return "Active (Measurement in progress)";
219 } else if ("V".equalsIgnoreCase(gpsStatus)) {
220 return "Void (Measurement Interoperability)";
221 } else {
222 return "Unknown (" + gpsStatus + ")";
223 }
224 }
225
226 @Nullable
227 public String getGpsAltitudeRefDescription()
228 {
229 Integer value = _directory.getInteger(GpsDirectory.TAG_GPS_ALTITUDE_REF);
230 if (value==null)
231 return null;
232 if (value == 0)
233 return "Sea level";
234 if (value == 1)
235 return "Below sea level";
236 return "Unknown (" + value + ")";
237 }
238
239 @Nullable
240 public String getGpsAltitudeDescription()
241 {
242 final Rational value = _directory.getRational(GpsDirectory.TAG_GPS_ALTITUDE);
243 if (value==null)
244 return null;
245 return value.intValue() + " metres";
246 }
247
248 @Nullable
249 public String getGpsDifferentialDescription()
250 {
251 final Integer value = _directory.getInteger(GpsDirectory.TAG_GPS_DIFFERENTIAL);
252 if (value==null)
253 return null;
254 if (value == 0)
255 return "No Correction";
256 if (value == 1)
257 return "Differential Corrected";
258 return "Unknown (" + value + ")";
259 }
260
261 @Nullable
262 public String getDegreesMinutesSecondsDescription()
263 {
264 GeoLocation location = _directory.getGeoLocation();
265
266 if (location == null)
267 return null;
268
269 return location.toDMSString();
270 }
271}
Note: See TracBrowser for help on using the repository browser.