OSDN Git Service

red: fixed M2a で、trksegが3つ認識されない現象が解決した。
authorhayashi <hayashi.yuu@gmail.com>
Tue, 27 Jun 2017 10:27:39 +0000 (19:27 +0900)
committerhayashi <hayashi.yuu@gmail.com>
Tue, 27 Jun 2017 10:27:39 +0000 (19:27 +0900)
importPicture/src/osm/jp/gpx/ElementMapTRKSEG.java
importPicture/src/osm/jp/gpx/ImportPicture.java
importPicture/test/osm/jp/gpx/ElementMapTRKSEGTest.java
importPicture/test/osm/jp/gpx/ImportPictureTest.java
importPicture/testdata/AdjustTime.M2b.separate.ini [new file with mode: 0644]

index b1e64d8..404581a 100644 (file)
@@ -15,6 +15,20 @@ import org.xml.sax.SAXException;
 
 @SuppressWarnings("serial")
 public class ElementMapTRKSEG extends TreeMap<Date, ElementMapTRKPT> {
+       /**
+        * TESTing
+        * @throws ParseException 
+        * @throws ParserConfigurationException 
+        * @throws IOException 
+        * @throws SAXException 
+        * @throws DOMException 
+        */
+       public static void main(String[] argv) throws DOMException, SAXException, IOException, ParserConfigurationException, ParseException {
+               ElementMapTRKSEG mapTRKSEG = null;
+               mapTRKSEG = new ElementMapTRKSEG();
+        mapTRKSEG.parse(new File("testdata/cameradata/separate.gpx"));
+        mapTRKSEG.printinfo();
+       }
        
        public ElementMapTRKSEG() {
                super(new TimeComparator());
@@ -50,15 +64,13 @@ public class ElementMapTRKSEG extends TreeMap<Date, ElementMapTRKPT> {
         factory.setIgnoringComments(true);
         factory.setValidating(true);
         
-        Element trk = null;
-        
         Node gpx    = builder.parse(gpxFile).getFirstChild();
         Document document = gpx.getOwnerDocument();
         NodeList nodes = gpx.getChildNodes();
         for (int i=0; i < nodes.getLength(); i++) {
             Node node2 = nodes.item(i);
             if (node2.getNodeName().equals("trk")) {
-                trk = (Element) node2;
+               Element trk = (Element) node2;
                 
                 NodeList nodes1 = trk.getChildNodes();
                 for (int i1=0; i1 < nodes1.getLength(); i1++) {
@@ -83,7 +95,6 @@ public class ElementMapTRKSEG extends TreeMap<Date, ElementMapTRKPT> {
         if (nodeTRKSEG.getNodeName().equals("trkseg")) {
             NodeList nodes2 = nodeTRKSEG.getChildNodes();
             
-               Date trksegStartTime = new Date();                              // 対象とする開始時刻(現在時刻)
             ElementMapTRKPT mapTRKPT = new ElementMapTRKPT();
             for (int i2 = 0; i2 < nodes2.getLength(); i2++) {
                 Node nodeTRKPT = nodes2.item(i2);
@@ -91,13 +102,10 @@ public class ElementMapTRKSEG extends TreeMap<Date, ElementMapTRKPT> {
                        if (ImportPicture.param_GpxNoFirstNode && (i2 == 0)) {
                                continue;
                        }
-                    Date time = mapTRKPT.put((Element)nodeTRKPT);
-                               if (trksegStartTime.compareTo(time) < 0) {
-                                       trksegStartTime = time;
-                               }
+                    mapTRKPT.put((Element)nodeTRKPT);
                 }
             }
-            this.put(trksegStartTime, mapTRKPT);
+            this.put(mapTRKPT);
         }
        }
        
@@ -111,20 +119,21 @@ public class ElementMapTRKSEG extends TreeMap<Date, ElementMapTRKPT> {
        public void put(ElementMapTRKPT value) {
                for (Date key : value.keySet()) {
                        this.put(key, value);
+                       return;
                }
        }
        
        public void printinfo() {
-               System.out.println("                                 |--------------------|--------------------|");
+               System.out.println("                                 +--------------------+--------------------|");
                System.out.println("  GPS logging time               | First Time         | Last Time          |");
+               System.out.println("|--------------------------------+--------------------+--------------------|");
 
                for (java.util.Map.Entry<Date, ElementMapTRKPT> map : this.entrySet()) {
-               System.out.println("|--------------------------------|--------------------|--------------------|");
                ElementMapTRKPT mapTRKPT = map.getValue();
                mapTRKPT.printinfo();
         }
                
-               System.out.println("|--------------------------------|--------------------|--------------------|");
+               System.out.println("|--------------------------------+--------------------+--------------------|");
                System.out.println();
        }
 
index 428006d..ac14872 100644 (file)
@@ -294,7 +294,12 @@ public class ImportPicture extends Thread {
        public boolean param_GpxOutputWpt = true;\r
        public boolean param_ImgOutputAll = false;\r
        public String param_GpxSourceFolder = ".";\r
+    Document document;\r
        \r
+    public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss";\r
+    public static final SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
+    public static final SimpleDateFormat dfuk = new SimpleDateFormat(TIME_FORMAT_STRING +"'Z'");\r
+\r
     @Override\r
     public void run() {\r
         /**\r
@@ -341,8 +346,12 @@ public class ImportPicture extends Thread {
      * @throws TransformerException \r
      */\r
     void procGPXfile(File gpxFile) throws ParserConfigurationException, SAXException, IOException, ParseException, ImageReadException, ImageWriteException, TransformerException {\r
-        DocumentBuilderFactory factory;\r
-        DocumentBuilder        builder;\r
+        DocumentBuilderFactory factory = null;\r
+        DocumentBuilder        builder = null;\r
+        ElementMapTRKSEG mapTRKSEG = null;\r
+        Node gpx = null;\r
+        \r
+        System.gc();\r
 \r
         String fileName = gpxFile.getName();\r
         String iStr = fileName.substring(0, fileName.length() - 4);\r
@@ -361,14 +370,14 @@ public class ImportPicture extends Thread {
         factory.setValidating(true);\r
 \r
         // GPXファイルをパースする\r
-        ElementMapTRKSEG mapTRKSEG = new ElementMapTRKSEG();\r
+        mapTRKSEG = new ElementMapTRKSEG();\r
         document = mapTRKSEG.parse(gpxFile);\r
         \r
         // パースされた mapTRKSEG の中身を出力する\r
         mapTRKSEG.printinfo();\r
         \r
         // GPX file --> Node root\r
-        Node gpx = builder.parse(gpxFile).getFirstChild();\r
+        gpx = builder.parse(gpxFile).getFirstChild();\r
 \r
         // imgDir内の画像ファイルを処理する\r
                System.out.println("|--------------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|");\r
@@ -635,16 +644,6 @@ public class ImportPicture extends Thread {
         return ret;\r
     }\r
        \r
-    static Document document;\r
-\r
-\r
-    /**\r
-     * 2012-06-10T05:09:46Z  (日本時間の'2012-06-10T14:09:46')\r
-     */\r
-    public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss";\r
-    public static SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
-    public static SimpleDateFormat dfuk = new SimpleDateFormat(TIME_FORMAT_STRING +"'Z'");\r
-\r
     /**\r
      * 対象は '*.JPG' のみ対象とする\r
      * @return \r
@@ -758,7 +757,7 @@ public class ImportPicture extends Thread {
         wpt.appendChild(name);\r
 \r
         Element link = document.createElement("link");\r
-        link.setAttribute("href", getShortPathName(imgDir, iFile));\r
+        link.setAttribute("href", ImportPicture.getShortPathName(imgDir, iFile));\r
         Element text = document.createElement("text");\r
         text.setTextContent(iFile.getName());\r
         link.appendChild(text);\r
@@ -777,43 +776,13 @@ public class ImportPicture extends Thread {
             return filePath;\r
         }\r
     }\r
-\r
-    public static Element getCopy(Document doc, Node node) {\r
-        Element root = doc.createElement(node.getNodeName());\r
-\r
-        NamedNodeMap nodeMap = node.getAttributes();\r
-        if (null != nodeMap) {\r
-            for (int j=0; j < nodeMap.getLength(); j++ ) {\r
-                root.setAttribute(nodeMap.item(j).getNodeName(), nodeMap.item(j).getNodeValue());\r
-            }\r
-        }\r
-\r
-        NodeList nodes = node.getChildNodes();\r
-        for (int i=0; i < nodes.getLength(); i++) {\r
-            Node node2 = nodes.item(i);\r
-            if (node2.getNodeType() == Node.ELEMENT_NODE) {\r
-                root.appendChild(getCopy(doc, node2));\r
-            }\r
-            else if (node2.getNodeType() == Node.TEXT_NODE) {\r
-                String str = node2.getNodeValue();\r
-                Text textContents = doc.createTextNode(str);\r
-                root.appendChild(textContents);\r
-            }\r
-            else if (node2.getNodeType() == Node.CDATA_SECTION_NODE) {\r
-                String str = node2.getNodeValue();\r
-                CDATASection cdataSection = doc.createCDATASection(str);\r
-                root.appendChild(cdataSection);\r
-            }\r
-        }\r
-        return root;\r
-    }\r
-       \r
+    \r
     /**\r
      * ファイル名の順序に並び替えるためのソートクラス\r
      * \r
      * @author hayashi\r
      */\r
-    static class FileSort implements Comparator<File>{\r
+    static class FileSort implements Comparator<File> {\r
         @Override\r
         public int compare(File src, File target){\r
             int diff = src.getName().compareTo(target.getName());\r
@@ -825,7 +794,7 @@ public class ImportPicture extends Thread {
      * JPEGファイルフィルター\r
      * @author yuu\r
      */\r
-       class JpegFileFilter implements FilenameFilter{\r
+       class JpegFileFilter implements FilenameFilter {\r
        public boolean accept(File dir, String name) {\r
                        if (name.toUpperCase().matches(".*\\.JPG$")) {\r
                                return true;\r
index 4eb9e04..13b0a25 100644 (file)
@@ -57,7 +57,7 @@ public class ElementMapTRKSEGTest {
         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()));
index 0ad0be1..8120a2b 100644 (file)
@@ -19,8 +19,6 @@ import org.junit.experimental.theories.DataPoints;
 import org.junit.experimental.theories.Theories;
 import org.junit.experimental.theories.Theory;
 
-import hayashi.tools.files.DeleteDir;
-
 @RunWith(Theories.class)
 public class ImportPictureTest {
        static class Expecter {
@@ -206,7 +204,7 @@ public class ImportPictureTest {
                                        "testdata/AdjustTime.M1c.separate.ini",
                                        new Expecter[] {
                                                // GPX file
-                                                       new Expecter("separate_", true),
+                                                       new Expecter("separate/separate_.gpx", true),
                                            
                                            // out of time ( - 2017-05-29T01:23:18)
                                                        new Expecter("separate/20170529_102305A.jpg", false),
@@ -242,7 +240,7 @@ public class ImportPictureTest {
                                        "testdata/AdjustTime.M1d.separate.ini",
                                        new Expecter[] {
                                                // GPX file
-                                                       new Expecter("separate_", true),
+                                                       new Expecter("separate/separate_.gpx", true),
                                            
                                            // out of time ( - 2017-05-29T01:23:18)
                                                        new Expecter("separate/20170529_102305A.jpg", true),
@@ -563,8 +561,8 @@ public class ImportPictureTest {
 
        @Theory
        public void パラメータテスト(Fixture dataset) throws Exception {
-               setup(dataset);
-               testdo(dataset.iniFilePath);
+               ImportPictureTest.setup(dataset);
+               ImportPictureTest.testdo(dataset.iniFilePath);
                
                Expecter[] es = dataset.expecters;
                AppParameters params = new AppParameters(dataset.iniFilePath);
@@ -576,22 +574,22 @@ public class ImportPictureTest {
                }
        }
 
-       public void setup(Fixture dataset) throws IOException {
+       static void setup(Fixture dataset) throws IOException {
                System.out.println(dataset.toString());
                
                // カメラディレクトリを削除する
                File dir = new File("testdata/cameradata");
                if (dir.exists()) {
-                       DeleteDir.delete(dir);
+                       ImportPictureTest.delete(dir);
                }
                File outDir = new File("testdata/output");
                if (outDir.exists()) {
-                       DeleteDir.delete(outDir);
+                       ImportPictureTest.delete(outDir);
                }
                outDir.mkdir();
 
                // カメラディレクトリを作成する
-               uncompress(new File(dataset.tarFilePath), new File("testdata/cameradata"));
+               ImportPictureTest.uncompress(new File(dataset.tarFilePath), new File("testdata/cameradata"));
                
                // GPXファイルをセット
         try (  FileInputStream inStream = new FileInputStream(new File(dataset.gpxSourcePath));
@@ -607,7 +605,7 @@ public class ImportPictureTest {
         * 実行する
         * @throws Exception
         */
-       public static void testdo(String iniFilePath) {
+       static void testdo(String iniFilePath) {
         try {
                String[] argv = new String[1];
                argv[0] = new String(iniFilePath);
@@ -635,7 +633,7 @@ public class ImportPictureTest {
         TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
         while (tarEntry != null) {
             File destPath = new File(dest, tarEntry.getName());
-            System.out.println("uncompress: " + destPath.getCanonicalPath());
+            //System.out.println("uncompress: " + destPath.getCanonicalPath());
             if (tarEntry.isDirectory()) {
                 destPath.mkdirs();
             }
@@ -661,4 +659,24 @@ public class ImportPictureTest {
         }
         tarIn.close();
     }
+
+    public static void delete(File file) throws IOException {
+        if (!file.exists()) {
+            System.out.println("ERROR: ファイルまたはディレクトリが見つかりませんでした。");
+            throw new IOException("File not found.");
+        }
+        
+        if (file.isDirectory()) {
+            File files[] = file.listFiles();
+            if (files != null) {
+                for (int i=0; i < files.length; i++) {
+                    delete(files[i]);    // 再帰呼び出し
+                }
+            }
+        }
+        if (!file.delete()) {
+                       System.out.println("ERROR: ファイルは削除できませんでした。 '" + file.getAbsolutePath() +"'");
+        }
+        return;
+    }
 }
diff --git a/importPicture/testdata/AdjustTime.M2b.separate.ini b/importPicture/testdata/AdjustTime.M2b.separate.ini
new file mode 100644 (file)
index 0000000..8be595f
--- /dev/null
@@ -0,0 +1,16 @@
+#defuilt settings
+#Tue Jun 27 19:19:34 JST 2017
+GPX.BASETIME=FILE_UPDATE
+IMG.OUTPUT_EXIF=true
+GPX.OUTPUT_SPEED=false
+GPX.OUTPUT_WPT=false
+IMG.OUTPUT_ALL=false
+GPX.noFirstNode=true
+IMG.OUTPUT=true
+GPX.gpxSplit=true
+GPX.REUSE=false
+GPX.OVERWRITE_MAGVAR=false
+IMG.BASE_FILE=
+IMG.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.
+GPX.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.
+IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.