Commits

P_W999 committed dbd80ff

- fix support for different geo formats
- add forgotten GPSUtil class
- this will be v0.0.3

Comments (0)

Files changed (4)

src/be/pw/jexif/DemoApp.java

 
 		JExifInfo gpsInfo = tool.getInfo(gps);
 		//50.84791165546716N 4.350469368264016E == Bourse @ Brussels
-		gpsInfo.setGPSInfo("50.84791165546716", "N", "4.350469368264016", "E", "50", "0");
+		//gpsInfo.setGPSInfo("50.84791165546716", "N", "4.350469368264016", "E", "50", "0");
+		
+		//60.586967S 131.835938W == South Pacific Ocean
+		gpsInfo.setGPSInfo("60 35 13.08", "S", "131 50 9.38", "W", "100", "1");
 		tool.stop();
 		
 		LOG.info("Executing took {} ms", watch.elapsedTime(TimeUnit.MILLISECONDS));

src/be/pw/jexif/JExifTool.java

         try {
             LOG.trace("Starting readTagInfo");
             GPSUtil.validateGPSValues(valuesToWrite);
+            GPSUtil.formatGPSValues(valuesToWrite);
             action = ActionFactory.createTagWriteAction(file, valuesToWrite);
             String[] arguments = action.buildArguments();
             handler = new EventHandler();

src/be/pw/jexif/enums/tag/ExifGPS.java

  * @author phillip
  */
 public enum ExifGPS implements Tag {
-	GPSVERSIONID("GPSVersionID", false, false, false, INT8U), GPSLATITUDEREF("GPSLatitudeRef", false, false, false, STRING), GPSLATITUDE("GPSLatitude", false, false, false, RAT64U), GPSLONGITUDEREF("GPSLongitudeRef", false, false, false, STRING), GPSLONGITUDE("GPSLongitude", false, false, false, RAT64U), GPSALTITUDEREF("GPSAltitudeRef", false, false, false, INT8U), GPSALTITUDE("GPSAltitude", false, false, false, RAT64U), GPSTIMESTAMP("GPSTimeStamp", false, false, false, RAT64U), GPSSATELLITES("GPSSatellites", false, false, false, STRING), GPSSTATUS("GPSStatus", false, false, false, STRING), GPSMEASUREMODE("GPSMeasureMode", false, false, false, STRING), GPSDOP("GPSDOP", false, false, false, RAT64U), GPSSPEEDREF("GPSSpeedRef", false, false, false, STRING), GPSSPEED("GPSSpeed", false, false, false, RAT64U), GPSTRACKREF("GPSTrackRef", false, false, false, STRING), GPSTRACK("GPSTrack", false, false, false, RAT64U), GPSIMGDIRECTIONREF("GPSImgDirectionRef", false, false, false, STRING), GPSIMGDIRECTION("GPSImgDirection", false, false, false, RAT64U), GPSMAPDATUM("GPSMapDatum", false, false, false, STRING), GPSDESTLATITUDEREF("GPSDestLatitudeRef", false, false, false, STRING), GPSDESTLATITUDE("GPSDestLatitude", false, false, false, RAT64U), GPSDESTLONGITUDEREF("GPSDestLongitudeRef", false, false, false, STRING), GPSDESTLONGITUDE("GPSDestLongitude", false, false, false, RAT64U), GPSDESTBEARINGREF("GPSDestBearingRef", false, false, false, STRING), GPSDESTBEARING("GPSDestBearing", false, false, false, RAT64U), GPSDESTDISTANCEREF("GPSDestDistanceRef", false, false, false, STRING), GPSDESTDISTANCE("GPSDestDistance", false, false, false, RAT64U), GPSPROCESSINGMETHOD("GPSProcessingMethod", false, false, false, UNDEF), GPSAREAINFORMATION("GPSAreaInformation", false, false, false, UNDEF), GPSDATESTAMP("GPSDateStamp", false, false, false, STRING), GPSDIFFERENTIAL("GPSDifferential", false, false, false, INT16U), GPSHPOSITIONINGERROR("GPSHPositioningError", false, false, false, RAT64U);
+	GPSVERSIONID("GPSVersionID", false, false, false, INT8U), GPSLATITUDEREF("GPSLatitudeRef", false, false, false, STRING), GPSLATITUDE("GPSLatitude", false, false, false, STRING), GPSLONGITUDEREF("GPSLongitudeRef", false, false, false, STRING), GPSLONGITUDE("GPSLongitude", false, false, false, STRING), GPSALTITUDEREF("GPSAltitudeRef", false, false, false, INT8U), GPSALTITUDE("GPSAltitude", false, false, false, RAT64U), GPSTIMESTAMP("GPSTimeStamp", false, false, false, RAT64U), GPSSATELLITES("GPSSatellites", false, false, false, STRING), GPSSTATUS("GPSStatus", false, false, false, STRING), GPSMEASUREMODE("GPSMeasureMode", false, false, false, STRING), GPSDOP("GPSDOP", false, false, false, RAT64U), GPSSPEEDREF("GPSSpeedRef", false, false, false, STRING), GPSSPEED("GPSSpeed", false, false, false, RAT64U), GPSTRACKREF("GPSTrackRef", false, false, false, STRING), GPSTRACK("GPSTrack", false, false, false, RAT64U), GPSIMGDIRECTIONREF("GPSImgDirectionRef", false, false, false, STRING), GPSIMGDIRECTION("GPSImgDirection", false, false, false, RAT64U), GPSMAPDATUM("GPSMapDatum", false, false, false, STRING), GPSDESTLATITUDEREF("GPSDestLatitudeRef", false, false, false, STRING), GPSDESTLATITUDE("GPSDestLatitude", false, false, false, RAT64U), GPSDESTLONGITUDEREF("GPSDestLongitudeRef", false, false, false, STRING), GPSDESTLONGITUDE("GPSDestLongitude", false, false, false, RAT64U), GPSDESTBEARINGREF("GPSDestBearingRef", false, false, false, STRING), GPSDESTBEARING("GPSDestBearing", false, false, false, RAT64U), GPSDESTDISTANCEREF("GPSDestDistanceRef", false, false, false, STRING), GPSDESTDISTANCE("GPSDestDistance", false, false, false, RAT64U), GPSPROCESSINGMETHOD("GPSProcessingMethod", false, false, false, UNDEF), GPSAREAINFORMATION("GPSAreaInformation", false, false, false, UNDEF), GPSDATESTAMP("GPSDateStamp", false, false, false, STRING), GPSDIFFERENTIAL("GPSDifferential", false, false, false, INT16U), GPSHPOSITIONINGERROR("GPSHPositioningError", false, false, false, RAT64U);
 
 	private final boolean avoided;
 	private final boolean unsafe;

src/be/pw/jexif/internal/util/GPSUtil.java

+/*******************************************************************************
+ * Copyright 2012 P_W999
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package be.pw.jexif.internal.util;
+
+import java.text.Format;
+import java.util.Map;
+import java.util.logging.SimpleFormatter;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import be.pw.jexif.enums.Errors;
+import be.pw.jexif.enums.tag.ExifGPS;
+import be.pw.jexif.enums.tag.Tag;
+import be.pw.jexif.exception.JExifValidationException;
+
+public class GPSUtil {
+
+	public static void validateGPSValues(final Map<Tag, String> valuesToValidate) throws JExifValidationException {
+		boolean allEmpty = true;
+		boolean allFilledIn = true;
+		allEmpty = valuesToValidate.get(ExifGPS.GPSALTITUDE) == null && 
+				valuesToValidate.get(ExifGPS.GPSALTITUDEREF) == null &&
+				valuesToValidate.get(ExifGPS.GPSLONGITUDE) == null &&
+				valuesToValidate.get(ExifGPS.GPSLONGITUDEREF) == null &&
+				valuesToValidate.get(ExifGPS.GPSLATITUDE) == null &&
+				valuesToValidate.get(ExifGPS.GPSLATITUDEREF) == null;
+		allFilledIn = valuesToValidate.get(ExifGPS.GPSALTITUDE) != null && 
+				valuesToValidate.get(ExifGPS.GPSALTITUDEREF) != null &&
+				valuesToValidate.get(ExifGPS.GPSLONGITUDE) != null &&
+				valuesToValidate.get(ExifGPS.GPSLONGITUDEREF) != null &&
+				valuesToValidate.get(ExifGPS.GPSLATITUDE) != null &&
+				valuesToValidate.get(ExifGPS.GPSLATITUDEREF) != null;
+		
+		if (!allEmpty && !allFilledIn) {
+			throw new JExifValidationException(Cal10nUtil.get(Errors.GPS_MISSING_FIELD));
+		}
+	}
+	
+	public static void formatGPSValues(final Map<Tag, String> valuesToAlter) {
+		String lon = valuesToAlter.get(ExifGPS.GPSLONGITUDE);
+		String lat = valuesToAlter.get(ExifGPS.GPSLATITUDE);
+		if (lon != null && lon.trim().contains(" ")) {
+			lon = DMSToDecimal(lon);
+			valuesToAlter.put(ExifGPS.GPSLONGITUDE, lon);
+		}
+		if (lat != null && lat.trim().contains(" ")) {
+			lat = DMSToDecimal(lat);
+			valuesToAlter.put(ExifGPS.GPSLATITUDE, lat);
+		}
+		
+	}
+	
+	@VisibleForTesting
+	static String DMSToDecimal(final String DMS) {
+		String[] split = DMS.split("\\s");
+		Double d = 0.0;
+		Double m = 0.0;
+		Double s = 0.0;
+		Double decimal = 0.0;
+		if (split.length >= 1) {
+			d = Double.parseDouble(split[0]);
+		}
+		if (split.length >= 2) {
+			m = Double.parseDouble(split[1]);
+		}
+		if (split.length >= 3) {
+			s = Double.parseDouble(split[2]);
+		} 
+		decimal = d + (((60 * m) + s) / 3600.0);
+		return String.format("%.14f", decimal).replace(",", ".");
+		
+	}
+}