diff --git a/importPicture/doc/GPX.class.violet.html b/importPicture/doc/GPX.class.violet.html index c2e27eb..d8bd08c 100644 --- a/importPicture/doc/GPX.class.violet.html +++ b/importPicture/doc/GPX.class.violet.html @@ -20,7 +20,7 @@ - + 1 @@ -51,7 +51,7 @@ - + 1 @@ -136,7 +136,7 @@ - + 1 @@ -165,7 +165,7 @@ - + 1 @@ -186,19 +186,19 @@ + key:Date = trkptエレメントのtime [*] -+ value:Element = trkpt [*] ++ value:TagTrkpt = trkpt [*] + put(value: Element): Date -+ getValue(jpdate: Date): Element -- getTrkpt(jpdate: Date): Element -- getMaeTrkpt(imaTrkpt: TagTrkpt): Element ++ getValue(jpdate: Date): TagTrkpt +- getTrkpt(jpdate: Date): TagTrkpt +- getMaeTrkpt(imaTrkpt: TagTrkpt): TagTrkpt + printinfo(): void - + 1 @@ -229,7 +229,7 @@ - + 1 @@ -259,7 +259,7 @@ - + 1 @@ -277,7 +277,7 @@ - + 1 @@ -305,7 +305,7 @@ - + 1 @@ -317,1252 +317,1509 @@ + + + + + 1 + + 255 + 255 + 255 + 255 + + + 0 + 0 + 0 + 255 + + + + TagTrkpt + + + + Element trkpt = null; ++ Double lat = null; ++ Double lon = null; ++ eleStr : String ++ time : Date ++ magvarStr : String ++ speedStr: String + + + + removeElement(eleName:String) ++ appendElement(eleName:String, valueStr:String) + + - - + + - - - - + + + + 1 0..* 1 - + - - - - - + + + + + - + 1 0..* 1 - + - - - - + + + + 1 0..* 1 - + - - - - + + + + 1 0..* 1 - - - - - - - - 1 - - * - - value [時間順] - 1 - - + - - - - + + + + 1 - + - - - - + + + + 1 - + - - - - + + + + 1 - + - - - - + + + + 1 * - value [時間順] 1 - + - - - - + + + + 1 - + - - - - - 1 - - - - - - + + - + 1 - + - + 1 - + - - - - + + + + 1 - + + + + + + + + 1 + + - - - - + + + + 1 + + + + + + + + 1 + + * + + get(key: Date) + 1 + + + + + + + + + 1 + + 1 + + 1 + ]]>

