Changeset 6127 in josm for trunk/src/com/drew/metadata/exif/GpsDirectory.java
- Timestamp:
- 2013-08-09T18:05:11+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/metadata/exif/GpsDirectory.java
r4231 r6127 1 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. 2 * Copyright 2002-2012 Drew Noakes 6 3 * 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. 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 9 7 * 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/ 8 * http://www.apache.org/licenses/LICENSE-2.0 14 9 * 15 * Created by dnoakes on 26-Nov-2002 11:00:52 using IntelliJ IDEA. 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/ 16 20 */ 17 21 package com.drew.metadata.exif; 18 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; 19 27 import com.drew.metadata.Directory; 20 28 … … 22 30 23 31 /** 32 * Describes Exif tags that contain Global Positioning System (GPS) data. 24 33 * 34 * @author Drew Noakes http://drewnoakes.com 25 35 */ 26 36 public class GpsDirectory extends Directory … … 81 91 public static final int TAG_GPS_DEST_DISTANCE = 0x001A; 82 92 83 protected static final HashMap tagNameMap = new HashMap(); 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>(); 84 101 85 102 static 86 103 { 87 tagNameMap.put(new Integer(TAG_GPS_VERSION_ID), "GPS Version ID"); 88 tagNameMap.put(new Integer(TAG_GPS_LATITUDE_REF), "GPS Latitude Ref"); 89 tagNameMap.put(new Integer(TAG_GPS_LATITUDE), "GPS Latitude"); 90 tagNameMap.put(new Integer(TAG_GPS_LONGITUDE_REF), "GPS Longitude Ref"); 91 tagNameMap.put(new Integer(TAG_GPS_LONGITUDE), "GPS Longitude"); 92 tagNameMap.put(new Integer(TAG_GPS_ALTITUDE_REF), "GPS Altitude Ref"); 93 tagNameMap.put(new Integer(TAG_GPS_ALTITUDE), "GPS Altitude"); 94 tagNameMap.put(new Integer(TAG_GPS_TIME_STAMP), "GPS Time-Stamp"); 95 tagNameMap.put(new Integer(TAG_GPS_SATELLITES), "GPS Satellites"); 96 tagNameMap.put(new Integer(TAG_GPS_STATUS), "GPS Status"); 97 tagNameMap.put(new Integer(TAG_GPS_MEASURE_MODE), "GPS Measure Mode"); 98 tagNameMap.put(new Integer(TAG_GPS_DOP), "GPS DOP"); 99 tagNameMap.put(new Integer(TAG_GPS_SPEED_REF), "GPS Speed Ref"); 100 tagNameMap.put(new Integer(TAG_GPS_SPEED), "GPS Speed"); 101 tagNameMap.put(new Integer(TAG_GPS_TRACK_REF), "GPS Track Ref"); 102 tagNameMap.put(new Integer(TAG_GPS_TRACK), "GPS Track"); 103 tagNameMap.put(new Integer(TAG_GPS_IMG_DIRECTION_REF), "GPS Img Direction Ref"); 104 tagNameMap.put(new Integer(TAG_GPS_IMG_DIRECTION_REF), "GPS Img Direction"); 105 tagNameMap.put(new Integer(TAG_GPS_MAP_DATUM), "GPS Map Datum"); 106 tagNameMap.put(new Integer(TAG_GPS_DEST_LATITUDE_REF), "GPS Dest Latitude Ref"); 107 tagNameMap.put(new Integer(TAG_GPS_DEST_LATITUDE), "GPS Dest Latitude"); 108 tagNameMap.put(new Integer(TAG_GPS_DEST_LONGITUDE_REF), "GPS Dest Longitude Ref"); 109 tagNameMap.put(new Integer(TAG_GPS_DEST_LONGITUDE), "GPS Dest Longitude"); 110 tagNameMap.put(new Integer(TAG_GPS_DEST_BEARING_REF), "GPS Dest Bearing Ref"); 111 tagNameMap.put(new Integer(TAG_GPS_DEST_BEARING), "GPS Dest Bearing"); 112 tagNameMap.put(new Integer(TAG_GPS_DEST_DISTANCE_REF), "GPS Dest Distance Ref"); 113 tagNameMap.put(new Integer(TAG_GPS_DEST_DISTANCE), "GPS Dest Distance"); 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"); 114 135 } 115 136 … … 119 140 } 120 141 142 @NotNull 121 143 public String getName() 122 144 { … … 124 146 } 125 147 126 protected HashMap getTagNameMap() 148 @NotNull 149 protected HashMap<Integer, String> getTagNameMap() 127 150 { 128 return tagNameMap; 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); 129 184 } 130 185 }
Note:
See TracChangeset
for help on using the changeset viewer.
