OSDN Git Service

FUNCTION:アウトプットフォルダの指定が可能になった。
authorhayashi yuu <hayashi.yuu@gmail.com>
Mon, 10 Aug 2015 10:39:00 +0000 (19:39 +0900)
committerhayashi yuu <hayashi.yuu@gmail.com>
Mon, 10 Aug 2015 10:39:00 +0000 (19:39 +0900)
importPicture/src/osm/jp/gpx/ImportPicture.java

index 2d9ec0f..76fd44d 100644 (file)
@@ -93,7 +93,7 @@ public class ImportPicture extends Thread {
      * argv[0] = 画像ファイルが格納されているディレクトリ\r
      * argv[1] = 時刻補正の基準とする画像ファイル\r
      * argv[2] = 基準画像ファイルの精確な撮影日時 "yyyy-MM-dd'T'HH:mm:ss"\r
-     * argv[3] = [EXIF] EXIF情報の書き換えを行う / [not] EXIF情報の書き換えを行わない\r
+     * argv[3] = [noEXIF] EXIF情報の書き換えを行わない / EXIF情報の書き換えを行う(出力先フォルダ)\r
      * argv[4] = 撮影位置をロギングしたGPXファイル\r
      * \r
      * @throws IOException\r
@@ -104,8 +104,6 @@ public class ImportPicture extends Thread {
         Date jptime;\r
 \r
         ImportPicture obj = new ImportPicture();\r
-        obj.outDir = null;\r
-        obj.gpxDir = new File(".");\r
 \r
         if (argv.length > 0) {\r
             obj.imgDir = new File(argv[0]);\r
@@ -134,13 +132,24 @@ public class ImportPicture extends Thread {
         }\r
 \r
         // \r
-        if (argv[3].toUpperCase().equals("EXIF")) {\r
+        if (argv[3].toUpperCase().equals("noEXIF")) {\r
+            obj.exif = false;\r
+            obj.outDir = null;\r
+        }\r
+        else {\r
             obj.exif = true;\r
+            obj.outDir = new File(argv[3]);\r
         }\r
 \r
         // 第6引数が指定されなければ、指定されたディレクトリ内のGPXファイルすべてを対象とする\r
-        if (argv.length > 4) {\r
-            obj.gpxFiles.add(new File(obj.gpxDir, argv[4]));\r
+        if (argv.length >= 5) {\r
+            obj.gpxDir = new File(argv[4]);\r
+        }\r
+        else {\r
+            obj.gpxDir = obj.imgDir;\r
+        }\r
+        if (obj.gpxDir.isFile()) {\r
+            obj.gpxFiles.add(new File(obj.gpxDir, argv[4]));            \r
         }\r
         else {\r
             File[] files = obj.gpxDir.listFiles();\r
@@ -162,9 +171,9 @@ public class ImportPicture extends Thread {
         } catch(InterruptedException end) {}\r
     }\r
     \r
-    public File gpxDir = new File(".");\r
-    public File imgDir = new File(".");\r
-    public File outDir = null;\r
+    public File gpxDir;\r
+    public File imgDir;\r
+    public File outDir;\r
     public long delta = 0;\r
     public boolean exif = false;\r
     public ArrayList<File> gpxFiles = new ArrayList<>();\r
@@ -191,11 +200,13 @@ public class ImportPicture extends Thread {
         Node gpx;\r
 \r
         try {\r
+            outDir = new File(outDir, imgDir.getName());\r
+\r
             for (File gpxFile : this.gpxFiles) {\r
                 String fileName = gpxFile.getName();\r
                 String iStr = fileName.substring(0, fileName.length() - 4);\r
 \r
-                File outputFile = new File(gpxFile.getParent(), iStr +"_.gpx");\r
+                File outputFile = new File(imgDir, iStr +"_.gpx");\r
                 System.out.println(iStr + " => "+ outputFile.getName());\r
 \r
                 factory = DocumentBuilderFactory.newInstance();\r
@@ -237,6 +248,7 @@ public class ImportPicture extends Thread {
                     }\r
                 }\r
 \r
+                boolean change = false;\r
                 if (trk != null) {\r
                     /*\r
                     * GPXへ割りつける開始時刻と終了時刻を求める\r
@@ -254,8 +266,6 @@ public class ImportPicture extends Thread {
                         }\r
                     }\r
 \r
-                    outDir = new File(gpxDir, imgDir.getName());\r
-                    outDir.mkdir();\r
                     System.out.println("           時差: "+ (delta / 1000) +"(sec)");\r
                     System.out.println("    Target GPX: ["+ gpxFile.getAbsolutePath() +"]");\r
                     System.out.println("GPX start time: "+ dfjp.format(new Date(gpxStartTime)) + "\t[GMT " + dfuk.format(new Date(gpxStartTime))+"]");\r
@@ -265,19 +275,21 @@ public class ImportPicture extends Thread {
                     System.out.println("------------|--------------------|--------------------|------------|------------|--------|------|");\r
                     System.out.println(" name       | UpdateTime         | GPStime            | Latitude   | Longitude  | ele    |magvar|");\r
                     System.out.println("------------|--------------------|--------------------|------------|------------|--------|------|");\r
-                    proc(imgDir, delta, gpxStartTime, gpxEndTime, map, exif, gpx);\r
+                    change = proc(imgDir, delta, gpxStartTime, gpxEndTime, map, exif, gpx);\r
                     System.out.println("------------|--------------------|--------------------|------------|------------|--------|------|");\r
                 }\r
 \r
                 // 出力\r
-                DOMSource source = new DOMSource(gpx);\r
-                FileOutputStream os = new FileOutputStream(outputFile);\r
-                StreamResult result = new StreamResult(os);\r
-                TransformerFactory transFactory = TransformerFactory.newInstance();\r
-                Transformer transformer = transFactory.newTransformer();\r
-                transformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
-                transformer.setOutputProperty(OutputKeys.METHOD, "xml");\r
-                transformer.transform(source, result);\r
+                if (change) {\r
+                    DOMSource source = new DOMSource(gpx);\r
+                    FileOutputStream os = new FileOutputStream(outputFile);\r
+                    StreamResult result = new StreamResult(os);\r
+                    TransformerFactory transFactory = TransformerFactory.newInstance();\r
+                    Transformer transformer = transFactory.newTransformer();\r
+                    transformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
+                    transformer.setOutputProperty(OutputKeys.METHOD, "xml");\r
+                    transformer.transform(source, result);                    \r
+                }\r
             }\r
         }\r
         catch(ParserConfigurationException | DOMException | SAXException | IOException | ParseException | ImageReadException | ImageWriteException | IllegalArgumentException | TransformerException e) {\r
@@ -291,16 +303,17 @@ public class ImportPicture extends Thread {
      * @throws ImageReadException \r
      * @throws ImageWriteException \r
      */\r
-    void proc(File dir, long delta, long gpxStartTime, long gpxEndTime, TreeMap<Long,Element> map, boolean exifWrite, Node gpx) throws ParseException, ImageReadException, IOException, ImageWriteException {\r
+    boolean proc(File dir, long delta, long gpxStartTime, long gpxEndTime, TreeMap<Long,Element> map, boolean exifWrite, Node gpx) throws ParseException, ImageReadException, IOException, ImageWriteException {\r
         DecimalFormat yearFormatter = new DecimalFormat("0000");\r
         DecimalFormat monthFormatter = new DecimalFormat("00");\r
         DecimalFormat dayFormatter = new DecimalFormat("00");\r
 \r
+        boolean ret = false;\r
         File[] files = dir.listFiles();\r
         Arrays.sort(files, new FileSort());\r
         for (File image : files) {\r
             if (image.isDirectory()) {\r
-                proc(image, delta, gpxStartTime, gpxEndTime, map, exifWrite, gpx);\r
+                ret = proc(image, delta, gpxStartTime, gpxEndTime, map, exifWrite, gpx);\r
             }\r
             else {\r
                 String imageName = image.getName();\r
@@ -338,6 +351,7 @@ public class ImportPicture extends Thread {
                             System.out.print(String.format("%20s|", dfjp.format(uktime)));\r
                             System.out.print(String.format("%12s %12s|", latStr, lonStr));\r
                             System.out.println(String.format("%8s|%6s|", eleStr, magvarStr));\r
+                            ret = true;\r
 \r
                             if (exifWrite) {\r
                                 TiffOutputSet outputSet = null;\r
@@ -440,6 +454,7 @@ public class ImportPicture extends Thread {
                                             RationalNumber.valueOf(latitudeSeconds));\r
                                 }\r
 \r
+                                outDir.mkdir();\r
                                 ExifRewriter rewriter = new ExifRewriter();\r
                                 try {\r
                                     fos = new FileOutputStream(new File(outDir, imageName));\r
@@ -459,6 +474,7 @@ public class ImportPicture extends Thread {
                 }\r
             }\r
         }\r
+        return ret;\r
     }\r
        \r
     static Document document;\r