if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) {\r
obj.exif = true;\r
}\r
-\r
+ \r
System.out.println(" - param: imgDir = '"+ obj.imgDir.getAbsolutePath() +"'");\r
System.out.println(" - param: outDir = '"+ (obj.outDir == null ? "" : obj.outDir.getAbsolutePath()) +"'");\r
System.out.println(" - param: gpxDir = '"+ (obj.gpxDir == null ? "" : obj.gpxDir.getAbsolutePath()) +"'");\r
System.out.println(" - param: number of gpxFiles = '"+ obj.gpxFiles.size() +"'");\r
System.out.println(" - param: "+ AppParameters.GPX_GPXSPLIT +"="+ obj.param_GpxSplit);\r
System.out.println(" - param: "+ AppParameters.GPX_NO_FIRST_NODE +"="+ obj.param_GpxNoFirstNode); \r
- System.out.println(" - param: "+ AppParameters.GPX_REUSE +"="+ obj.param_GpxReuse); \r
+ System.out.println(" - param: "+ AppParameters.GPX_REUSE +"="+ obj.param_GpxReuse);\r
+ System.out.println(" - param: "+ AppParameters.IMG_BASE_FILE +"="+ obj.params.getProperty(AppParameters.IMG_BASE_FILE) );\r
System.out.println(" - param: "+ AppParameters.GPX_BASETIME +"="+ obj.params.getProperty(AppParameters.GPX_BASETIME) );\r
System.out.println(" - param: "+ AppParameters.IMG_OUTPUT +"="+ obj.params.getProperty(AppParameters.IMG_OUTPUT)); \r
System.out.println(" - param: "+ AppParameters.IMG_OUTPUT_ALL +"="+ obj.param_ImgOutputAll);\r
\r
System.out.println("GPX start time: "+ dfjp.format(new Date(gpxStartTime)) + "\t[GMT " + dfuk.format(new Date(gpxStartTime))+"]");\r
System.out.println(" GPX end time: "+ dfjp.format(new Date(gpxEndTime)) + "\t[GMT " + dfuk.format(new Date(gpxEndTime))+"]");\r
- System.out.println("------------------------|--------------------|--------------------|------------|------------|--------|------|------|");\r
- System.out.println(" name | UpdateTime | GPStime | Latitude | Longitude | ele |magvar| km/h |");\r
- System.out.println("------------------------|--------------------|--------------------|------------|------------|--------|------|------|");\r
+ System.out.println("------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|");\r
+ System.out.println(" name | UpdateTime | GPStime | Latitude | Longitude | ele |magvar| km/h |");\r
+ System.out.println("------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|");\r
proc(imgDir, delta, gpxStartTime, gpxEndTime, map, exif, gpx);\r
- System.out.println("------------------------|--------------------|--------------------|------------|------------|--------|------|------|");\r
+ System.out.println("------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|");\r
\r
// 出力\r
outputFile.getParentFile().mkdirs();\r
if (trkptT.speedStr != null) {\r
speedStr = new String(trkptT.speedStr);\r
}\r
- System.out.print(String.format("%12s %12s|", (new Double(latitude)).toString(), (new Double(longitude)).toString()));\r
+ System.out.print(String.format("%-14s %-14s|", (new Double(latitude)).toString(), (new Double(longitude)).toString()));\r
System.out.println(String.format("%8s|%6s|%6s|", eleStr, magvarStr, speedStr));\r
}\r
\r
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.nio.channels.FileChannel;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.*;
import org.junit.experimental.runners.Enclosed;
import hayashi.tools.files.DeleteDir;
+import osm.jp.gpx.utils.TarGz;
@RunWith(Enclosed.class)
public class ImportPictureTest {
outDir.mkdir();
// カメラディレクトリを作成する
- TarGz.uncompress(new File("testdata", "Sony20170518.tar.gz"), dir);
+ uncompress(new File("testdata", "Sony20170518.tar.gz"), dir);
// GPXファイルをセット
try ( FileInputStream inStream = new FileInputStream(new File("testdata", "20170518.gpx"));
}
}
}
+
+ public static class GPXが複数のTRKSEGに分割している場合 {
+
+ @Before
+ public void setUp() throws Exception {
+ // カメラディレクトリを削除する
+ File dir = new File("testdata/cameradata");
+ if (dir.exists()) {
+ DeleteDir.delete(dir);
+ }
+ File outDir = new File("testdata/output");
+ if (outDir.exists()) {
+ DeleteDir.delete(outDir);
+ }
+ outDir.mkdir();
+
+ // カメラディレクトリを作成する
+ TarGz.uncompress(new File("testdata", "separate.tar.gz"), dir);
+
+ // GPXファイルをセット
+ try ( FileInputStream inStream = new FileInputStream(new File("testdata", "separate.gpx"));
+ FileOutputStream outStream = new FileOutputStream(new File("testdata/cameradata/separate.gpx"));
+ FileChannel inChannel = inStream.getChannel();
+ FileChannel outChannel = outStream.getChannel(); )
+ {
+ inChannel.transferTo(0, inChannel.size(), outChannel);
+ }
+
+ // プロパティファイルを設定
+ File iniFile = new File("AdjustTime.ini");
+ File orgFile = new File("AdjustTime.ini.org");
+ File testFile = new File("testdata", "AdjustTime.separate.ini");
+ if (orgFile.exists()) {
+ orgFile.delete();
+ }
+ if (iniFile.exists()) {
+ iniFile.renameTo(orgFile);
+ }
+ try ( FileInputStream inStream = new FileInputStream(testFile);
+ FileOutputStream outStream = new FileOutputStream(new File("AdjustTime.ini"));
+ FileChannel inChannel = inStream.getChannel();
+ FileChannel outChannel = outStream.getChannel(); )
+ {
+ inChannel.transferTo(0, inChannel.size(),outChannel);
+ }
+
+ AppParameters params = new AppParameters();
+ params.setProperty(AppParameters.IMG_TIME, "2017-05-29T10:31:46");
+ params.setProperty(AppParameters.IMG_BASE_FILE, "20170529_103146A.jpg");
+ params.setProperty(AppParameters.IMG_SOURCE_FOLDER, "./testdata/cameradata/separate");
+ params.setProperty(AppParameters.GPX_SOURCE_FOLDER, "./testdata/cameradata/separate.gpx");
+ params.store();
+ }
+
+ @Test
+ public void FILE_UPDATE時間を基準にして時間外のファイルはコピー対象外の時() throws Exception {
+ AppParameters params = new AppParameters();
+ params.setProperty(AppParameters.GPX_BASETIME, "FILE_UPDATE");
+ params.setProperty(AppParameters.IMG_OUTPUT_ALL, "false");
+ params.store();
+
+ // 実行する
+ testdo();
+
+ File gpxfile = new File("./testdata/output/cameradata/separate", "separate_.gpx");
+ assertThat(gpxfile.exists(), is(true));
+ File file0 = new File("./testdata/output/cameradata/separate", "20170529_102305A.jpg");
+ assertThat(file0.exists(), is(false));
+ File file1 = new File("./testdata/output/cameradata/separate", "20170529_103146A.jpg");
+ assertThat(file1.exists(), is(true));
+ File file3 = new File("./testdata/output/cameradata/separate", "20170529_103515A.jpg");
+ assertThat(file3.exists(), is(true));
+ File file4 = new File("./testdata/output/cameradata/separate", "20170529_104119A.jpg");
+ assertThat(file4.exists(), is(true));
+ }
+
+ @Test
+ public void EXIF時間を基準にして時間外のファイルはコピー対象外の時() throws Exception {
+ AppParameters params = new AppParameters();
+ params.setProperty(AppParameters.GPX_BASETIME, "EXIF_TIME");
+ params.setProperty(AppParameters.IMG_OUTPUT_ALL, "false");
+ params.store();
+
+ // 実行する
+ testdo();
+
+ File gpxfile = new File("./testdata/output/cameradata/separate", "separate_.gpx");
+ assertThat(gpxfile.exists(), is(true));
+ File file0 = new File("./testdata/output/cameradata/separate", "20170529_102305A.jpg");
+ assertThat(file0.exists(), is(false));
+ File file1 = new File("./testdata/output/cameradata/separate", "20170529_103146A.jpg");
+ assertThat(file1.exists(), is(true));
+ File file3 = new File("./testdata/output/cameradata/separate", "20170529_103515A.jpg");
+ assertThat(file3.exists(), is(true));
+ File file4 = new File("./testdata/output/cameradata/separate", "20170529_104119A.jpg");
+ assertThat(file4.exists(), is(true));
+ }
+
+ /**
+ * 実行する
+ * @throws Exception
+ */
+ public void testdo() {
+ try {
+ String[] argv = {
+ "./testdata/cameradata/separate",
+ "20170529_103146A.jpg",
+ "2017-05-29T10:31:46",
+ "./testdata/output",
+ "./testdata/cameradata/separate.gpx"
+ };
+ ImportPicture.main(argv);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ fail("Exceptionが発生した。");
+ }
+ }
+ }
+
+ /**
+ * *.tar.gz解凍
+ * ファイル更新日時をオリジナルと同じにします。
+ * @param tazFile 解凍する*.tar.gzファイル
+ * @param dest 解凍先フォルダ
+ * @throws IOException
+ */
+ public static void uncompress(File tazFile, File dest) throws IOException {
+ dest.mkdir();
+
+ TarArchiveInputStream tarIn = null;
+ tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tazFile))));
+
+ TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
+ while (tarEntry != null) {
+ File destPath = new File(dest, tarEntry.getName());
+ System.out.println("uncompress: " + destPath.getCanonicalPath());
+ if (tarEntry.isDirectory()) {
+ destPath.mkdirs();
+ }
+ else {
+ File dir = new File(destPath.getParent());
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+ destPath.createNewFile();
+ byte[] btoRead = new byte[1024];
+ BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath));
+ int len = 0;
+
+ while ((len = tarIn.read(btoRead)) != -1) {
+ bout.write(btoRead, 0, len);
+ }
+
+ bout.close();
+ destPath.setLastModified(tarEntry.getLastModifiedDate().getTime());
+ btoRead = null;
+ }
+ tarEntry = tarIn.getNextTarEntry();
+ }
+ tarIn.close();
+ }
}