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

Last change on this file since 13722 was 13061, checked in by Don-vip, 7 years ago

fix #15505 - update to metadata-extractor 2.10.1

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