OSDN Git Service

speed and magver
authoryuuhayashi <hayashi.yuu@gmail.com>
Mon, 3 Oct 2016 17:29:59 +0000 (02:29 +0900)
committeryuuhayashi <hayashi.yuu@gmail.com>
Mon, 3 Oct 2016 17:29:59 +0000 (02:29 +0900)
importPicture/src/LICENSE.txt
importPicture/src/osm/jp/gpx/Complementation.java
importPicture/src/osm/jp/gpx/Coords.java [new file with mode: 0644]
importPicture/src/osm/jp/gpx/ImportPicture.java

index 9586edf..24cc95a 100644 (file)
@@ -33,3 +33,10 @@ THE SOFTWARE.
 はありません。 作者または著作権者は、契約行為、不法行為、またはそれ以外であろうと、ソフトウェアに起因または
 関連し、あるいはソフトウェアの使用またはその他の扱いによって生じる一切の請求、損害、その他の義務について何
 らの責任も負わないものとします。
+
+----------------
+
+osm.jp.gpx.Cords.java は'やまだらけ'様の著作物です。
+       Copyright (C) 2007-2012   やまだらけ
+       The MIT License (MIT)
+       参照元: http://yamadarake.jp/trdi/report000001.html
index 7b1914f..a70daaf 100644 (file)
@@ -9,15 +9,34 @@ import org.w3c.dom.NodeList;
 
 public class Complementation {
 
+    /**
+     * 
+     *         <trkpt lat="34.976635" lon="138.466228">
+     *                 <ele>267.291</ele>
+     *                 <magvar>359</magvar>
+     *                 <speed></speed>
+     *                 <time>2016-07-02T08:25:18Z</time>
+     *         </trkpt>
+     * 
+     * @param trkseg
+     * @param map
+     * @throws ParseException
+     */
        public Complementation(Element imaE, Element maeE) throws ParseException {
         // <MAGVAR>がなければ、
         // 直前の位置と、現在地から進行方向を求める
         NodeList nodes3 = imaE.getChildNodes();
+        magvar = null;
+        speed = null;
         for (int i3=0; i3 < nodes3.getLength(); i3++) {
             Node node4 = nodes3.item(i3);
             String nodename = node4.getNodeName().toLowerCase();
             if (nodename.equals("magvar")) {
-                magvar = (Element) node4;
+               magvar = (Element)node4;
+                break;
+            }
+            else if (nodename.equals("speed")) {
+               speed = (Element)node4;
                 break;
             }
             else if (nodename.equals("time")) {
@@ -41,34 +60,36 @@ public class Complementation {
             }
         }
 
-        nodes3 = maeE.getChildNodes();
-        for (int i3=0; i3 < nodes3.getLength(); i3++) {
-            Node node4 = nodes3.item(i3);
-            if (node4.getNodeName().toLowerCase().equals("time")) {
-                String timeStr = node4.getTextContent();
-                maeTIME = ImportPicture.dfuk.parse(timeStr).getTime();
-                break;
+        if (maeE != null) {
+            nodes3 = maeE.getChildNodes();
+            for (int i3=0; i3 < nodes3.getLength(); i3++) {
+                Node node4 = nodes3.item(i3);
+                if (node4.getNodeName().toLowerCase().equals("time")) {
+                    String timeStr = node4.getTextContent();
+                    setMaeTIME(ImportPicture.dfuk.parse(timeStr).getTime());
+                    break;
+                }
             }
-        }
 
-        nodeMap = maeE.getAttributes();
-        for (int j=0; j < nodeMap.getLength(); j++ ) {
-            switch (nodeMap.item(j).getNodeName()) {
-                case "lat":
-                    String latStr = nodeMap.item(j).getNodeValue();
-                    maeLAT = new Double(latStr);
-                    break;
-                case "lon":
-                    String lonStr = nodeMap.item(j).getNodeValue();
-                    maeLON = new Double(lonStr);
-                    break;
+            nodeMap = maeE.getAttributes();
+            for (int j=0; j < nodeMap.getLength(); j++ ) {
+                switch (nodeMap.item(j).getNodeName()) {
+                    case "lat":
+                        String latStr = nodeMap.item(j).getNodeValue();
+                        maeLAT = new Double(latStr);
+                        break;
+                    case "lon":
+                        String lonStr = nodeMap.item(j).getNodeValue();
+                        maeLON = new Double(lonStr);
+                        break;
+                }
             }
         }
        }
 
-    public static final Double R = 20000000 / Math.PI;
-    public static final double dLat = 0.00453D;                        // 1km距離を表す緯度(差分)
-    public static final double dLon = 0.005588D;               // 1km距離を表す経度(差分)
+    public static final Double R = (6378137D + 6356752.314D)/2D;       // 6367444.657m
+    //public static final double dLat = 0.00453D;                      // 1km距離を表す緯度(差分)
+    //public static final double dLon = 0.005588D;             // 1km距離を表す経度(差分)
 
     public long imaTIME = 0L;
     public long maeTIME = 0L;
@@ -77,6 +98,7 @@ public class Complementation {
     public Double imaLAT = null;
     public Double imaLON =null;
     public Element magvar = null;
+    public Element speed = null;
     
     
     /**
@@ -84,13 +106,9 @@ public class Complementation {
      * 
      */
     public void complementationSpeed(Element imaE) throws ParseException {
-               double lon = (imaLON - maeLON);
-               lon = lon * dLon;
-               double lat = (imaLAT - maeLAT);
-               lat = lat * dLat;
-
         Element speed = imaE.getOwnerDocument().createElement("speed");
-        String str = Double.toString((Math.sqrt(Math.pow(lon, 2) + Math.pow(lat, 2)) / (imaTIME - maeTIME)));
+       double d = Coords.calcDistHubeny(imaLAT, imaLON, maeLAT, maeLON);
+        String str = Double.toString((d * 1000) / (imaTIME - maeTIME));
         int iDot = str.indexOf('.');
         if (iDot > 0) {
             str = str.substring(0, iDot+2);
@@ -175,6 +193,11 @@ public class Complementation {
                this.maeLON = maeLON;
        }
 
+       public int getMagvar() {
+        String magvarStr = magvar.getTextContent();
+               return Integer.getInteger(magvarStr);
+       }
+
        public Double getImaLAT() {
                return imaLAT;
        }
diff --git a/importPicture/src/osm/jp/gpx/Coords.java b/importPicture/src/osm/jp/gpx/Coords.java
new file mode 100644 (file)
index 0000000..a7d8672
--- /dev/null
@@ -0,0 +1,86 @@
+package osm.jp.gpx;
+
+/**
+ * The MIT License (MIT)
+ * Copyright(C) 2007-2012   やまだらけ
+ * http://yamadarake.jp/trdi/report000001.html
+ *   2016-10-03
+ * 
+ * @author やまだらけ yama_darake@yahoo.co.jp
+ *
+ */
+public class Coords {
+
+  public static final double BESSEL_A = 6377397.155;
+  public static final double BESSEL_E2 = 0.00667436061028297;
+  public static final double BESSEL_MNUM = 6334832.10663254;
+
+  public static final double GRS80_A = 6378137.000;
+  public static final double GRS80_E2 = 0.00669438002301188;
+  public static final double GRS80_MNUM = 6335439.32708317;
+
+  public static final double WGS84_A = 6378137.000;
+  public static final double WGS84_E2 = 0.00669437999019758;
+  public static final double WGS84_MNUM = 6335439.32729246;
+
+  public static final int BESSEL = 0;
+  public static final int GRS80 = 1;
+  public static final int WGS84 = 2;
+
+  public static double deg2rad(double deg){
+       return deg * Math.PI / 180.0;
+  }
+
+  public static double calcDistHubeny(double lat1, double lng1,
+                                      double lat2, double lng2,
+                                      double a, double e2, double mnum){
+    double my = deg2rad((lat1 + lat2) / 2.0);
+    double dy = deg2rad(lat1 - lat2);
+    double dx = deg2rad(lng1 - lng2);
+
+    double sin = Math.sin(my);
+    double w = Math.sqrt(1.0 - e2 * sin * sin);
+    double m = mnum / (w * w * w);
+    double n = a / w;
+       
+    double dym = dy * m;
+    double dxncos = dx * n * Math.cos(my);
+
+    return Math.sqrt(dym * dym + dxncos * dxncos);
+  }
+
+  public static double calcDistHubeny(double lat1, double lng1,
+                                      double lat2, double lng2){
+    return calcDistHubeny(lat1, lng1, lat2, lng2,
+                          GRS80_A, GRS80_E2, GRS80_MNUM);
+  }
+
+  public static double calcDistHubery(double lat1, double lng1,
+                                      double lat2, double lng2, int type){
+    switch(type){
+      case BESSEL:
+        return calcDistHubeny(lat1, lng1, lat2, lng2,
+                              BESSEL_A, BESSEL_E2, BESSEL_MNUM);
+      case WGS84:
+        return calcDistHubeny(lat1, lng1, lat2, lng2,
+                              WGS84_A, WGS84_E2, WGS84_MNUM);
+      default:
+        return calcDistHubeny(lat1, lng1, lat2, lng2,
+                              GRS80_A, GRS80_E2, GRS80_MNUM);
+     }
+  }
+  
+  public static void main(String[] args){
+    System.out.println("Coords Test Program");
+    double lat1, lng1, lat2, lng2;
+
+    lat1 = Double.parseDouble(args[0]);
+    lng1 = Double.parseDouble(args[1]);
+    lat2 = Double.parseDouble(args[2]);
+    lng2 = Double.parseDouble(args[3]);
+
+    double d = calcDistHubeny(lat1, lng1, lat2, lng2);
+
+    System.out.println("Distance = " + d + " m");
+  }
+}
\ No newline at end of file
index 03ed192..e4bb2c9 100644 (file)
@@ -347,6 +347,7 @@ public class ImportPicture extends Thread {
         TreeMap<Long,Element> map = new TreeMap<>();\r
         TreeMap<Long,Element> mapTRKSEG = new TreeMap<>();\r
         Element trk = null;\r
+        Element maeTRKPT = null;\r
         gpx    = builder.parse(gpxFile).getFirstChild();\r
         Document doc = gpx.getOwnerDocument();\r
         NodeList nodes = gpx.getChildNodes();\r
@@ -370,6 +371,26 @@ public class ImportPicture extends Thread {
                                if (param_GpxNoFirstNode && (i2 == 0)) {\r
                                        continue;\r
                                }\r
+                               if (param_GpxOutputSpeed || param_GpxOverwriteMagvar) {\r
+                                       Complementation cmp = new Complementation((Element)nodeTRKPT, maeTRKPT);\r
+                                       if (param_GpxOutputSpeed) {\r
+                                               if (cmp.speed != null) {\r
+                                                       nodeTRKPT.removeChild(cmp.speed);\r
+                                               }\r
+                                               if (maeTRKPT != null) {\r
+                                                       cmp.complementationSpeed((Element)nodeTRKPT);\r
+                                               }\r
+                                       }\r
+                                       if (param_GpxOverwriteMagvar) {\r
+                                               if (cmp.magvar != null) {\r
+                                                       nodeTRKPT.removeChild(cmp.magvar);\r
+                                               }\r
+                                               if (maeTRKPT != null) {\r
+                                                       cmp.complementationMagvar((Element)nodeTRKPT);\r
+                                               }\r
+                                       }\r
+                               }\r
+                                maeTRKPT = getCopy(doc, nodeTRKPT);\r
                                newTRKSEG.appendChild(getCopy(doc, nodeTRKPT));\r
                             }\r
                         }\r
@@ -388,7 +409,7 @@ public class ImportPicture extends Thread {
                        Element newTRKSEG = mapTRKSEG.get(keyIte.next());\r
                     trk.appendChild(newTRKSEG);\r
                     \r
-                    // mapに、<trkpy>を割り付ける\r
+                    // mapに、<trkpt>を割り付ける\r
                     trkptMap(newTRKSEG, map);\r
                 }\r
             }\r
@@ -482,6 +503,7 @@ public class ImportPicture extends Thread {
                itime = new Date(lastModifyTime);\r
             }\r
 \r
+            // uktime <-- 画像撮影時刻に対応するGPX時刻\r
             Date uktime = new Date(itime.getTime() + delta);\r
             System.out.print(String.format("%20s ", dfjp.format(itime)));\r
             System.out.print(String.format("%20s|", dfjp.format(uktime)));\r
@@ -490,6 +512,7 @@ public class ImportPicture extends Thread {
                continue;\r
             }\r
 \r
+               // 時刻uktimeにおける<magver>をtrkptに追加する\r
             Element trkpt = trkpt(map, uktime);\r
             if (trkpt == null) {\r
                 System.out.println(String.format("%20s ", "Out of GPX logging time."));\r
@@ -524,7 +547,7 @@ public class ImportPicture extends Thread {
             }\r
 \r
             System.out.print(String.format("%12s %12s|", latStr, lonStr));\r
-            System.out.println(String.format("%8s|%6s|%6s|", eleStr, magvarStr, speedStr));\r
+            System.out.println(String.format("%8s|%6s|%s|", eleStr, magvarStr, speedStr));\r
             ret = true;\r
 \r
             if (exifWrite) {\r
@@ -661,7 +684,14 @@ public class ImportPicture extends Thread {
     /**\r
      * XMLエレメント<trkpt>をTIMEでキー付したHashMapを生成する<br>\r
      * \r
-     *         <trkseg><trkpt><time>2014-01-01T00:59:09Z</time></trkpt></trkseg>\r
+     * <trkseg>\r
+     *         <trkpt lat="34.976635" lon="138.466228">\r
+     *                 <ele>267.291</ele>\r
+     *                 <magvar>359</magvar>\r
+     *                 <speed></speed>\r
+     *                 <time>2016-07-02T08:25:18Z</time>\r
+     *         </trkpt>\r
+     * </trkseg>\r
      * \r
      * @param trk\r
      * @param map\r
@@ -698,6 +728,7 @@ public class ImportPicture extends Thread {
         }\r
     }\r
 \r
+    \r
     /**\r
      * <trkpt lat="35.32123832" lon="139.56965631">\r
      *          <ele>47.20000076293945</ele>\r