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

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

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

File size: 9.2 KB
RevLine 
[4231]1/*
[6127]2 * Copyright 2002-2012 Drew Noakes
[4231]3 *
[6127]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
[4231]7 *
[6127]8 * http://www.apache.org/licenses/LICENSE-2.0
[4231]9 *
[6127]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/
[4231]20 */
21package com.drew.metadata.exif;
22
[6127]23import com.drew.lang.GeoLocation;
[4231]24import com.drew.lang.Rational;
[6127]25import com.drew.lang.annotations.NotNull;
26import com.drew.lang.annotations.Nullable;
[4231]27import com.drew.metadata.TagDescriptor;
28
[6127]29import java.text.DecimalFormat;
30
[4231]31/**
[6127]32 * Provides human-readable string representations of tag values stored in a <code>GpsDirectory</code>.
[4231]33 *
[6127]34 * @author Drew Noakes http://drewnoakes.com
[4231]35 */
[6127]36public class GpsDescriptor extends TagDescriptor<GpsDirectory>
[4231]37{
[6127]38 public GpsDescriptor(@NotNull GpsDirectory directory)
[4231]39 {
40 super(directory);
41 }
42
[6127]43 @Nullable
44 public String getDescription(int tagType)
[4231]45 {
46 switch (tagType) {
[6127]47 case GpsDirectory.TAG_GPS_VERSION_ID:
48 return getGpsVersionIdDescription();
[4231]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();
[6127]71 case GpsDirectory.TAG_GPS_LONGITUDE:
[4231]72 // three rational numbers -- displayed in HH"MM"SS.ss
73 return getGpsLongitudeDescription();
74 case GpsDirectory.TAG_GPS_LATITUDE:
[6127]75 // three rational numbers -- displayed in HH"MM"SS.ss
[4231]76 return getGpsLatitudeDescription();
[6127]77 case GpsDirectory.TAG_GPS_DIFFERENTIAL:
78 return getGpsDifferentialDescription();
[4231]79 default:
[6127]80 return super.getDescription(tagType);
[4231]81 }
82 }
83
[6127]84 @Nullable
85 private String getGpsVersionIdDescription()
[4231]86 {
[6127]87 return convertBytesToVersionString(_directory.getIntArray(GpsDirectory.TAG_GPS_VERSION_ID), 1);
[4231]88 }
89
[6127]90 @Nullable
91 public String getGpsLatitudeDescription()
[4231]92 {
[6127]93 GeoLocation location = _directory.getGeoLocation();
94
95 if (location == null)
96 return null;
97
98 return GeoLocation.decimalToDegreesMinutesSecondsString(location.getLatitude());
[4231]99 }
100
[6127]101 @Nullable
102 public String getGpsLongitudeDescription()
[4231]103 {
[6127]104 GeoLocation location = _directory.getGeoLocation();
105
106 if (location == null)
107 return null;
108
109 return GeoLocation.decimalToDegreesMinutesSecondsString(location.getLongitude());
[4231]110 }
111
[6127]112 @Nullable
113 public String getGpsTimeStampDescription()
[4231]114 {
115 // time in hour, min, sec
116 int[] timeComponents = _directory.getIntArray(GpsDirectory.TAG_GPS_TIME_STAMP);
[6127]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();
[4231]127 }
128
[6127]129 @Nullable
[4231]130 public String getGpsDestinationReferenceDescription()
131 {
[6127]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)) {
[4231]137 return "kilometers";
[6127]138 } else if ("M".equalsIgnoreCase(distanceRef)) {
[4231]139 return "miles";
[6127]140 } else if ("N".equalsIgnoreCase(distanceRef)) {
[4231]141 return "knots";
142 } else {
[6127]143 return "Unknown (" + distanceRef + ")";
[4231]144 }
145 }
146
[6127]147 @Nullable
[4231]148 public String getGpsDirectionDescription(int tagType)
149 {
[6127]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";
[4231]158 }
159
[6127]160 @Nullable
[4231]161 public String getGpsDirectionReferenceDescription(int tagType)
162 {
[6127]163 final String value = _directory.getString(tagType);
164 if (value==null)
165 return null;
166 String gpsDistRef = value.trim();
[4231]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
[6127]176 @Nullable
[4231]177 public String getGpsSpeedRefDescription()
178 {
[6127]179 final String value = _directory.getString(GpsDirectory.TAG_GPS_SPEED_REF);
180 if (value==null)
181 return null;
182 String gpsSpeedRef = value.trim();
[4231]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
[6127]194 @Nullable
[4231]195 public String getGpsMeasureModeDescription()
196 {
[6127]197 final String value = _directory.getString(GpsDirectory.TAG_GPS_MEASURE_MODE);
198 if (value==null)
199 return null;
200 String gpsSpeedMeasureMode = value.trim();
[4231]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
[6127]210 @Nullable
[4231]211 public String getGpsStatusDescription()
212 {
[6127]213 final String value = _directory.getString(GpsDirectory.TAG_GPS_STATUS);
214 if (value==null)
215 return null;
216 String gpsStatus = value.trim();
[4231]217 if ("A".equalsIgnoreCase(gpsStatus)) {
[6127]218 return "Active (Measurement in progress)";
[4231]219 } else if ("V".equalsIgnoreCase(gpsStatus)) {
[6127]220 return "Void (Measurement Interoperability)";
[4231]221 } else {
222 return "Unknown (" + gpsStatus + ")";
223 }
224 }
225
[6127]226 @Nullable
227 public String getGpsAltitudeRefDescription()
[4231]228 {
[6127]229 Integer value = _directory.getInteger(GpsDirectory.TAG_GPS_ALTITUDE_REF);
230 if (value==null)
231 return null;
232 if (value == 0)
[4231]233 return "Sea level";
[6127]234 if (value == 1)
235 return "Below sea level";
236 return "Unknown (" + value + ")";
[4231]237 }
238
[6127]239 @Nullable
240 public String getGpsAltitudeDescription()
[4231]241 {
[6127]242 final Rational value = _directory.getRational(GpsDirectory.TAG_GPS_ALTITUDE);
243 if (value==null)
244 return null;
245 return value.intValue() + " metres";
[4231]246 }
[6127]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 }
[4231]271}
Note: See TracBrowser for help on using the repository browser.