- embedded diagram image + embedded diagram image \ No newline at end of file diff --git a/importPicture/src/osm/jp/gpx/Complementation.java b/importPicture/src/osm/jp/gpx/Complementation.java index 7dd5725..b541784 100644 --- a/importPicture/src/osm/jp/gpx/Complementation.java +++ b/importPicture/src/osm/jp/gpx/Complementation.java @@ -1,7 +1,6 @@ package osm.jp.gpx; import java.text.ParseException; -import org.w3c.dom.Element; public class Complementation { public static final Double R = (6378137D + 6356752.314D)/2D; // 6367444.657m @@ -13,7 +12,6 @@ public static boolean param_GpxOutputSpeed = false; public static boolean param_GpxOverwriteMagvar = false; - /** * * @@ -27,13 +25,12 @@ * @param map * @throws ParseException */ - public Complementation(Element imaE, Element maeE) throws ParseException { - this.imaTag = new TagTrkpt(imaE); + public Complementation(TagTrkpt imaE, TagTrkpt maeE) throws ParseException { + this.imaTag = new TagTrkpt(imaE.trkpt); if (maeE != null) { - this.maeTag = new TagTrkpt(maeE); + this.maeTag = new TagTrkpt(maeE.trkpt); } } - /** * 緯度・経度と時間差から速度(km/h)を求める diff --git a/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java b/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java index d8b9c79..c88b168 100644 --- a/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java +++ b/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java @@ -5,12 +5,9 @@ import java.util.TreeMap; import org.w3c.dom.DOMException; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; @SuppressWarnings("serial") -public class ElementMapTRKPT extends TreeMap { +public class ElementMapTRKPT extends TreeMap { public static final long DIFF_MAE_TIME = 3000L; // before 3 secound public ElementMapTRKPT() { @@ -19,30 +16,19 @@ /** * 拡張put value:ElementをputするとElement内のtimeを読み取ってkeyとしてthis.put(key,value)する。 + * + * 614.90 + * + * 0.5 + * * @param value * @return keyとして登録したtime:Date * @throws ParseException * @throws DOMException */ - public Date put(Element value) throws DOMException, ParseException { - NodeList nodes3 = value.getChildNodes(); - for (int i3=0; i3 < nodes3.getLength(); i3++) { - Node node4 = nodes3.item(i3); - if (node4.getNodeName().equals("time")) { - NodeList nodes4 = node4.getChildNodes(); // 子ノードを取得 - for (int i4=0; i4< nodes4.getLength(); i4++) { - Node node5 = nodes4.item(i4); - if (node5 != null) { - if (node5.getNodeType() == Node.TEXT_NODE) { - Date time = ImportPicture.toUTCDate(node5.getNodeValue()); - this.put(time, value); - return time; - } - } - } - } - } - return null; + public Date put(TagTrkpt tag) throws DOMException, ParseException { + this.put(tag.time, tag); + return tag.time; } /** @@ -52,10 +38,10 @@ * @return エレメントTRKPT。指定時刻に対応するノードがないときはnullを返す。 * @throws ParseException */ - public Element getValue(Date jptime) throws ParseException { - Element imaE = getTrkpt(jptime); + public TagTrkpt getValue(Date jptime) throws ParseException { + TagTrkpt imaE = getTrkpt(jptime); if (imaE != null) { - Element maeE = getMaeTrkpt((new TagTrkpt(imaE)).time); + TagTrkpt maeE = getMaeTrkpt(imaE.time); if (maeE != null) { Complementation comp = new Complementation(imaE, maeE); @@ -71,7 +57,7 @@ comp.complementationSpeed(); } - return (Element)(comp.imaTag.trkpt.cloneNode(true)); + return (TagTrkpt)(comp.imaTag.trkpt.cloneNode(true)); } return imaE; } @@ -88,7 +74,7 @@ * @return エレメント。対象のエレメントが存在しなかった場合には null。 * @throws ParseException */ - private Element getTrkpt(Date jptime) throws ParseException { + private TagTrkpt getTrkpt(Date jptime) throws ParseException { Date keyTime = null; for (Date key : this.keySet()) { int flag = jptime.compareTo(key); @@ -120,7 +106,7 @@ */ public static long OVER_TIME_LIMIT = 3000; // ミリ秒(msec) - private Element getMaeTrkpt(Date time) throws ParseException { + private TagTrkpt getMaeTrkpt(Date time) throws ParseException { Date maeTime = null; for (Date key : this.keySet()) { int flag = time.compareTo(key); diff --git a/importPicture/src/osm/jp/gpx/ElementMapTRKSEG.java b/importPicture/src/osm/jp/gpx/ElementMapTRKSEG.java index 404581a..154b16d 100644 --- a/importPicture/src/osm/jp/gpx/ElementMapTRKSEG.java +++ b/importPicture/src/osm/jp/gpx/ElementMapTRKSEG.java @@ -102,7 +102,7 @@ if (ImportPicture.param_GpxNoFirstNode && (i2 == 0)) { continue; } - mapTRKPT.put((Element)nodeTRKPT); + mapTRKPT.put(new TagTrkpt((Element)nodeTRKPT)); } } this.put(mapTRKPT); diff --git a/importPicture/src/osm/jp/gpx/ImportPicture.java b/importPicture/src/osm/jp/gpx/ImportPicture.java index 9eefb5c..ef2b2fd 100644 --- a/importPicture/src/osm/jp/gpx/ImportPicture.java +++ b/importPicture/src/osm/jp/gpx/ImportPicture.java @@ -463,17 +463,17 @@ String speedStr = "-"; double latitude = 90.5D; double longitude = 180.5D; - Element trkptE = null; + //Element trkptE = null; TagTrkpt trkptT = null; for (Map.Entry map : mapTRKSEG.entrySet()) { ElementMapTRKPT mapTRKPT = map.getValue(); - trkptE = mapTRKPT.getValue(correctedtime); - if (trkptE != null) { + trkptT = mapTRKPT.getValue(correctedtime); + if (trkptT != null) { break; } } - if (trkptE == null) { + if (trkptT == null) { System.out.print(String.format("%-14s|%-14s|", "", "")); System.out.println(String.format("%8s|%6s|%6s|", "", "", "")); if (!this.param_ImgOutputAll) { @@ -481,7 +481,6 @@ } } else { - trkptT = new TagTrkpt(trkptE); latitude = trkptT.lat; longitude = trkptT.lon; @@ -552,7 +551,7 @@ gpsDir.add(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP, dateStamp); } - if (trkptE != null) { + if (trkptT != null) { //---- EXIF GPS elevation/ALTITUDE ---- if (eleStr.equals("-") == false) { final double altitude = Double.parseDouble(eleStr); diff --git a/importPicture/test/osm/jp/gpx/AppParametersTest.java b/importPicture/test/osm/jp/gpx/AppParametersTest.java index 65e3a27..3fb54e6 100644 --- a/importPicture/test/osm/jp/gpx/AppParametersTest.java +++ b/importPicture/test/osm/jp/gpx/AppParametersTest.java @@ -31,7 +31,6 @@ if (iniFile.exists()) { iniFile.renameTo(orgFile); } - params = new AppParameters(); } @After @@ -49,6 +48,7 @@ @Test public void IMG_OUTPUT_ALLが定義されていない時() { try { + params = new AppParameters("testdata/AdjustTime.off.ini"); String valueStr = params.getProperty(AppParameters.IMG_OUTPUT_ALL); assertThat(valueStr, is("false")); } diff --git a/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java b/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java index 90d4a1f..a99f934 100644 --- a/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java +++ b/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java @@ -84,15 +84,15 @@ /* * - * - * - * + * 614.90 + * 615.00 + * 615.03 */ static String[][] values = { - {"2017-05-29T01:23:18Z", "35.8812697884", "137.9952202085"}, - {"2017-05-29T01:23:21Z", "35.8811769169", "137.9951928835"}, - {"2017-05-29T01:23:24Z", "35.881112963", "137.9951796401"}, - {"2017-05-29T01:23:27Z", "35.881072646", "137.9951728508"} + {"2017-05-29T01:23:18Z", "35.8812697884", "137.9952202085", null}, + {"2017-05-29T01:23:21Z", "35.8811769169", "137.9951928835", "614.90"}, + {"2017-05-29T01:23:24Z", "35.881112963", "137.9951796401", "615.00"}, + {"2017-05-29T01:23:27Z", "35.881072646", "137.9951728508", "615.03"} }; Element createElement(Document document, String[] values) { @@ -102,6 +102,11 @@ Element timeE = document.createElement("time"); timeE.appendChild(document.createTextNode(values[0])); trkpt.appendChild(timeE); + if (values[3] != null) { + Element eleE = document.createElement("ele"); + eleE.appendChild(document.createTextNode(values[3])); + trkpt.appendChild(eleE); + } return trkpt; } @@ -114,7 +119,7 @@ map = new ElementMapTRKPT(); for (int cnt = 4; cnt > 0; cnt--) { - map.put(createElement(document, values[cnt - 1])); + map.put(new TagTrkpt(createElement(document, values[cnt - 1]))); } } @@ -127,104 +132,109 @@ public void KEYが時間順に取り出せるか() { int i = 0; for (Date key : map.keySet()) { - assertThat(sdf.format(key), is(values[i++][0])); + try { + String s = sdf.format(ImportPicture.toUTCDate(values[i++][0])); + assertThat(sdf.format(key), is(s)); + } catch (ParseException e) { + e.printStackTrace(); + } } } @Test public void get_17() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:17Z")); - assertThat(ret, is(nullValue())); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:17Z")); + assertThat(tag, is(nullValue())); } @Test public void get_18() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:18Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:18Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:18Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z")); + assertThat(tag.eleStr, is(nullValue())); } @Test public void get_19() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:19Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:18Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:19Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z")); + assertThat(tag.eleStr, is(nullValue())); } @Test public void get_20() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:20Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:18Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:20Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:18Z")); + assertThat(tag.eleStr, is(nullValue())); } @Test public void get_21() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:21Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:21Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:21Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z")); + assertThat(tag.eleStr, is("614.90")); } @Test public void get_22() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:22Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:21Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:22Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z")); + assertThat(tag.eleStr, is("614.90")); } @Test public void get_23() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:23Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:21Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:23Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:21Z")); + assertThat(tag.eleStr, is("614.90")); } @Test public void get_24() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:24Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:24Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:24Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z")); + assertThat(tag.eleStr, is("615.00")); } @Test public void get_25() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:25Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:24Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:25Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z")); + assertThat(tag.eleStr, is("615.00")); } @Test public void get_26() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:26Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:24Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:26Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:24Z")); + assertThat(tag.eleStr, is("615.00")); } @Test public void get_27() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:27Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:27Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:27Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z")); + assertThat(tag.eleStr, is("615.03")); } @Test public void get_28() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:28Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:27Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:28Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z")); + assertThat(tag.eleStr, is("615.03")); } @Test public void get_30() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:30Z")); - TagTrkpt tag = new TagTrkpt(ret); - assertThat(sdf.format(tag.time), is("2017-05-29T01:23:27Z")); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:30Z")); + assertThat(sdf.format(tag.time), is("2017-05-29T10:23:27Z")); + assertThat(tag.eleStr, is("615.03")); } @Test public void get_31() throws ParseException { - Element ret = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:31Z")); - assertThat(ret, is(nullValue())); + TagTrkpt tag = map.getValue(ImportPicture.toUTCDate("2017-05-29T01:23:31Z")); + assertThat(tag, is(nullValue())); } } @@ -234,9 +244,9 @@ String dateTimeOriginal = "2017:06:30 09:59:59"; Date time = ImportPicture.toEXIFDate(dateTimeOriginal); assertThat(ImportPicture.toEXIFString(time), is("2017:06:30 09:59:59")); - assertThat(ImportPicture.toUTCString(time), is("2017-06-30T09:59:59Z")); + assertThat(ImportPicture.toUTCString(time), is("2017-06-30T00:59:59Z")); DateFormat dfUTC = new SimpleDateFormat(ImportPicture.TIME_FORMAT_STRING); - assertThat(dfUTC.format(time), is("2017-06-30T18:59:59Z")); + assertThat(dfUTC.format(time), is("2017-06-30T09:59:59Z")); } } diff --git a/importPicture/test/osm/jp/gpx/ElementMapTRKSEGTest.java b/importPicture/test/osm/jp/gpx/ElementMapTRKSEGTest.java index 13b0a25..4446e9d 100644 --- a/importPicture/test/osm/jp/gpx/ElementMapTRKSEGTest.java +++ b/importPicture/test/osm/jp/gpx/ElementMapTRKSEGTest.java @@ -3,20 +3,15 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import java.io.File; -import java.io.IOException; -import java.text.ParseException; import java.util.Date; -import javax.xml.parsers.ParserConfigurationException; - import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; -import org.w3c.dom.DOMException; -import org.xml.sax.SAXException; @RunWith(Theories.class) public class ElementMapTRKSEGTest { @@ -53,14 +48,19 @@ }; @Theory - public void TRKSEGを読み込む(Fixture dataset) throws ParserConfigurationException, SAXException, IOException, DOMException, ParseException { - ElementMapTRKSEG mapTRKSEG = new ElementMapTRKSEG(); - mapTRKSEG.parse(new File(dataset.gpxSourcePath)); - mapTRKSEG.printinfo(); - System.out.println("GPX file: "+ dataset.gpxSourcePath); - assertThat(mapTRKSEG.size(), is(dataset.segCount)); - for (Date key : mapTRKSEG.keySet()) { - assertThat(key, is(notNullValue())); + public void TRKSEGを読み込む(Fixture dataset) { + try { + ElementMapTRKSEG mapTRKSEG = new ElementMapTRKSEG(); + mapTRKSEG.parse(new File(dataset.gpxSourcePath)); + mapTRKSEG.printinfo(); + System.out.println("GPX file: "+ dataset.gpxSourcePath); + assertThat(mapTRKSEG.size(), is(dataset.segCount)); + for (Date key : mapTRKSEG.keySet()) { + assertThat(key, is(notNullValue())); + } + } + catch (Exception e) { + fail(); } } }