diff --git a/importPicture/build.xml b/importPicture/build.xml
index 3ffaf85..27b3f7e 100644
--- a/importPicture/build.xml
+++ b/importPicture/build.xml
@@ -17,6 +17,26 @@
+
+
+
+
+
+
+
+
+
+
@@ -30,8 +50,8 @@
-
-
+
+
@@ -61,6 +81,7 @@
+
diff --git a/importPicture/importPictute.sh b/importPicture/importPictute.sh
new file mode 100755
index 0000000..4087038
--- /dev/null
+++ b/importPicture/importPictute.sh
@@ -0,0 +1,7 @@
+java -jar importPicture.jar list.csv /home/hayashi/osm/20140101/10040101 DSC01396.JPG 2014-01-01T15:46:56 "/home/hayashi/osm/20140101/2014-01-01 09.14.01 自動.gpx"
+java -jar importPicture.jar list.csv /home/hayashi/osm/20140101/10040101 DSC01396.JPG 2014-01-01T15:46:56 "/home/hayashi/osm/20140101/2014-01-01 09.59.09 自動.gpx"
+java -jar importPicture.jar list.csv /home/hayashi/osm/20140101/10040101 DSC01396.JPG 2014-01-01T15:46:56 "/home/hayashi/osm/20140101/2014-01-01 10.44.19 自動.gpx"
+java -jar importPicture.jar list.csv /home/hayashi/osm/20140101/10040101 DSC01396.JPG 2014-01-01T15:46:56 "/home/hayashi/osm/20140101/2014-01-01 11.29.22 自動.gpx"
+java -jar importPicture.jar list.csv /home/hayashi/osm/20140101/10040101 DSC01396.JPG 2014-01-01T15:46:56 "/home/hayashi/osm/20140101/2014-01-01 12.14.49 自動.gpx"
+java -jar importPicture.jar list.csv /home/hayashi/osm/20140101/10040101 DSC01396.JPG 2014-01-01T15:46:56 "/home/hayashi/osm/20140101/20140101.gpx"
+java -jar importPicture.jar list.csv /home/hayashi/osm/20140101/10040101 DSC01396.JPG 2014-01-01T15:46:56 "/home/hayashi/osm/20140101/Current.gpx"
diff --git a/importPicture/src/osm/jp/gpx/ImportPicture.java b/importPicture/src/osm/jp/gpx/ImportPicture.java
index 67e2e3e..b5e7520 100644
--- a/importPicture/src/osm/jp/gpx/ImportPicture.java
+++ b/importPicture/src/osm/jp/gpx/ImportPicture.java
@@ -2,6 +2,8 @@
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
@@ -79,7 +81,7 @@
String fileName = gpxFile.getName();
String iStr = fileName.substring(0, fileName.length() - 4);
- File outputFile = new File(iStr +"_.gpx");
+ File outputFile = new File(gpxFile.getParent(), iStr +"_.gpx");
System.out.println(iStr + " => "+ outputFile.getName());
try {
@@ -130,26 +132,49 @@
try {
Date t = dfjp.parse(timeStr);
long delta = t.getTime() - jptime.getTime();
+
+ /*
+ * GPXへ割りつける開始時刻と終了時刻を求める
+ */
+ long gpxStartTime = (new Date()).getTime(); // 対象とする開始時刻
+ long gpxEndTime = 0L; // 対象とする終了時刻
+ Set keySet = map.keySet(); //すべてのキー値を取得
+ for (Iterator keyIte = keySet.iterator(); keyIte.hasNext();) {
+ Long timeLong = (Long)keyIte.next();
+ long gpxTime = timeLong.longValue();
+ if (gpxStartTime > gpxTime) {
+ gpxStartTime = gpxTime;
+ }
+ if (gpxEndTime < gpxTime) {
+ gpxEndTime = gpxTime;
+ }
+ }
+
System.out.println("時差: "+ (delta / 1000) +"(sec)");
- pw.println("時差: "+ (delta / 1000) +"(sec)");
- ImportPicture.proc(dir, csvfile, delta);
+ pw.println(" 時差: "+ (delta / 1000) +"(sec)");
+ pw.println(" Target GPX: ["+ gpxFile.getName() +"]");
+ pw.println("GPX start time: "+ dfjp.format(new Date(gpxStartTime).getTime()));
+ pw.println(" GPX end time: "+ dfjp.format(new Date(gpxEndTime).getTime()));
pw.println("\"name\",\"orignal\",\"gpstime\"");
File[] files = dir.listFiles();
+ Arrays.sort(files, new FileSort());
for (File image : files) {
String imageName = image.getName();
if (checkFile(imageName)) {
Date itime = new Date(image.lastModified());
Date uktime = new Date(itime.getTime() + delta);
- pw.print("\""+ fileName +"\",");
- pw.print("\""+ dfjp.format(itime) +"\",");
- pw.println("\""+ dfjp.format(uktime) +"\"");
+ if ((uktime.getTime() >= gpxStartTime) && (uktime.getTime() <= gpxEndTime)) {
+ Element trkpt = trkpt(map, uktime);
+ if (trkpt != null) {
+ pw.print("\""+ image.getName() +"\",");
+ pw.print("\""+ dfjp.format(itime) +"\",");
+ pw.println("\""+ dfjp.format(uktime) +"\"");
- Element trkpt = trkpt(map, uktime);
- if (trkpt != null) {
- Element wpt = createWptTag(dir, image, uktime.getTime(), trkpt);
- Element temp = getCopy(gpx.getOwnerDocument(), wpt);
- gpx.appendChild(temp);
+ Element wpt = createWptTag(dir, image, uktime.getTime(), trkpt);
+ Element temp = getCopy(gpx.getOwnerDocument(), wpt);
+ gpx.appendChild(temp);
+ }
}
}
}
@@ -198,6 +223,15 @@
static SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
static SimpleDateFormat dfuk = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.UK);
+ /**
+ * XMLエレメントをTIMEでキー付したHashMapを生成する
+ *
+ *
+ *
+ * @param trk
+ * @return
+ * @throws ParseException
+ */
public static HashMap trkptMap(Element trk) throws ParseException {
HashMap map = new HashMap();
@@ -243,63 +277,21 @@
Element ret = null;
Set keySet = map.keySet(); //すべてのキー値を取得
- Iterator keyIte = keySet.iterator();
- while (keyIte.hasNext()) { //ループ。反復子iteratorによる キー 取得
- Long time = keyIte.next();
- long t = time.longValue();
+ Iterator keyIte = keySet.iterator();
+ while (keyIte.hasNext()) { //ループ。反復子iteratorによる キー 取得
+ Long time = keyIte.next();
+ long t = time.longValue();
if (Math.abs(jpt - t) < sa) {
sa = Math.abs(jpt - t);
ret = map.get(time);
}
- }
+ }
- if (sa < (60000L * 10L)) {
+ if (sa < (60000L * 10L)) {
System.out.println(dfuk.format(jpt) +" ("+ sa +")");
return ret;
}
- return null;
- }
-
- /**
- *
- *
- * 62.099998474121094
- *
- *
- *
- * 2012-06-11_09-44-38.jpg
- *
- *
- *
- * @param dir
- * @param csvfile
- * @param delta
- * @throws IOException
- */
- public static void proc (File dir, File csvfile, long delta) throws IOException {
- int counter = 0;
- PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(csvfile)));
- pw.println("\"name\",\"orignal\",\"gpstime\"");
-
- try {
- File[] files = dir.listFiles();
- for (File iFile : files) {
- String fileName = iFile.getName();
- if (checkFile(fileName)) {
- counter++;
- Date jptime = new Date(iFile.lastModified());
- Date uktime = new Date(jptime.getTime() + delta);
- pw.print("\""+ fileName +"\",");
- pw.print("\""+ dfjp.format(jptime) +"\",");
- pw.println("\""+ dfjp.format(uktime) +"\"");
- }
- }
- }
- finally {
- pw.close();
- System.out.println("Image file count = "+ counter);
- }
- System.out.println("SUCESS 'ListUpdateTime' => '"+ csvfile.getAbsolutePath() +"' !");
+ return null;
}
/**
@@ -425,4 +417,17 @@
}
return root;
}
+
+ /**
+ * ファイル名の順序に並び替えるためのソートクラス
+ *
+ * @author hayashi
+ */
+ static class FileSort implements Comparator{
+ public int compare(File src, File target){
+ int diff = src.getName().compareTo(target.getName());
+ return diff;
+ }
+ }
+
}
\ No newline at end of file