package osm.jp.gpx;\r
\r
import java.io.*;\r
+import java.math.BigDecimal;\r
+import java.math.RoundingMode;\r
import java.nio.channels.FileChannel;\r
import java.text.DateFormat;\r
import java.text.DecimalFormat;\r
gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);\r
gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF, latitudeRef);\r
{\r
- double value = longitude;\r
- final double longitudeDegrees = (long) value;\r
- value %= 1;\r
- value *= 60.0;\r
- final double longitudeMinutes = (long) value;\r
- value %= 1;\r
- value *= 60.0;\r
- final double longitudeSeconds = value;\r
+ BigDecimal value = BigDecimal.valueOf(longitude);\r
+ \r
+ final double longitudeDegrees = (value.setScale(0, RoundingMode.DOWN)).doubleValue();\r
+ value = value.subtract(BigDecimal.valueOf(longitudeDegrees));\r
+ value = value.multiply(BigDecimal.valueOf(60));\r
+ final double longitudeMinutes = (value.setScale(0, RoundingMode.DOWN)).doubleValue();\r
+ value = value.subtract(BigDecimal.valueOf(longitudeMinutes));\r
+ value = value.multiply(BigDecimal.valueOf(60));\r
+ final double longitudeSeconds = (value.setScale(0, RoundingMode.DOWN)).doubleValue();\r
gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);\r
gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LONGITUDE,\r
RationalNumber.valueOf(longitudeDegrees),\r
RationalNumber.valueOf(longitudeSeconds));\r
}\r
{\r
- double value = latitude;\r
- final double latitudeDegrees = (long) value;\r
- value %= 1;\r
- value *= 60.0;\r
- final double latitudeMinutes = (long) value;\r
- value %= 1;\r
- value *= 60.0;\r
- final double latitudeSeconds = value;\r
- gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE);\r
+ BigDecimal value = BigDecimal.valueOf(latitude);\r
+ final double latitudeDegrees = (value.setScale(0, RoundingMode.DOWN)).doubleValue();\r
+ value = value.subtract(BigDecimal.valueOf(latitudeDegrees));\r
+ value = value.multiply(BigDecimal.valueOf(60));\r
+ final double latitudeMinutes = (value.setScale(0, RoundingMode.DOWN)).doubleValue();\r
+ value = value.subtract(BigDecimal.valueOf(latitudeMinutes));\r
+ value = value.multiply(BigDecimal.valueOf(60));\r
+ final double latitudeSeconds = (value.setScale(0, RoundingMode.DOWN)).doubleValue(); gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE);\r
gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LATITUDE,\r
RationalNumber.valueOf(latitudeDegrees),\r
RationalNumber.valueOf(latitudeMinutes),\r
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.nio.channels.FileChannel;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
// in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
- new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808881603D, 137.9979396332D, true),
+ new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true),
// out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
new Expecter("separate/20170529_102409A.jpg", false, null, 90.0D, 180.0D, false),
// in TRKSEG(1) (2017-05-29T01:23:18 - 2017-05-29T01:24:05)
new Expecter("separate/20170529_102318A.jpg", true, "2017:05:29 10:23:18", 35.8812697884D, 137.9952202085D, true),
new Expecter("separate/20170529_102322A.jpg", true, "2017:05:29 10:23:22", 35.8810500987D, 137.9951669835D, true),
- new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808881603D, 137.9979396332D, true),
+ new Expecter("separate/20170529_102405A.jpg", true, "2017:05:29 10:24:05", 35.8808641881D, 137.9981065169D, true),
// out of time (2017-05-29T01:24:05 - 2017-05-29T01:24:37)
new Expecter("separate/20170529_102409A.jpg", true, "2017:05:29 10:24:09", 90.0D, 180.0D, true),
// LAT,LON
GPSInfo gpsInfo = exif.getGPS();
if (es[i].latD != 90.0D) {
- assertThat(round7(gpsInfo.getLatitudeAsDegreesNorth()), is(round7(es[i].latD)));
+ //assertThat(comparePosition(gpsInfo.getLatitudeAsDegreesNorth(), es[i].latD), is(true));
+ assertThat(String.format("%.7f", gpsInfo.getLatitudeAsDegreesNorth()), is(comparePosition(es[i].latD)));
}
if (es[i].lonD != 180.0D) {
- assertThat(round7(gpsInfo.getLongitudeAsDegreesEast()), is(round7(es[i].lonD)));
+ //assertThat(comparePosition(gpsInfo.getLongitudeAsDegreesEast(), es[i].lonD), is(true));
+ assertThat(String.format("%.7f", gpsInfo.getLongitudeAsDegreesEast()), is(comparePosition(es[i].lonD)));
}
}
}
}
+ static String comparePosition(double b) {
+ //System.out.println(String.format("a=%.10f : b=%.10f", a, b));
+
+ BigDecimal bB = BigDecimal.valueOf(b);
+ int degreesB = (bB.setScale(0, RoundingMode.DOWN)).intValue();
+ bB = bB.subtract(BigDecimal.valueOf(degreesB));
+ bB = bB.multiply(BigDecimal.valueOf(60));
+ int minutesB = (bB.setScale(0, RoundingMode.DOWN)).intValue();
+ bB = bB.subtract(BigDecimal.valueOf(minutesB));
+ bB = bB.multiply(BigDecimal.valueOf(60));
+ int secondsB = (bB.setScale(0, RoundingMode.DOWN)).intValue();
+
+ BigDecimal aB = BigDecimal.valueOf(secondsB);
+ aB = aB.divide(BigDecimal.valueOf(60), 7, RoundingMode.HALF_UP);
+ aB = aB.add(BigDecimal.valueOf(minutesB));
+ aB = aB.divide(BigDecimal.valueOf(60), 7, RoundingMode.HALF_UP);
+ aB = aB.add(BigDecimal.valueOf(degreesB));
+
+ /*
+ BigDecimal aB = BigDecimal.valueOf(a);
+ int degreesA = (aB.setScale(0, RoundingMode.DOWN)).intValue();
+ aB = aB.subtract(BigDecimal.valueOf(degreesA));
+ aB = aB.multiply(BigDecimal.valueOf(60));
+ int minutesA = (aB.setScale(0, RoundingMode.DOWN)).intValue();
+ aB = aB.subtract(BigDecimal.valueOf(minutesA));
+ aB = aB.multiply(BigDecimal.valueOf(60));
+ int secondsA = (aB.setScale(0, RoundingMode.DOWN)).intValue();
+ System.out.println(String.format("a=%2d : b=%2d", degreesA, degreesB));
+ if (degreesA != degreesB) {
+ return false;
+ }
+ System.out.println(String.format("a=%2d : b=%2d", minutesA, minutesB));
+ if (minutesA != minutesB) {
+ return false;
+ }
+ System.out.println(String.format("a=%2d : b=%2d", secondsA, secondsB));
+ if (secondsA != secondsB) {
+ return false;
+ }
+ return true;
+ */
+ return String.format("%.7f", aB.doubleValue());
+ }
+
/**
* 小数点第8位で四捨五入した文字列
* @param d