3 import java.text.ParseException;
5 public class Complementation {
6 public static final Double R = (6378137D + 6356752.314D)/2D; // 6367444.657m
8 public TagTrkpt imaTag = null;
9 public TagTrkpt maeTag = null;
10 //public static boolean param_GpxOutputSpeed = false;
11 //public static boolean param_GpxOverwriteMagvar = false;
16 * @throws java.text.ParseException
18 * <trkpt lat="34.976635" lon="138.466228">
20 * <magvar>359</magvar>
22 * <time>2016-07-02T08:25:18Z</time>
27 * @throws ParseException
29 public Complementation(TagTrkpt imaE, TagTrkpt maeE) throws ParseException {
30 this.imaTag = imaE.clone();
32 this.maeTag = maeE.clone();
37 * 緯度・経度と時間差から速度(km/h)を求める
40 public void complementationSpeed() {
41 if (imaTag.speedStr != null) {
43 Double.parseDouble(imaTag.speedStr);
45 catch (NumberFormatException e) {
46 // 数字以外なら<speed>エレメントを削除する
47 imaTag.speedStr = null;
51 if (imaTag.speedStr == null) {
52 double d = GeoDistance.calcDistHubeny(imaTag.lat, imaTag.lon, maeTag.lat, maeTag.lon);
53 String str = Double.toString((d * 3600) / (imaTag.time.getTime() - maeTag.time.getTime()));
54 int iDot = str.indexOf('.');
56 str = str.substring(0, iDot+2);
58 imaTag.speedStr = str;
63 * 経度(longitude)と経度から進行方向を求める
64 * @throws ParseException
66 public void complementationMagvar() throws ParseException {
67 if (imaTag.magvarStr != null) {
69 Double.parseDouble(imaTag.magvarStr);
71 catch (NumberFormatException e) {
72 // 数字以外なら<magvar>エレメントを削除する
73 imaTag.magvarStr = null;
77 if (imaTag.magvarStr == null) {
78 Double r = Math.cos(Math.toRadians((imaTag.lat + maeTag.lat) / 2)) * R;
79 Double x = Math.toRadians(imaTag.lon - maeTag.lon) * r;
80 Double y = Math.toRadians(imaTag.lat - maeTag.lat) * R;
81 double rad = Math.toDegrees(Math.atan2(y, x));
88 rad = 360 - (rad - 90);
100 String str = Double.toString(rad);
101 int iDot = str.indexOf('.');
103 str = str.substring(0, iDot);
105 imaTag.magvarStr = str;