OSDN Git Service

FIX:EXIFに撮影方角を正しく付加できるようにした。
authorhayashi yuu <hayashi.yuu@gmail.com>
Sun, 26 Jul 2015 10:28:15 +0000 (19:28 +0900)
committerhayashi yuu <hayashi.yuu@gmail.com>
Sun, 26 Jul 2015 10:28:15 +0000 (19:28 +0900)
importPicture/src/osm/jp/gpx/ImportPicture.java

index e56c698..5c14a62 100644 (file)
@@ -9,10 +9,10 @@ import java.util.Calendar;
 import java.util.Comparator;\r
 import java.util.Date;\r
 import java.util.GregorianCalendar;\r
-import java.util.HashMap;\r
 import java.util.Iterator;\r
 import java.util.Set;\r
 import java.util.TimeZone;\r
+import java.util.TreeMap;\r
 import java.util.logging.LogManager;\r
 import java.util.logging.Logger;\r
 \r
@@ -200,7 +200,7 @@ public class ImportPicture {
             </wpt>\r
             </gpx>\r
             */\r
-            HashMap<Long,Element> map = new HashMap<>();\r
+            TreeMap<Long,Element> map = new TreeMap<>();\r
             Element trk = null;\r
             gpx    = builder.parse(gpxFile).getFirstChild();\r
             NodeList nodes = gpx.getChildNodes();\r
@@ -270,7 +270,7 @@ public class ImportPicture {
      * @throws ImageReadException \r
      * @throws ImageWriteException \r
      */\r
-    static void proc(File dir, long delta, long gpxStartTime, long gpxEndTime, HashMap<Long,Element> map, boolean exifWrite, Node gpx) throws ParseException, ImageReadException, IOException, ImageWriteException {\r
+    static void proc(File dir, long delta, long gpxStartTime, long gpxEndTime, TreeMap<Long,Element> map, boolean exifWrite, Node gpx) throws ParseException, ImageReadException, IOException, ImageWriteException {\r
         DecimalFormat yearFormatter = new DecimalFormat("0000");\r
         DecimalFormat monthFormatter = new DecimalFormat("00");\r
         DecimalFormat dayFormatter = new DecimalFormat("00");\r
@@ -462,7 +462,7 @@ public class ImportPicture {
      * @param map\r
      * @throws ParseException\r
      */\r
-    public static void trkptMap(Element trk, HashMap<Long,Element> map) throws ParseException {\r
+    public static void trkptMap(Element trk, TreeMap<Long,Element> map) throws ParseException {\r
         dfuk.setTimeZone(TimeZone.getTimeZone("GMT"));\r
 \r
         NodeList nodes1 = trk.getChildNodes();\r
@@ -510,8 +510,8 @@ public class ImportPicture {
      * @param jptime\r
      * @throws ParseException\r
      */\r
-    public static Element trkpt(HashMap<Long,Element> map, Date jptime) throws ParseException {\r
-        Double R = 20000000 / Math.PI;                  // 地球の半径(m)\r
+    public static Element trkpt(TreeMap<Long,Element> map, Date jptime) throws ParseException {\r
+        Double R = 20000000 / Math.PI;\r
         long sa = 2L * 3600000L;\r
         long jpt = jptime.getTime();\r
         Element ret = null;\r
@@ -572,20 +572,25 @@ public class ImportPicture {
                                         break;\r
                                 }\r
                             }\r
-                            Double dLON = imaLON - maeLON;\r
-                            Double dLAT = imaLAT - maeLAT;\r
-                            Double r = Math.cos(Math.toRadians((imaLAT + maeLAT) * 2)) * R;\r
+                            Double r = Math.cos(Math.toRadians((imaLAT + maeLAT) / 2)) * R;\r
                             Double x = Math.toRadians(imaLON - maeLON) * r;\r
                             Double y = Math.toRadians(imaLAT - maeLAT) * R;\r
-                            double rad = Math.toDegrees(Math.atan(y / x));\r
+                            double rad = Math.toDegrees(Math.atan2(y, x));\r
                             \r
-                            if (y < 0) {\r
-                                rad = rad * -1;\r
-                                if (x > 0) {\r
-                                    rad = rad + 90;\r
+                            if (y >= 0) {\r
+                                if (x >= 0) {\r
+                                    rad = 0 - (rad - 90);\r
                                 }\r
                                 else {\r
-                                    rad = rad - 90;\r
+                                    rad = 360 - (rad - 90);\r
+                                }\r
+                            }\r
+                            else {\r
+                                if (x >= 0) {\r
+                                    rad = 90 - rad;\r
+                                }\r
+                                else {\r
+                                    rad = 90 - rad;\r
                                 }\r
                             }\r
 \r
@@ -597,6 +602,15 @@ public class ImportPicture {
                             }\r
                             magvar.setTextContent(str);\r
                             ret.appendChild(magvar);\r
+                            \r
+                            Element speed = ret.getOwnerDocument().createElement("speed");\r
+                            str = Double.toString(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));\r
+                            iDot = str.indexOf('.');\r
+                            if (iDot > 0) {\r
+                                str = str.substring(0, iDot);\r
+                            }\r
+                            speed.setTextContent(str);\r
+                            ret.appendChild(speed);\r
                         }\r
                     }\r
                 }\r