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