3 import java.text.ParseException;
5 import java.util.TreeMap;
7 import org.w3c.dom.DOMException;
9 @SuppressWarnings("serial")
10 public class ElementMapTRKPT extends TreeMap<Date, TagTrkpt> {
11 public static final long DIFF_MAE_TIME = 3000L; // before 3 secound
13 public ElementMapTRKPT() {
14 super(new TimeComparator());
18 * 拡張put value:ElementをputするとElement内のtimeを読み取ってkeyとしてthis.put(key,value)する。
21 * <trkpt lat="36.4260153752" lon="138.0117778201">
23 * <time>2017-05-21T23:02:16Z</time>
27 * @return keyとして登録したtime:Date
28 * @throws ParseException
29 * @throws DOMException
31 public Date put(TagTrkpt tag) throws DOMException, ParseException {
32 this.put(tag.time, tag);
37 * 指定時刻(jptime)のTRKPTエレメントを取り出す。
39 * @param jptime 指定する日時
40 * @return エレメントTRKPT。指定時刻に対応するノードがないときはnullを返す。
41 * @throws ParseException
43 public TagTrkpt getValue(Date jptime) throws ParseException {
44 TagTrkpt imaE = getTrkpt(jptime);
46 TagTrkpt maeE = getMaeTrkpt(imaE.time);
48 Complementation comp = new Complementation(imaE, maeE);
51 // 直前の位置と、現在地から進行方向を求める
52 // 経度(longitude)と経度から進行方向を求める
53 if (Complementation.param_GpxOverwriteMagvar) {
54 comp.complementationMagvar();
57 // 緯度・経度と時間差から速度(km/h)を求める
58 if (Complementation.param_GpxOutputSpeed) {
59 comp.complementationSpeed();
61 //return (TagTrkpt)(comp.imaTag.trkpt.cloneNode(true));
62 return (TagTrkpt)(comp.imaTag);
70 * [map]から指定した時刻の<trkpt>エレメントを取り出す。
71 * 取り出すエレメントは、指定した時刻と同一時刻、もしくは、直近・直前の時刻のエレメントとする。
72 * 指定した時刻以前のエレメントが存在しない場合は null を返す。
73 * 指定した時刻と直近・直前のエレメントの時刻との乖離が プロパティ[OVER_TIME_LIMIT=3000(ミリ秒)]より大きい場合には null を返す。
76 * @return <trkpt>エレメント。対象のエレメントが存在しなかった場合には null。
77 * @throws ParseException
79 private TagTrkpt getTrkpt(Date jptime) throws ParseException {
81 for (Date key : this.keySet()) {
82 int flag = jptime.compareTo(key);
84 if (keyTime != null) {
85 return this.get(keyTime);
93 keyTime = new Date(key.getTime());
96 if (keyTime != null) {
97 if (Math.abs(keyTime.getTime() - jptime.getTime()) <= OVER_TIME_LIMIT) {
98 return this.get(keyTime);
105 * ロガーの最終取得時刻を超えた場合、どこまでを有効とするかを設定する。
106 * この設定がないと、最終取得時刻を超えたものは全て有効になってしまう。
107 * OVER_TIME_LIMITは、GPSロガーの位置取得間隔()よりも長くする必要がある。長すぎても良くない。
109 public static long OVER_TIME_LIMIT = 3000; // ミリ秒(msec)
111 private TagTrkpt getMaeTrkpt(Date time) throws ParseException {
113 for (Date key : this.keySet()) {
114 int flag = time.compareTo(key);
116 maeTime = new Date(key.getTime());
118 else if (flag == 0) {
119 if (maeTime == null) {
122 return this.get(maeTime);
126 if (maeTime == null) {
129 if (Math.abs(maeTime.getTime() - time.getTime()) > OVER_TIME_LIMIT) {
132 return this.get(maeTime);
138 public void printinfo() {
139 Date firstTime = null;
140 Date lastTime = null;
141 for (Date key : this.keySet()) {
142 if (firstTime == null) {
143 firstTime = new Date(key.getTime());
145 lastTime = new Date(key.getTime());
147 System.out.println(String.format("| <trkseg/> |%20s|%20s|", ImportPicture.toUTCString(firstTime), ImportPicture.toUTCString(lastTime)));