はありません。 作者または著作権者は、契約行為、不法行為、またはそれ以外であろうと、ソフトウェアに起因または
関連し、あるいはソフトウェアの使用またはその他の扱いによって生じる一切の請求、損害、その他の義務について何
らの責任も負わないものとします。
+
+----------------
+
+osm.jp.gpx.Cords.java は'やまだらけ'様の著作物です。
+ Copyright (C) 2007-2012 やまだらけ
+ The MIT License (MIT)
+ 参照元: http://yamadarake.jp/trdi/report000001.html
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")) {
}
}
- 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;
public Double imaLAT = null;
public Double imaLON =null;
public Element magvar = null;
+ public Element speed = null;
/**
*
*/
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);
this.maeLON = maeLON;
}
+ public int getMagvar() {
+ String magvarStr = magvar.getTextContent();
+ return Integer.getInteger(magvarStr);
+ }
+
public Double getImaLAT() {
return imaLAT;
}
--- /dev/null
+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
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
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
Element newTRKSEG = mapTRKSEG.get(keyIte.next());\r
trk.appendChild(newTRKSEG);\r
\r
- // mapに、<trkpy>を割り付ける\r
+ // mapに、<trkpt>を割り付ける\r
trkptMap(newTRKSEG, map);\r
}\r
}\r
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
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
}\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
/**\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
}\r
}\r
\r
+ \r
/**\r
* <trkpt lat="35.32123832" lon="139.56965631">\r
* <ele>47.20000076293945</ele>\r