source: josm/trunk/src/com/drew/metadata/exif/GpsDirectory.java@ 6209

Last change on this file since 6209 was 6127, checked in by bastiK, 11 years ago

applied #8895 - Upgrade metadata-extractor to v. 2.6.4 (patch by ebourg)

File size: 8.7 KB
Line 
1/*
2 * Copyright 2002-2012 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 * http://drewnoakes.com/code/exif/
19 * http://code.google.com/p/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.Directory;
28
29import java.util.HashMap;
30
31/**
32 * Describes Exif tags that contain Global Positioning System (GPS) data.
33 *
34 * @author Drew Noakes http://drewnoakes.com
35 */
36public class GpsDirectory extends Directory
37{
38 /** GPS tag version GPSVersionID 0 0 BYTE 4 */
39 public static final int TAG_GPS_VERSION_ID = 0x0000;
40 /** North or South Latitude GPSLatitudeRef 1 1 ASCII 2 */
41 public static final int TAG_GPS_LATITUDE_REF = 0x0001;
42 /** Latitude GPSLatitude 2 2 RATIONAL 3 */
43 public static final int TAG_GPS_LATITUDE = 0x0002;
44 /** East or West Longitude GPSLongitudeRef 3 3 ASCII 2 */
45 public static final int TAG_GPS_LONGITUDE_REF = 0x0003;
46 /** Longitude GPSLongitude 4 4 RATIONAL 3 */
47 public static final int TAG_GPS_LONGITUDE = 0x0004;
48 /** Altitude reference GPSAltitudeRef 5 5 BYTE 1 */
49 public static final int TAG_GPS_ALTITUDE_REF = 0x0005;
50 /** Altitude GPSAltitude 6 6 RATIONAL 1 */
51 public static final int TAG_GPS_ALTITUDE = 0x0006;
52 /** GPS time (atomic clock) GPSTimeStamp 7 7 RATIONAL 3 */
53 public static final int TAG_GPS_TIME_STAMP = 0x0007;
54 /** GPS satellites used for measurement GPSSatellites 8 8 ASCII Any */
55 public static final int TAG_GPS_SATELLITES = 0x0008;
56 /** GPS receiver status GPSStatus 9 9 ASCII 2 */
57 public static final int TAG_GPS_STATUS = 0x0009;
58 /** GPS measurement mode GPSMeasureMode 10 A ASCII 2 */
59 public static final int TAG_GPS_MEASURE_MODE = 0x000A;
60 /** Measurement precision GPSDOP 11 B RATIONAL 1 */
61 public static final int TAG_GPS_DOP = 0x000B;
62 /** Speed unit GPSSpeedRef 12 C ASCII 2 */
63 public static final int TAG_GPS_SPEED_REF = 0x000C;
64 /** Speed of GPS receiver GPSSpeed 13 D RATIONAL 1 */
65 public static final int TAG_GPS_SPEED = 0x000D;
66 /** Reference for direction of movement GPSTrackRef 14 E ASCII 2 */
67 public static final int TAG_GPS_TRACK_REF = 0x000E;
68 /** Direction of movement GPSTrack 15 F RATIONAL 1 */
69 public static final int TAG_GPS_TRACK = 0x000F;
70 /** Reference for direction of image GPSImgDirectionRef 16 10 ASCII 2 */
71 public static final int TAG_GPS_IMG_DIRECTION_REF = 0x0010;
72 /** Direction of image GPSImgDirection 17 11 RATIONAL 1 */
73 public static final int TAG_GPS_IMG_DIRECTION = 0x0011;
74 /** Geodetic survey data used GPSMapDatum 18 12 ASCII Any */
75 public static final int TAG_GPS_MAP_DATUM = 0x0012;
76 /** Reference for latitude of destination GPSDestLatitudeRef 19 13 ASCII 2 */
77 public static final int TAG_GPS_DEST_LATITUDE_REF = 0x0013;
78 /** Latitude of destination GPSDestLatitude 20 14 RATIONAL 3 */
79 public static final int TAG_GPS_DEST_LATITUDE = 0x0014;
80 /** Reference for longitude of destination GPSDestLongitudeRef 21 15 ASCII 2 */
81 public static final int TAG_GPS_DEST_LONGITUDE_REF = 0x0015;
82 /** Longitude of destination GPSDestLongitude 22 16 RATIONAL 3 */
83 public static final int TAG_GPS_DEST_LONGITUDE = 0x0016;
84 /** Reference for bearing of destination GPSDestBearingRef 23 17 ASCII 2 */
85 public static final int TAG_GPS_DEST_BEARING_REF = 0x0017;
86 /** Bearing of destination GPSDestBearing 24 18 RATIONAL 1 */
87 public static final int TAG_GPS_DEST_BEARING = 0x0018;
88 /** Reference for distance to destination GPSDestDistanceRef 25 19 ASCII 2 */
89 public static final int TAG_GPS_DEST_DISTANCE_REF = 0x0019;
90 /** Distance to destination GPSDestDistance 26 1A RATIONAL 1 */
91 public static final int TAG_GPS_DEST_DISTANCE = 0x001A;
92
93 /** Values of "GPS", "CELLID", "WLAN" or "MANUAL" by the EXIF spec. */
94 public static final int TAG_GPS_PROCESSING_METHOD = 0x001B;
95 public static final int TAG_GPS_AREA_INFORMATION = 0x001C;
96 public static final int TAG_GPS_DATE_STAMP = 0x001D;
97 public static final int TAG_GPS_DIFFERENTIAL = 0x001E;
98
99 @NotNull
100 protected static final HashMap<Integer, String> _tagNameMap = new HashMap<Integer, String>();
101
102 static
103 {
104 _tagNameMap.put(TAG_GPS_VERSION_ID, "GPS Version ID");
105 _tagNameMap.put(TAG_GPS_LATITUDE_REF, "GPS Latitude Ref");
106 _tagNameMap.put(TAG_GPS_LATITUDE, "GPS Latitude");
107 _tagNameMap.put(TAG_GPS_LONGITUDE_REF, "GPS Longitude Ref");
108 _tagNameMap.put(TAG_GPS_LONGITUDE, "GPS Longitude");
109 _tagNameMap.put(TAG_GPS_ALTITUDE_REF, "GPS Altitude Ref");
110 _tagNameMap.put(TAG_GPS_ALTITUDE, "GPS Altitude");
111 _tagNameMap.put(TAG_GPS_TIME_STAMP, "GPS Time-Stamp");
112 _tagNameMap.put(TAG_GPS_SATELLITES, "GPS Satellites");
113 _tagNameMap.put(TAG_GPS_STATUS, "GPS Status");
114 _tagNameMap.put(TAG_GPS_MEASURE_MODE, "GPS Measure Mode");
115 _tagNameMap.put(TAG_GPS_DOP, "GPS DOP");
116 _tagNameMap.put(TAG_GPS_SPEED_REF, "GPS Speed Ref");
117 _tagNameMap.put(TAG_GPS_SPEED, "GPS Speed");
118 _tagNameMap.put(TAG_GPS_TRACK_REF, "GPS Track Ref");
119 _tagNameMap.put(TAG_GPS_TRACK, "GPS Track");
120 _tagNameMap.put(TAG_GPS_IMG_DIRECTION_REF, "GPS Img Direction Ref");
121 _tagNameMap.put(TAG_GPS_IMG_DIRECTION, "GPS Img Direction");
122 _tagNameMap.put(TAG_GPS_MAP_DATUM, "GPS Map Datum");
123 _tagNameMap.put(TAG_GPS_DEST_LATITUDE_REF, "GPS Dest Latitude Ref");
124 _tagNameMap.put(TAG_GPS_DEST_LATITUDE, "GPS Dest Latitude");
125 _tagNameMap.put(TAG_GPS_DEST_LONGITUDE_REF, "GPS Dest Longitude Ref");
126 _tagNameMap.put(TAG_GPS_DEST_LONGITUDE, "GPS Dest Longitude");
127 _tagNameMap.put(TAG_GPS_DEST_BEARING_REF, "GPS Dest Bearing Ref");
128 _tagNameMap.put(TAG_GPS_DEST_BEARING, "GPS Dest Bearing");
129 _tagNameMap.put(TAG_GPS_DEST_DISTANCE_REF, "GPS Dest Distance Ref");
130 _tagNameMap.put(TAG_GPS_DEST_DISTANCE, "GPS Dest Distance");
131 _tagNameMap.put(TAG_GPS_PROCESSING_METHOD, "GPS Processing Method");
132 _tagNameMap.put(TAG_GPS_AREA_INFORMATION, "GPS Area Information");
133 _tagNameMap.put(TAG_GPS_DATE_STAMP, "GPS Date Stamp");
134 _tagNameMap.put(TAG_GPS_DIFFERENTIAL, "GPS Differential");
135 }
136
137 public GpsDirectory()
138 {
139 this.setDescriptor(new GpsDescriptor(this));
140 }
141
142 @NotNull
143 public String getName()
144 {
145 return "GPS";
146 }
147
148 @NotNull
149 protected HashMap<Integer, String> getTagNameMap()
150 {
151 return _tagNameMap;
152 }
153
154 /**
155 * Parses various tags in an attempt to obtain a single object representing the latitude and longitude
156 * at which this image was captured.
157 *
158 * @return The geographical location of this image, if possible, otherwise null
159 */
160 @Nullable
161 public GeoLocation getGeoLocation()
162 {
163 Rational[] latitudes = getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);
164 Rational[] longitudes = getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);
165 String latitudeRef = getString(GpsDirectory.TAG_GPS_LATITUDE_REF);
166 String longitudeRef = getString(GpsDirectory.TAG_GPS_LONGITUDE_REF);
167
168 // Make sure we have the required values
169 if (latitudes == null || latitudes.length != 3)
170 return null;
171 if (longitudes == null || longitudes.length != 3)
172 return null;
173 if (latitudeRef == null || longitudeRef == null)
174 return null;
175
176 Double lat = GeoLocation.degreesMinutesSecondsToDecimal(latitudes[0], latitudes[1], latitudes[2], latitudeRef.equalsIgnoreCase("S"));
177 Double lon = GeoLocation.degreesMinutesSecondsToDecimal(longitudes[0], longitudes[1], longitudes[2], longitudeRef.equalsIgnoreCase("W"));
178
179 // This can return null, in cases where the conversion was not possible
180 if (lat == null || lon == null)
181 return null;
182
183 return new GeoLocation(lat, lon);
184 }
185}
Note: See TracBrowser for help on using the repository browser.