Changeset 8132 in josm for trunk/src/com/drew/metadata/exif/GpsDescriptor.java
- Timestamp:
- 2015-03-10T01:17:39+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/metadata/exif/GpsDescriptor.java
r6127 r8132 1 1 /* 2 * Copyright 2002-201 2Drew Noakes2 * Copyright 2002-2015 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 16 16 * More information about this project is available at: 17 17 * 18 * http ://drewnoakes.com/code/exif/19 * http ://code.google.com/p/metadata-extractor/18 * https://drewnoakes.com/code/exif/ 19 * https://github.com/drewnoakes/metadata-extractor 20 20 */ 21 21 package com.drew.metadata.exif; … … 29 29 import java.text.DecimalFormat; 30 30 31 import static com.drew.metadata.exif.GpsDirectory.*; 32 31 33 /** 32 * Provides human-readable string representations of tag values stored in a <code>GpsDirectory</code>.33 * 34 * @author Drew Noakes http ://drewnoakes.com34 * Provides human-readable string representations of tag values stored in a {@link GpsDirectory}. 35 * 36 * @author Drew Noakes https://drewnoakes.com 35 37 */ 36 38 public class GpsDescriptor extends TagDescriptor<GpsDirectory> … … 41 43 } 42 44 45 @Override 43 46 @Nullable 44 47 public String getDescription(int tagType) 45 48 { 46 49 switch (tagType) { 47 case GpsDirectory.TAG_GPS_VERSION_ID:50 case TAG_VERSION_ID: 48 51 return getGpsVersionIdDescription(); 49 case GpsDirectory.TAG_GPS_ALTITUDE:52 case TAG_ALTITUDE: 50 53 return getGpsAltitudeDescription(); 51 case GpsDirectory.TAG_GPS_ALTITUDE_REF:54 case TAG_ALTITUDE_REF: 52 55 return getGpsAltitudeRefDescription(); 53 case GpsDirectory.TAG_GPS_STATUS:56 case TAG_STATUS: 54 57 return getGpsStatusDescription(); 55 case GpsDirectory.TAG_GPS_MEASURE_MODE:58 case TAG_MEASURE_MODE: 56 59 return getGpsMeasureModeDescription(); 57 case GpsDirectory.TAG_GPS_SPEED_REF:60 case TAG_SPEED_REF: 58 61 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 case TAG_TRACK_REF: 63 case TAG_IMG_DIRECTION_REF: 64 case TAG_DEST_BEARING_REF: 62 65 return getGpsDirectionReferenceDescription(tagType); 63 case GpsDirectory.TAG_GPS_TRACK:64 case GpsDirectory.TAG_GPS_IMG_DIRECTION:65 case GpsDirectory.TAG_GPS_DEST_BEARING:66 case TAG_TRACK: 67 case TAG_IMG_DIRECTION: 68 case TAG_DEST_BEARING: 66 69 return getGpsDirectionDescription(tagType); 67 case GpsDirectory.TAG_GPS_DEST_DISTANCE_REF:70 case TAG_DEST_DISTANCE_REF: 68 71 return getGpsDestinationReferenceDescription(); 69 case GpsDirectory.TAG_GPS_TIME_STAMP:72 case TAG_TIME_STAMP: 70 73 return getGpsTimeStampDescription(); 71 case GpsDirectory.TAG_GPS_LONGITUDE:74 case TAG_LONGITUDE: 72 75 // three rational numbers -- displayed in HH"MM"SS.ss 73 76 return getGpsLongitudeDescription(); 74 case GpsDirectory.TAG_GPS_LATITUDE:77 case TAG_LATITUDE: 75 78 // three rational numbers -- displayed in HH"MM"SS.ss 76 79 return getGpsLatitudeDescription(); 77 case GpsDirectory.TAG_GPS_DIFFERENTIAL:80 case TAG_DIFFERENTIAL: 78 81 return getGpsDifferentialDescription(); 79 82 default: … … 85 88 private String getGpsVersionIdDescription() 86 89 { 87 return convertBytesToVersionString(_directory.getIntArray(GpsDirectory.TAG_GPS_VERSION_ID), 1);90 return getVersionBytesDescription(TAG_VERSION_ID, 1); 88 91 } 89 92 … … 92 95 { 93 96 GeoLocation location = _directory.getGeoLocation(); 94 95 if (location == null) 96 return null; 97 98 return GeoLocation.decimalToDegreesMinutesSecondsString(location.getLatitude()); 97 return location == null ? null : GeoLocation.decimalToDegreesMinutesSecondsString(location.getLatitude()); 99 98 } 100 99 … … 103 102 { 104 103 GeoLocation location = _directory.getGeoLocation(); 105 106 if (location == null) 107 return null; 108 109 return GeoLocation.decimalToDegreesMinutesSecondsString(location.getLongitude()); 104 return location == null ? null : GeoLocation.decimalToDegreesMinutesSecondsString(location.getLongitude()); 110 105 } 111 106 … … 114 109 { 115 110 // 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(); 111 int[] timeComponents = _directory.getIntArray(TAG_TIME_STAMP); 112 return timeComponents == null ? null : String.format("%d:%d:%d UTC", timeComponents[0], timeComponents[1], timeComponents[2]); 127 113 } 128 114 … … 130 116 public String getGpsDestinationReferenceDescription() 131 117 { 132 final String value = _directory.getString( GpsDirectory.TAG_GPS_DEST_DISTANCE_REF);133 if (value ==null)118 final String value = _directory.getString(TAG_DEST_DISTANCE_REF); 119 if (value == null) 134 120 return null; 135 121 String distanceRef = value.trim(); … … 151 137 // provide a decimal version of rational numbers in the description, to avoid strings like "35334/199 degrees" 152 138 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"; 139 ? new DecimalFormat("0.##").format(angle.doubleValue()) 140 : _directory.getString(tagType); 141 return value == null || value.trim().length() == 0 ? null : value.trim() + " degrees"; 158 142 } 159 143 … … 162 146 { 163 147 final String value = _directory.getString(tagType); 164 if (value ==null)148 if (value == null) 165 149 return null; 166 150 String gpsDistRef = value.trim(); … … 177 161 public String getGpsSpeedRefDescription() 178 162 { 179 final String value = _directory.getString( GpsDirectory.TAG_GPS_SPEED_REF);180 if (value ==null)163 final String value = _directory.getString(TAG_SPEED_REF); 164 if (value == null) 181 165 return null; 182 166 String gpsSpeedRef = value.trim(); … … 195 179 public String getGpsMeasureModeDescription() 196 180 { 197 final String value = _directory.getString( GpsDirectory.TAG_GPS_MEASURE_MODE);198 if (value ==null)181 final String value = _directory.getString(TAG_MEASURE_MODE); 182 if (value == null) 199 183 return null; 200 184 String gpsSpeedMeasureMode = value.trim(); … … 211 195 public String getGpsStatusDescription() 212 196 { 213 final String value = _directory.getString( GpsDirectory.TAG_GPS_STATUS);214 if (value ==null)197 final String value = _directory.getString(TAG_STATUS); 198 if (value == null) 215 199 return null; 216 200 String gpsStatus = value.trim(); … … 227 211 public String getGpsAltitudeRefDescription() 228 212 { 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 + ")"; 213 return getIndexedDescription(TAG_ALTITUDE_REF, "Sea level", "Below sea level"); 237 214 } 238 215 … … 240 217 public String getGpsAltitudeDescription() 241 218 { 242 final Rational value = _directory.getRational(GpsDirectory.TAG_GPS_ALTITUDE); 243 if (value==null) 244 return null; 245 return value.intValue() + " metres"; 219 final Rational value = _directory.getRational(TAG_ALTITUDE); 220 return value == null ? null : value.intValue() + " metres"; 246 221 } 247 222 … … 249 224 public String getGpsDifferentialDescription() 250 225 { 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 + ")"; 226 return getIndexedDescription(TAG_DIFFERENTIAL, "No Correction", "Differential Corrected"); 259 227 } 260 228 … … 263 231 { 264 232 GeoLocation location = _directory.getGeoLocation(); 265 266 if (location == null) 267 return null; 268 269 return location.toDMSString(); 233 return location == null ? null : location.toDMSString(); 270 234 } 271 235 }
Note:
See TracChangeset
for help on using the changeset viewer.