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

Last change on this file since 4231 was 4231, checked in by stoecker, 13 years ago

add signpost and metadata extractor code to repository directly

File size: 7.9 KB
Line 
1/*
2 * This is public domain software - that is, you can do whatever you want
3 * with it, and include it software that is licensed under the GNU or the
4 * BSD license, or whatever other licence you choose, including proprietary
5 * closed source licenses. I do ask that you leave this header in tact.
6 *
7 * If you make modifications to this code that you think would benefit the
8 * wider community, please send me a copy and I'll post it on my site.
9 *
10 * If you make use of this code, I'd appreciate hearing about it.
11 * drew@drewnoakes.com
12 * Latest version of this software kept at
13 * http://drewnoakes.com/
14 *
15 * Created by dnoakes on 12-Nov-2002 22:27:52 using IntelliJ IDEA.
16 */
17package com.drew.metadata.exif;
18
19import com.drew.lang.Rational;
20import com.drew.metadata.Directory;
21import com.drew.metadata.MetadataException;
22import com.drew.metadata.TagDescriptor;
23
24/**
25 *
26 */
27public class GpsDescriptor extends TagDescriptor
28{
29 public GpsDescriptor(Directory directory)
30 {
31 super(directory);
32 }
33
34 public String getDescription(int tagType) throws MetadataException
35 {
36 switch (tagType) {
37 case GpsDirectory.TAG_GPS_ALTITUDE:
38 return getGpsAltitudeDescription();
39 case GpsDirectory.TAG_GPS_ALTITUDE_REF:
40 return getGpsAltitudeRefDescription();
41 case GpsDirectory.TAG_GPS_STATUS:
42 return getGpsStatusDescription();
43 case GpsDirectory.TAG_GPS_MEASURE_MODE:
44 return getGpsMeasureModeDescription();
45 case GpsDirectory.TAG_GPS_SPEED_REF:
46 return getGpsSpeedRefDescription();
47 case GpsDirectory.TAG_GPS_TRACK_REF:
48 case GpsDirectory.TAG_GPS_IMG_DIRECTION_REF:
49 case GpsDirectory.TAG_GPS_DEST_BEARING_REF:
50 return getGpsDirectionReferenceDescription(tagType);
51 case GpsDirectory.TAG_GPS_TRACK:
52 case GpsDirectory.TAG_GPS_IMG_DIRECTION:
53 case GpsDirectory.TAG_GPS_DEST_BEARING:
54 return getGpsDirectionDescription(tagType);
55 case GpsDirectory.TAG_GPS_DEST_DISTANCE_REF:
56 return getGpsDestinationReferenceDescription();
57 case GpsDirectory.TAG_GPS_TIME_STAMP:
58 return getGpsTimeStampDescription();
59 // three rational numbers -- displayed in HH"MM"SS.ss
60 case GpsDirectory.TAG_GPS_LONGITUDE:
61 return getGpsLongitudeDescription();
62 case GpsDirectory.TAG_GPS_LATITUDE:
63 return getGpsLatitudeDescription();
64 default:
65 return _directory.getString(tagType);
66 }
67 }
68
69 public String getGpsLatitudeDescription() throws MetadataException
70 {
71 if (!_directory.containsTag(GpsDirectory.TAG_GPS_LATITUDE)) return null;
72 return getHoursMinutesSecondsDescription(GpsDirectory.TAG_GPS_LATITUDE);
73 }
74
75 public String getGpsLongitudeDescription() throws MetadataException
76 {
77 if (!_directory.containsTag(GpsDirectory.TAG_GPS_LONGITUDE)) return null;
78 return getHoursMinutesSecondsDescription(GpsDirectory.TAG_GPS_LONGITUDE);
79 }
80
81 public String getHoursMinutesSecondsDescription(int tagType) throws MetadataException
82 {
83 Rational[] components = _directory.getRationalArray(tagType);
84 // TODO create an HoursMinutesSecods class ??
85 int deg = components[0].intValue();
86 float min = components[1].floatValue();
87 float sec = components[2].floatValue();
88 // carry fractions of minutes into seconds -- thanks Colin Briton
89 sec += (min % 1) * 60;
90 return String.valueOf(deg) + "\"" + String.valueOf((int)min) + "'" + String.valueOf(sec);
91 }
92
93 public String getGpsTimeStampDescription() throws MetadataException
94 {
95 // time in hour, min, sec
96 if (!_directory.containsTag(GpsDirectory.TAG_GPS_TIME_STAMP)) return null;
97 int[] timeComponents = _directory.getIntArray(GpsDirectory.TAG_GPS_TIME_STAMP);
98 StringBuffer sbuffer = new StringBuffer();
99 sbuffer.append(timeComponents[0]);
100 sbuffer.append(":");
101 sbuffer.append(timeComponents[1]);
102 sbuffer.append(":");
103 sbuffer.append(timeComponents[2]);
104 sbuffer.append(" UTC");
105 return sbuffer.toString();
106 }
107
108 public String getGpsDestinationReferenceDescription()
109 {
110 if (!_directory.containsTag(GpsDirectory.TAG_GPS_DEST_DISTANCE_REF)) return null;
111 String destRef = _directory.getString(GpsDirectory.TAG_GPS_DEST_DISTANCE_REF).trim();
112 if ("K".equalsIgnoreCase(destRef)) {
113 return "kilometers";
114 } else if ("M".equalsIgnoreCase(destRef)) {
115 return "miles";
116 } else if ("N".equalsIgnoreCase(destRef)) {
117 return "knots";
118 } else {
119 return "Unknown (" + destRef + ")";
120 }
121 }
122
123 public String getGpsDirectionDescription(int tagType)
124 {
125 if (!_directory.containsTag(tagType)) return null;
126 String gpsDirection = _directory.getString(tagType).trim();
127 return gpsDirection + " degrees";
128 }
129
130 public String getGpsDirectionReferenceDescription(int tagType)
131 {
132 if (!_directory.containsTag(tagType)) return null;
133 String gpsDistRef = _directory.getString(tagType).trim();
134 if ("T".equalsIgnoreCase(gpsDistRef)) {
135 return "True direction";
136 } else if ("M".equalsIgnoreCase(gpsDistRef)) {
137 return "Magnetic direction";
138 } else {
139 return "Unknown (" + gpsDistRef + ")";
140 }
141 }
142
143 public String getGpsSpeedRefDescription()
144 {
145 if (!_directory.containsTag(GpsDirectory.TAG_GPS_SPEED_REF)) return null;
146 String gpsSpeedRef = _directory.getString(GpsDirectory.TAG_GPS_SPEED_REF).trim();
147 if ("K".equalsIgnoreCase(gpsSpeedRef)) {
148 return "kph";
149 } else if ("M".equalsIgnoreCase(gpsSpeedRef)) {
150 return "mph";
151 } else if ("N".equalsIgnoreCase(gpsSpeedRef)) {
152 return "knots";
153 } else {
154 return "Unknown (" + gpsSpeedRef + ")";
155 }
156 }
157
158 public String getGpsMeasureModeDescription()
159 {
160 if (!_directory.containsTag(GpsDirectory.TAG_GPS_MEASURE_MODE)) return null;
161 String gpsSpeedMeasureMode = _directory.getString(GpsDirectory.TAG_GPS_MEASURE_MODE).trim();
162 if ("2".equalsIgnoreCase(gpsSpeedMeasureMode)) {
163 return "2-dimensional measurement";
164 } else if ("3".equalsIgnoreCase(gpsSpeedMeasureMode)) {
165 return "3-dimensional measurement";
166 } else {
167 return "Unknown (" + gpsSpeedMeasureMode + ")";
168 }
169 }
170
171 public String getGpsStatusDescription()
172 {
173 if (!_directory.containsTag(GpsDirectory.TAG_GPS_STATUS)) return null;
174 String gpsStatus = _directory.getString(GpsDirectory.TAG_GPS_STATUS).trim();
175 if ("A".equalsIgnoreCase(gpsStatus)) {
176 return "Measurement in progess";
177 } else if ("V".equalsIgnoreCase(gpsStatus)) {
178 return "Measurement Interoperability";
179 } else {
180 return "Unknown (" + gpsStatus + ")";
181 }
182 }
183
184 public String getGpsAltitudeRefDescription() throws MetadataException
185 {
186 if (!_directory.containsTag(GpsDirectory.TAG_GPS_ALTITUDE_REF)) return null;
187 int alititudeRef = _directory.getInt(GpsDirectory.TAG_GPS_ALTITUDE_REF);
188 if (alititudeRef == 0) {
189 return "Sea level";
190 } else {
191 return "Unknown (" + alititudeRef + ")";
192 }
193 }
194
195 public String getGpsAltitudeDescription() throws MetadataException
196 {
197 if (!_directory.containsTag(GpsDirectory.TAG_GPS_ALTITUDE)) return null;
198 String alititude = _directory.getRational(GpsDirectory.TAG_GPS_ALTITUDE).toSimpleString(true);
199 return alititude + " metres";
200 }
201}
Note: See TracBrowser for help on using the repository browser.