diff --git a/importPicture/src/LICENSE.txt b/importPicture/src/LICENSE.txt index 9586edf..24cc95a 100644 --- a/importPicture/src/LICENSE.txt +++ b/importPicture/src/LICENSE.txt @@ -33,3 +33,10 @@ はありません。 作者または著作権者は、契約行為、不法行為、またはそれ以外であろうと、ソフトウェアに起因または 関連し、あるいはソフトウェアの使用またはその他の扱いによって生じる一切の請求、損害、その他の義務について何 らの責任も負わないものとします。 + +---------------- + +osm.jp.gpx.Cords.java は'やまだらけ'様の著作物です。 + Copyright (C) 2007-2012 やまだらけ + The MIT License (MIT) + 参照元: http://yamadarake.jp/trdi/report000001.html diff --git a/importPicture/src/osm/jp/gpx/Complementation.java b/importPicture/src/osm/jp/gpx/Complementation.java index 7b1914f..a70daaf 100644 --- a/importPicture/src/osm/jp/gpx/Complementation.java +++ b/importPicture/src/osm/jp/gpx/Complementation.java @@ -9,15 +9,34 @@ public class Complementation { + /** + * + * + * 267.291 + * 359 + * + * + * + * + * @param trkseg + * @param map + * @throws ParseException + */ public Complementation(Element imaE, Element maeE) throws ParseException { // がなければ、 // 直前の位置と、現在地から進行方向を求める 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 @@ } } - 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 Double imaLAT = null; public Double imaLON =null; public Element magvar = null; + public Element speed = null; /** @@ -84,13 +106,9 @@ * */ 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 @@ 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 index 0000000..a7d8672 --- /dev/null +++ b/importPicture/src/osm/jp/gpx/Coords.java @@ -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 diff --git a/importPicture/src/osm/jp/gpx/ImportPicture.java b/importPicture/src/osm/jp/gpx/ImportPicture.java index 03ed192..e4bb2c9 100644 --- a/importPicture/src/osm/jp/gpx/ImportPicture.java +++ b/importPicture/src/osm/jp/gpx/ImportPicture.java @@ -347,6 +347,7 @@ TreeMap map = new TreeMap<>(); TreeMap mapTRKSEG = new TreeMap<>(); Element trk = null; + Element maeTRKPT = null; gpx = builder.parse(gpxFile).getFirstChild(); Document doc = gpx.getOwnerDocument(); NodeList nodes = gpx.getChildNodes(); @@ -370,6 +371,26 @@ if (param_GpxNoFirstNode && (i2 == 0)) { continue; } + if (param_GpxOutputSpeed || param_GpxOverwriteMagvar) { + Complementation cmp = new Complementation((Element)nodeTRKPT, maeTRKPT); + if (param_GpxOutputSpeed) { + if (cmp.speed != null) { + nodeTRKPT.removeChild(cmp.speed); + } + if (maeTRKPT != null) { + cmp.complementationSpeed((Element)nodeTRKPT); + } + } + if (param_GpxOverwriteMagvar) { + if (cmp.magvar != null) { + nodeTRKPT.removeChild(cmp.magvar); + } + if (maeTRKPT != null) { + cmp.complementationMagvar((Element)nodeTRKPT); + } + } + } + maeTRKPT = getCopy(doc, nodeTRKPT); newTRKSEG.appendChild(getCopy(doc, nodeTRKPT)); } } @@ -388,7 +409,7 @@ Element newTRKSEG = mapTRKSEG.get(keyIte.next()); trk.appendChild(newTRKSEG); - // mapに、を割り付ける + // mapに、を割り付ける trkptMap(newTRKSEG, map); } } @@ -482,6 +503,7 @@ itime = new Date(lastModifyTime); } + // uktime <-- 画像撮影時刻に対応するGPX時刻 Date uktime = new Date(itime.getTime() + delta); System.out.print(String.format("%20s ", dfjp.format(itime))); System.out.print(String.format("%20s|", dfjp.format(uktime))); @@ -490,6 +512,7 @@ continue; } + // 時刻uktimeにおけるをtrkptに追加する Element trkpt = trkpt(map, uktime); if (trkpt == null) { System.out.println(String.format("%20s ", "Out of GPX logging time.")); @@ -524,7 +547,7 @@ } System.out.print(String.format("%12s %12s|", latStr, lonStr)); - System.out.println(String.format("%8s|%6s|%6s|", eleStr, magvarStr, speedStr)); + System.out.println(String.format("%8s|%6s|%s|", eleStr, magvarStr, speedStr)); ret = true; if (exifWrite) { @@ -661,7 +684,14 @@ /** * XMLエレメント<trkpt>をTIMEでキー付したHashMapを生成する
* - * <trkseg><trkpt><time>2014-01-01T00:59:09Z</time></trkpt></trkseg> + * + * + * 267.291 + * 359 + * + * + * + * * * @param trk * @param map @@ -698,6 +728,7 @@ } } + /** * <trkpt lat="35.32123832" lon="139.56965631"> * <ele>47.20000076293945</ele>