| 1 | /*
|
|---|
| 2 | * Copyright 2002-2015 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 | */
|
|---|
| 21 | package com.drew.metadata.exif;
|
|---|
| 22 |
|
|---|
| 23 | import com.drew.lang.GeoLocation;
|
|---|
| 24 | import com.drew.lang.Rational;
|
|---|
| 25 | import com.drew.lang.annotations.NotNull;
|
|---|
| 26 | import com.drew.lang.annotations.Nullable;
|
|---|
| 27 | import com.drew.metadata.TagDescriptor;
|
|---|
| 28 |
|
|---|
| 29 | import java.text.DecimalFormat;
|
|---|
| 30 |
|
|---|
| 31 | import 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 | public 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 | int[] timeComponents = _directory.getIntArray(TAG_TIME_STAMP);
|
|---|
| 112 | return timeComponents == null ? null : String.format("%d:%d:%d UTC", timeComponents[0], timeComponents[1], timeComponents[2]);
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | @Nullable
|
|---|
| 116 | public String getGpsDestinationReferenceDescription()
|
|---|
| 117 | {
|
|---|
| 118 | final String value = _directory.getString(TAG_DEST_DISTANCE_REF);
|
|---|
| 119 | if (value == null)
|
|---|
| 120 | return null;
|
|---|
| 121 | String distanceRef = value.trim();
|
|---|
| 122 | if ("K".equalsIgnoreCase(distanceRef)) {
|
|---|
| 123 | return "kilometers";
|
|---|
| 124 | } else if ("M".equalsIgnoreCase(distanceRef)) {
|
|---|
| 125 | return "miles";
|
|---|
| 126 | } else if ("N".equalsIgnoreCase(distanceRef)) {
|
|---|
| 127 | return "knots";
|
|---|
| 128 | } else {
|
|---|
| 129 | return "Unknown (" + distanceRef + ")";
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | @Nullable
|
|---|
| 134 | public String getGpsDirectionDescription(int tagType)
|
|---|
| 135 | {
|
|---|
| 136 | Rational angle = _directory.getRational(tagType);
|
|---|
| 137 | // provide a decimal version of rational numbers in the description, to avoid strings like "35334/199 degrees"
|
|---|
| 138 | String value = angle != null
|
|---|
| 139 | ? new DecimalFormat("0.##").format(angle.doubleValue())
|
|---|
| 140 | : _directory.getString(tagType);
|
|---|
| 141 | return value == null || value.trim().length() == 0 ? null : value.trim() + " degrees";
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | @Nullable
|
|---|
| 145 | public String getGpsDirectionReferenceDescription(int tagType)
|
|---|
| 146 | {
|
|---|
| 147 | final String value = _directory.getString(tagType);
|
|---|
| 148 | if (value == null)
|
|---|
| 149 | return null;
|
|---|
| 150 | String gpsDistRef = value.trim();
|
|---|
| 151 | if ("T".equalsIgnoreCase(gpsDistRef)) {
|
|---|
| 152 | return "True direction";
|
|---|
| 153 | } else if ("M".equalsIgnoreCase(gpsDistRef)) {
|
|---|
| 154 | return "Magnetic direction";
|
|---|
| 155 | } else {
|
|---|
| 156 | return "Unknown (" + gpsDistRef + ")";
|
|---|
| 157 | }
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | @Nullable
|
|---|
| 161 | public String getGpsSpeedRefDescription()
|
|---|
| 162 | {
|
|---|
| 163 | final String value = _directory.getString(TAG_SPEED_REF);
|
|---|
| 164 | if (value == null)
|
|---|
| 165 | return null;
|
|---|
| 166 | String gpsSpeedRef = value.trim();
|
|---|
| 167 | if ("K".equalsIgnoreCase(gpsSpeedRef)) {
|
|---|
| 168 | return "kph";
|
|---|
| 169 | } else if ("M".equalsIgnoreCase(gpsSpeedRef)) {
|
|---|
| 170 | return "mph";
|
|---|
| 171 | } else if ("N".equalsIgnoreCase(gpsSpeedRef)) {
|
|---|
| 172 | return "knots";
|
|---|
| 173 | } else {
|
|---|
| 174 | return "Unknown (" + gpsSpeedRef + ")";
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | @Nullable
|
|---|
| 179 | public String getGpsMeasureModeDescription()
|
|---|
| 180 | {
|
|---|
| 181 | final String value = _directory.getString(TAG_MEASURE_MODE);
|
|---|
| 182 | if (value == null)
|
|---|
| 183 | return null;
|
|---|
| 184 | String gpsSpeedMeasureMode = value.trim();
|
|---|
| 185 | if ("2".equalsIgnoreCase(gpsSpeedMeasureMode)) {
|
|---|
| 186 | return "2-dimensional measurement";
|
|---|
| 187 | } else if ("3".equalsIgnoreCase(gpsSpeedMeasureMode)) {
|
|---|
| 188 | return "3-dimensional measurement";
|
|---|
| 189 | } else {
|
|---|
| 190 | return "Unknown (" + gpsSpeedMeasureMode + ")";
|
|---|
| 191 | }
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | @Nullable
|
|---|
| 195 | public String getGpsStatusDescription()
|
|---|
| 196 | {
|
|---|
| 197 | final String value = _directory.getString(TAG_STATUS);
|
|---|
| 198 | if (value == null)
|
|---|
| 199 | return null;
|
|---|
| 200 | String gpsStatus = value.trim();
|
|---|
| 201 | if ("A".equalsIgnoreCase(gpsStatus)) {
|
|---|
| 202 | return "Active (Measurement in progress)";
|
|---|
| 203 | } else if ("V".equalsIgnoreCase(gpsStatus)) {
|
|---|
| 204 | return "Void (Measurement Interoperability)";
|
|---|
| 205 | } else {
|
|---|
| 206 | return "Unknown (" + gpsStatus + ")";
|
|---|
| 207 | }
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | @Nullable
|
|---|
| 211 | public String getGpsAltitudeRefDescription()
|
|---|
| 212 | {
|
|---|
| 213 | return getIndexedDescription(TAG_ALTITUDE_REF, "Sea level", "Below sea level");
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | @Nullable
|
|---|
| 217 | public String getGpsAltitudeDescription()
|
|---|
| 218 | {
|
|---|
| 219 | final Rational value = _directory.getRational(TAG_ALTITUDE);
|
|---|
| 220 | return value == null ? null : value.intValue() + " metres";
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | @Nullable
|
|---|
| 224 | public String getGpsDifferentialDescription()
|
|---|
| 225 | {
|
|---|
| 226 | return getIndexedDescription(TAG_DIFFERENTIAL, "No Correction", "Differential Corrected");
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | @Nullable
|
|---|
| 230 | public String getDegreesMinutesSecondsDescription()
|
|---|
| 231 | {
|
|---|
| 232 | GeoLocation location = _directory.getGeoLocation();
|
|---|
| 233 | return location == null ? null : location.toDMSString();
|
|---|
| 234 | }
|
|---|
| 235 | }
|
|---|