| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 28 |
import java.text.DateFormat; |
| 29 |
import java.text.ParseException; |
| 30 |
import java.text.SimpleDateFormat; |
| 31 |
import java.util.Date; |
| 32 |
import java.util.HashMap; |
| 33 |
import java.util.Locale; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
@SuppressWarnings("WeakerAccess") |
| 41 |
public class GpsDirectory extends ExifDirectoryBase |
| 42 |
{ |
| 43 |
|
| 44 |
public static final int TAG_VERSION_ID = 0x0000; |
| 45 |
|
| 46 |
public static final int TAG_LATITUDE_REF = 0x0001; |
| 47 |
|
| 48 |
public static final int TAG_LATITUDE = 0x0002; |
| 49 |
|
| 50 |
public static final int TAG_LONGITUDE_REF = 0x0003; |
| 51 |
|
| 52 |
public static final int TAG_LONGITUDE = 0x0004; |
| 53 |
|
| 54 |
public static final int TAG_ALTITUDE_REF = 0x0005; |
| 55 |
|
| 56 |
public static final int TAG_ALTITUDE = 0x0006; |
| 57 |
|
| 58 |
public static final int TAG_TIME_STAMP = 0x0007; |
| 59 |
|
| 60 |
public static final int TAG_SATELLITES = 0x0008; |
| 61 |
|
| 62 |
public static final int TAG_STATUS = 0x0009; |
| 63 |
|
| 64 |
public static final int TAG_MEASURE_MODE = 0x000A; |
| 65 |
|
| 66 |
public static final int TAG_DOP = 0x000B; |
| 67 |
|
| 68 |
public static final int TAG_SPEED_REF = 0x000C; |
| 69 |
|
| 70 |
public static final int TAG_SPEED = 0x000D; |
| 71 |
|
| 72 |
public static final int TAG_TRACK_REF = 0x000E; |
| 73 |
|
| 74 |
public static final int TAG_TRACK = 0x000F; |
| 75 |
|
| 76 |
public static final int TAG_IMG_DIRECTION_REF = 0x0010; |
| 77 |
|
| 78 |
public static final int TAG_IMG_DIRECTION = 0x0011; |
| 79 |
|
| 80 |
public static final int TAG_MAP_DATUM = 0x0012; |
| 81 |
|
| 82 |
public static final int TAG_DEST_LATITUDE_REF = 0x0013; |
| 83 |
|
| 84 |
public static final int TAG_DEST_LATITUDE = 0x0014; |
| 85 |
|
| 86 |
public static final int TAG_DEST_LONGITUDE_REF = 0x0015; |
| 87 |
|
| 88 |
public static final int TAG_DEST_LONGITUDE = 0x0016; |
| 89 |
|
| 90 |
public static final int TAG_DEST_BEARING_REF = 0x0017; |
| 91 |
|
| 92 |
public static final int TAG_DEST_BEARING = 0x0018; |
| 93 |
|
| 94 |
public static final int TAG_DEST_DISTANCE_REF = 0x0019; |
| 95 |
|
| 96 |
public static final int TAG_DEST_DISTANCE = 0x001A; |
| 97 |
|
| 98 |
public static final int TAG_PROCESSING_METHOD = 0x001B; |
| 99 |
|
| 100 |
public static final int TAG_AREA_INFORMATION = 0x001C; |
| 101 |
|
| 102 |
public static final int TAG_DATE_STAMP = 0x001D; |
| 103 |
|
| 104 |
public static final int TAG_DIFFERENTIAL = 0x001E; |
| 105 |
|
| 106 |
public static final int TAG_H_POSITIONING_ERROR = 0x001F; |
| 107 |
|
| 108 |
@NotNull |
| 109 |
private static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>(); |
| 110 |
|
| 111 |
static |
| 112 |
{ |
| 113 |
addExifTagNames(_tagNameMap); |
| 114 |
|
| 115 |
_tagNameMap.put(TAG_VERSION_ID, "GPS Version ID"); |
| 116 |
_tagNameMap.put(TAG_LATITUDE_REF, "GPS Latitude Ref"); |
| 117 |
_tagNameMap.put(TAG_LATITUDE, "GPS Latitude"); |
| 118 |
_tagNameMap.put(TAG_LONGITUDE_REF, "GPS Longitude Ref"); |
| 119 |
_tagNameMap.put(TAG_LONGITUDE, "GPS Longitude"); |
| 120 |
_tagNameMap.put(TAG_ALTITUDE_REF, "GPS Altitude Ref"); |
| 121 |
_tagNameMap.put(TAG_ALTITUDE, "GPS Altitude"); |
| 122 |
_tagNameMap.put(TAG_TIME_STAMP, "GPS Time-Stamp"); |
| 123 |
_tagNameMap.put(TAG_SATELLITES, "GPS Satellites"); |
| 124 |
_tagNameMap.put(TAG_STATUS, "GPS Status"); |
| 125 |
_tagNameMap.put(TAG_MEASURE_MODE, "GPS Measure Mode"); |
| 126 |
_tagNameMap.put(TAG_DOP, "GPS DOP"); |
| 127 |
_tagNameMap.put(TAG_SPEED_REF, "GPS Speed Ref"); |
| 128 |
_tagNameMap.put(TAG_SPEED, "GPS Speed"); |
| 129 |
_tagNameMap.put(TAG_TRACK_REF, "GPS Track Ref"); |
| 130 |
_tagNameMap.put(TAG_TRACK, "GPS Track"); |
| 131 |
_tagNameMap.put(TAG_IMG_DIRECTION_REF, "GPS Img Direction Ref"); |
| 132 |
_tagNameMap.put(TAG_IMG_DIRECTION, "GPS Img Direction"); |
| 133 |
_tagNameMap.put(TAG_MAP_DATUM, "GPS Map Datum"); |
| 134 |
_tagNameMap.put(TAG_DEST_LATITUDE_REF, "GPS Dest Latitude Ref"); |
| 135 |
_tagNameMap.put(TAG_DEST_LATITUDE, "GPS Dest Latitude"); |
| 136 |
_tagNameMap.put(TAG_DEST_LONGITUDE_REF, "GPS Dest Longitude Ref"); |
| 137 |
_tagNameMap.put(TAG_DEST_LONGITUDE, "GPS Dest Longitude"); |
| 138 |
_tagNameMap.put(TAG_DEST_BEARING_REF, "GPS Dest Bearing Ref"); |
| 139 |
_tagNameMap.put(TAG_DEST_BEARING, "GPS Dest Bearing"); |
| 140 |
_tagNameMap.put(TAG_DEST_DISTANCE_REF, "GPS Dest Distance Ref"); |
| 141 |
_tagNameMap.put(TAG_DEST_DISTANCE, "GPS Dest Distance"); |
| 142 |
_tagNameMap.put(TAG_PROCESSING_METHOD, "GPS Processing Method"); |
| 143 |
_tagNameMap.put(TAG_AREA_INFORMATION, "GPS Area Information"); |
| 144 |
_tagNameMap.put(TAG_DATE_STAMP, "GPS Date Stamp"); |
| 145 |
_tagNameMap.put(TAG_DIFFERENTIAL, "GPS Differential"); |
| 146 |
_tagNameMap.put(TAG_H_POSITIONING_ERROR, "GPS Horizontal Positioning Error"); |
| 147 |
} |
| 148 |
|
| 149 |
public GpsDirectory() |
| 150 |
{ |
| 151 |
this.setDescriptor(new GpsDescriptor(this)); |
| 152 |
} |
| 153 |
|
| 154 |
@Override |
| 155 |
@NotNull |
| 156 |
public String getName() |
| 157 |
{ |
| 158 |
return "GPS"; |
| 159 |
} |
| 160 |
|
| 161 |
@Override |
| 162 |
@NotNull |
| 163 |
protected HashMap<Integer, String> getTagNameMap() |
| 164 |
{ |
| 165 |
return _tagNameMap; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
@Nullable |
| 175 |
public GeoLocation getGeoLocation() |
| 176 |
{ |
| 177 |
Rational[] latitudes = getRationalArray(TAG_LATITUDE); |
| 178 |
Rational[] longitudes = getRationalArray(TAG_LONGITUDE); |
| 179 |
String latitudeRef = getString(TAG_LATITUDE_REF); |
| 180 |
String longitudeRef = getString(TAG_LONGITUDE_REF); |
| 181 |
|
| 182 |
|
| 183 |
if (latitudes == null || latitudes.length != 3) |
| 184 |
return null; |
| 185 |
if (longitudes == null || longitudes.length != 3) |
| 186 |
return null; |
| 187 |
if (latitudeRef == null || longitudeRef == null) |
| 188 |
return null; |
| 189 |
|
| 190 |
Double lat = GeoLocation.degreesMinutesSecondsToDecimal(latitudes[0], latitudes[1], latitudes[2], latitudeRef.equalsIgnoreCase("S")); |
| 191 |
Double lon = GeoLocation.degreesMinutesSecondsToDecimal(longitudes[0], longitudes[1], longitudes[2], longitudeRef.equalsIgnoreCase("W")); |
| 192 |
|
| 193 |
|
| 194 |
if (lat == null || lon == null) |
| 195 |
return null; |
| 196 |
|
| 197 |
return new GeoLocation(lat, lon); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
@Nullable |
| 207 |
public Date getGpsDate() |
| 208 |
{ |
| 209 |
String date = getString(TAG_DATE_STAMP); |
| 210 |
Rational[] timeComponents = getRationalArray(TAG_TIME_STAMP); |
| 211 |
|
| 212 |
|
| 213 |
if (date == null) |
| 214 |
return null; |
| 215 |
if (timeComponents == null || timeComponents.length != 3) |
| 216 |
return null; |
| 217 |
|
| 218 |
String dateTime = String.format(Locale.US, "%s %02d:%02d:%02.3f UTC", |
| 219 |
date, timeComponents[0].intValue(), timeComponents[1].intValue(), timeComponents[2].doubleValue()); |
| 220 |
try { |
| 221 |
DateFormat parser = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss.S z"); |
| 222 |
return parser.parse(dateTime); |
| 223 |
} catch (ParseException e) { |
| 224 |
return null; |
| 225 |
} |
| 226 |
} |
| 227 |
} |