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

Last change on this file since 10862 was 10862, checked in by Don-vip, 8 years ago

update to metadata-extractor 2.9.1

File size: 8.0 KB
Line 
1/*
2 * Copyright 2002-2016 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 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/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
31import static com.drew.metadata.exif.GpsDirectory.*;
32
33/**
34 * Provides human-readable string representations of tag values stored in a {@link GpsDirectory}.
35 *
36 * @author Drew Noakes https://drewnoakes.com
37 */
38public class GpsDescriptor extends TagDescriptor<GpsDirectory>
39{
40 public GpsDescriptor(@NotNull GpsDirectory directory)
41 {
42 super(directory);
43 }
44
45 @Override
46 @Nullable
47 public String getDescription(int tagType)
48 {
49 switch (tagType) {
50 case TAG_VERSION_ID:
51 return getGpsVersionIdDescription();
52 case TAG_ALTITUDE:
53 return getGpsAltitudeDescription();
54 case TAG_ALTITUDE_REF:
55 return getGpsAltitudeRefDescription();
56 case TAG_STATUS:
57 return getGpsStatusDescription();
58 case TAG_MEASURE_MODE:
59 return getGpsMeasureModeDescription();
60 case TAG_SPEED_REF:
61 return getGpsSpeedRefDescription();
62 case TAG_TRACK_REF:
63 case TAG_IMG_DIRECTION_REF:
64 case TAG_DEST_BEARING_REF:
65 return getGpsDirectionReferenceDescription(tagType);
66 case TAG_TRACK:
67 case TAG_IMG_DIRECTION:
68 case TAG_DEST_BEARING:
69 return getGpsDirectionDescription(tagType);
70 case TAG_DEST_DISTANCE_REF:
71 return getGpsDestinationReferenceDescription();
72 case TAG_TIME_STAMP:
73 return getGpsTimeStampDescription();
74 case TAG_LONGITUDE:
75 // three rational numbers -- displayed in HH"MM"SS.ss
76 return getGpsLongitudeDescription();
77 case TAG_LATITUDE:
78 // three rational numbers -- displayed in HH"MM"SS.ss
79 return getGpsLatitudeDescription();
80 case TAG_DIFFERENTIAL:
81 return getGpsDifferentialDescription();
82 default:
83 return super.getDescription(tagType);
84 }
85 }
86
87 @Nullable
88 private String getGpsVersionIdDescription()
89 {
90 return getVersionBytesDescription(TAG_VERSION_ID, 1);
91 }
92
93 @Nullable
94 public String getGpsLatitudeDescription()
95 {
96 GeoLocation location = _directory.getGeoLocation();
97 return location == null ? null : GeoLocation.decimalToDegreesMinutesSecondsString(location.getLatitude());
98 }
99
100 @Nullable
101 public String getGpsLongitudeDescription()
102 {
103 GeoLocation location = _directory.getGeoLocation();
104 return location == null ? null : GeoLocation.decimalToDegreesMinutesSecondsString(location.getLongitude());
105 }
106
107 @Nullable
108 public String getGpsTimeStampDescription()
109 {
110 // time in hour, min, sec
111 Rational[] timeComponents = _directory.getRationalArray(TAG_TIME_STAMP);
112 DecimalFormat df = new DecimalFormat("00.000");
113 return timeComponents == null
114 ? null
115 : String.format("%02d:%02d:%s UTC",
116 timeComponents[0].intValue(),
117 timeComponents[1].intValue(),
118 df.format(timeComponents[2].doubleValue()));
119 }
120
121 @Nullable
122 public String getGpsDestinationReferenceDescription()
123 {
124 final String value = _directory.getString(TAG_DEST_DISTANCE_REF);
125 if (value == null)
126 return null;
127 String distanceRef = value.trim();
128 if ("K".equalsIgnoreCase(distanceRef)) {
129 return "kilometers";
130 } else if ("M".equalsIgnoreCase(distanceRef)) {
131 return "miles";
132 } else if ("N".equalsIgnoreCase(distanceRef)) {
133 return "knots";
134 } else {
135 return "Unknown (" + distanceRef + ")";
136 }
137 }
138
139 @Nullable
140 public String getGpsDirectionDescription(int tagType)
141 {
142 Rational angle = _directory.getRational(tagType);
143 // provide a decimal version of rational numbers in the description, to avoid strings like "35334/199 degrees"
144 String value = angle != null
145 ? new DecimalFormat("0.##").format(angle.doubleValue())
146 : _directory.getString(tagType);
147 return value == null || value.trim().length() == 0 ? null : value.trim() + " degrees";
148 }
149
150 @Nullable
151 public String getGpsDirectionReferenceDescription(int tagType)
152 {
153 final String value = _directory.getString(tagType);
154 if (value == null)
155 return null;
156 String gpsDistRef = value.trim();
157 if ("T".equalsIgnoreCase(gpsDistRef)) {
158 return "True direction";
159 } else if ("M".equalsIgnoreCase(gpsDistRef)) {
160 return "Magnetic direction";
161 } else {
162 return "Unknown (" + gpsDistRef + ")";
163 }
164 }
165
166 @Nullable
167 public String getGpsSpeedRefDescription()
168 {
169 final String value = _directory.getString(TAG_SPEED_REF);
170 if (value == null)
171 return null;
172 String gpsSpeedRef = value.trim();
173 if ("K".equalsIgnoreCase(gpsSpeedRef)) {
174 return "kph";
175 } else if ("M".equalsIgnoreCase(gpsSpeedRef)) {
176 return "mph";
177 } else if ("N".equalsIgnoreCase(gpsSpeedRef)) {
178 return "knots";
179 } else {
180 return "Unknown (" + gpsSpeedRef + ")";
181 }
182 }
183
184 @Nullable
185 public String getGpsMeasureModeDescription()
186 {
187 final String value = _directory.getString(TAG_MEASURE_MODE);
188 if (value == null)
189 return null;
190 String gpsSpeedMeasureMode = value.trim();
191 if ("2".equalsIgnoreCase(gpsSpeedMeasureMode)) {
192 return "2-dimensional measurement";
193 } else if ("3".equalsIgnoreCase(gpsSpeedMeasureMode)) {
194 return "3-dimensional measurement";
195 } else {
196 return "Unknown (" + gpsSpeedMeasureMode + ")";
197 }
198 }
199
200 @Nullable
201 public String getGpsStatusDescription()
202 {
203 final String value = _directory.getString(TAG_STATUS);
204 if (value == null)
205 return null;
206 String gpsStatus = value.trim();
207 if ("A".equalsIgnoreCase(gpsStatus)) {
208 return "Active (Measurement in progress)";
209 } else if ("V".equalsIgnoreCase(gpsStatus)) {
210 return "Void (Measurement Interoperability)";
211 } else {
212 return "Unknown (" + gpsStatus + ")";
213 }
214 }
215
216 @Nullable
217 public String getGpsAltitudeRefDescription()
218 {
219 return getIndexedDescription(TAG_ALTITUDE_REF, "Sea level", "Below sea level");
220 }
221
222 @Nullable
223 public String getGpsAltitudeDescription()
224 {
225 final Rational value = _directory.getRational(TAG_ALTITUDE);
226 return value == null ? null : value.intValue() + " metres";
227 }
228
229 @Nullable
230 public String getGpsDifferentialDescription()
231 {
232 return getIndexedDescription(TAG_DIFFERENTIAL, "No Correction", "Differential Corrected");
233 }
234
235 @Nullable
236 public String getDegreesMinutesSecondsDescription()
237 {
238 GeoLocation location = _directory.getGeoLocation();
239 return location == null ? null : location.toDMSString();
240 }
241}
Note: See TracBrowser for help on using the repository browser.