diff --git a/src/main/java/osm/surveyor/matchtime/AppParameters.java b/src/main/java/osm/surveyor/matchtime/AppParameters.java deleted file mode 100644 index a96d284..0000000 --- a/src/main/java/osm/surveyor/matchtime/AppParameters.java +++ /dev/null @@ -1,102 +0,0 @@ -package osm.surveyor.matchtime; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; - -@SuppressWarnings("serial") -public class AppParameters extends Properties { - static final String FILE_PATH = "ReStamp.properties"; - - // GPX: ファイル更新時刻 yyyy:MM:dd HH:mm:ss - public static String IMG_TIME = "IMG.TIME"; - - // 対象IMGフォルダ:(位置情報を付加したい画像ファイルが格納されているフォルダ) - public static String IMG_SOURCE_FOLDER = "IMG.SOURCE_FOLDER"; - - // 基準時刻画像(正確な撮影時刻が判明できる画像) - public static String IMG_BASE_FILE = "IMG.BASE_FILE"; - - // 出力フォルダ:(変換した画像ファイルとGPXファイルを出力するフォルダ) - public static String IMG_OUTPUT_FOLDER = "IMG.OUTPUT_FOLDER"; - - // 出力OverwriteToSource: 入力ファイルに上書きする {ON | OFF} - public static String OUTPUT_OVERWRITE_TO_SOURCE= "IMG.OUTPUT_OVERWRITE_TO_SOURCE"; - - File file; - - public AppParameters() throws FileNotFoundException, IOException { - super(); - this.file = new File(FILE_PATH); - syncFile(); - } - - public AppParameters(Properties defaults) throws FileNotFoundException, IOException { - super(defaults); - this.file = new File(FILE_PATH); - syncFile(); - } - - public AppParameters(String iniFileName) throws FileNotFoundException, IOException { - super(); - this.file = new File(iniFileName); - syncFile(); - } - - private void syncFile() throws FileNotFoundException, IOException { - boolean update = false; - - if (this.file.exists()) { - // ファイルが存在すれば、その内容をロードする。 - this.load(new FileInputStream(file)); - } - else { - update = true; - } - - //------------------------------------------------ - // 対象フォルダ:(位置情報を付加したい画像ファイルが格納されているフォルダ) - String valueStr = this.getProperty(IMG_SOURCE_FOLDER); - if (valueStr == null) { - update = true; - this.setProperty(IMG_SOURCE_FOLDER, (new File(".")).getAbsolutePath()); - } - - //------------------------------------------------ - // 基準時刻画像(正確な撮影時刻が判明できる画像) - valueStr = this.getProperty(IMG_BASE_FILE); - if (valueStr == null) { - update = true; - this.setProperty(IMG_BASE_FILE, ""); - } - - //------------------------------------------------ - // 出力フォルダ:(変換した画像ファイルとGPXファイルを出力するフォルダ) - valueStr = this.getProperty(IMG_OUTPUT_FOLDER); - if (valueStr == null) { - update = true; - this.setProperty(IMG_OUTPUT_FOLDER, (new File(".")).getAbsolutePath()); - } - - //------------------------------------------------ - // 出力: 入力ファイルに上書きする {ON | OFF} - valueStr = this.getProperty(OUTPUT_OVERWRITE_TO_SOURCE); - if (valueStr == null) { - update = true; - this.setProperty(OUTPUT_OVERWRITE_TO_SOURCE, String.valueOf(false)); - } - - if (update) { - // ・ファイルがなければ新たに作る - // ・項目が足りない時は書き足す。 - this.store(new FileOutputStream(this.file), "defuilt settings"); - } - } - - public void store() throws FileNotFoundException, IOException { - this.store(new FileOutputStream(this.file), "by Restamp"); - } -} diff --git a/src/main/java/osm/surveyor/util/Exif.java b/src/main/java/osm/surveyor/util/Exif.java deleted file mode 100644 index a7ac358..0000000 --- a/src/main/java/osm/surveyor/util/Exif.java +++ /dev/null @@ -1,80 +0,0 @@ -package osm.surveyor.util; - -import java.io.*; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.TimeZone; - -public class Exif extends Thread { - public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - private static final String EXIF_DATE_TIME_FORMAT_STRING = "yyyy:MM:dd HH:mm:ss"; - - /** - * 対象は '*.JPG' のみ対象とする - * @return - * @param name - */ - public static boolean checkFile(String name) { - return ((name != null) && name.toUpperCase().endsWith(".JPG")); - } - - /** - * DateをEXIFの文字列に変換する。 - * 注意:EXiFの撮影時刻はUTC時間ではない - * @param localdate - * @return - */ - public static String toEXIFString(Date localdate) { - DateFormat dfUTC = new SimpleDateFormat(EXIF_DATE_TIME_FORMAT_STRING); - return dfUTC.format(localdate); - } - - /** - * EXIFの文字列をDateに変換する。 - * 注意:EXiFの撮影時刻はUTC時間ではない - * @param timeStr - * @return - * @throws ParseException - */ - public static Date toEXIFDate(String timeStr) throws ParseException { - DateFormat dfUTC = new SimpleDateFormat(EXIF_DATE_TIME_FORMAT_STRING); - //dfUTC.setTimeZone(TimeZone.getTimeZone("UTC")); - return dfUTC.parse(timeStr); - } - - public static String toUTCString(Date localdate) { - DateFormat dfUTC = new SimpleDateFormat(TIME_FORMAT_STRING); - dfUTC.setTimeZone(TimeZone.getTimeZone("UTC")); - return dfUTC.format(localdate); - } - - public static Date toUTCDate(String timeStr) throws ParseException { - DateFormat dfUTC = new SimpleDateFormat(TIME_FORMAT_STRING); - dfUTC.setTimeZone(TimeZone.getTimeZone("UTC")); - return dfUTC.parse(timeStr); - } - - static String getShortPathName(File dir, File iFile) { - String dirPath = dir.getAbsolutePath(); - String filePath = iFile.getAbsolutePath(); - if (filePath.startsWith(dirPath)) { - return filePath.substring(dirPath.length()+1); - } - else { - return filePath; - } - } - - /** - * JPEGファイルフィルター - * @author yuu - */ - class JpegFileFilter implements FilenameFilter { - @Override - public boolean accept(File dir, String name) { - return name.toUpperCase().matches(".*\\.JPG$"); - } - } -} \ No newline at end of file diff --git a/src/main/java/osm/surveyor/util/GeoDistance.java b/src/main/java/osm/surveyor/util/GeoDistance.java deleted file mode 100644 index 960794f..0000000 --- a/src/main/java/osm/surveyor/util/GeoDistance.java +++ /dev/null @@ -1,71 +0,0 @@ -package osm.surveyor.util; - -/** - * The MIT License (MIT) - * Copyright(C) 2007-2012 やまだらけ - * http://yamadarake.jp/trdi/report000001.html - * 「Cords.java」を改変 - * 2016-10-03 - * - * @author やまだらけ yama_darake@yahoo.co.jp - * - */ -public class GeoDistance { - - public static final double GRS80_A = 6378137.000; // 赤道半径(m) - public static final double GRS80_E2 = 0.00669438002301188; - public static final double GRS80_MNUM = 6335439.32708317; // - - public static final double WGS84_A = 6378137.000; - public static final double WGS84_E2 = 0.00669437999019758; - public static final double WGS84_MNUM = 6335439.32729246; - - /** - * 角度(180度)をラジアン(2π)に変換する - * @param deg - * @return - */ - public static double deg2rad(double deg){ - return deg * Math.PI / 180.0; - } - - /** - * 距離(m)を返す - * @param lat1 - * @param lng1 - * @param lat2 - * @param lng2 - * @return - */ - public static double calcDistHubeny(double lat1, double lng1, - double lat2, double lng2){ - double my = deg2rad((lat1 + lat2) / 2.0); // 平均緯度 - double dy = deg2rad(lat1 - lat2); // 2点間の緯度 - double dx = deg2rad(lng1 - lng2); // 2点間の経度 - - double sin = Math.sin(my); - double w = Math.sqrt(1.0 - GRS80_E2 * sin * sin); - double m = GRS80_MNUM / (w * w * w); - double n = GRS80_A / w; - - double dym = dy * m; - double dxncos = dx * n * Math.cos(my); - - return Math.sqrt(dym * dym + dxncos * dxncos); - } - - - public static void main(String[] args){ - System.out.println("Coords Test Program"); - double lat1, lng1, lat2, lng2; - - lat1 = Double.parseDouble(args[0]); - lng1 = Double.parseDouble(args[1]); - lat2 = Double.parseDouble(args[2]); - lng2 = Double.parseDouble(args[3]); - - double d = calcDistHubeny(lat1, lng1, lat2, lng2); - - System.out.println("Distance = " + d + " m"); - } -} \ No newline at end of file diff --git a/src/main/java/osm/surveyor/util/TimeComparator.java b/src/main/java/osm/surveyor/util/TimeComparator.java deleted file mode 100644 index c6997e0..0000000 --- a/src/main/java/osm/surveyor/util/TimeComparator.java +++ /dev/null @@ -1,21 +0,0 @@ -package osm.surveyor.util; - -import java.util.Comparator; -import java.util.Date; - -/** - * java.util.Date型をコレクションのKEYにした時に、時間順に並べ替える - * - */ -public class TimeComparator implements Comparator<Date> -{ - /** - * 日付順にソート - * @param arg0 - * @param arg1 - */ - @Override - public int compare(Date arg0, Date arg1) { - return arg0.compareTo(arg1); - } -} diff --git a/src/main/java/osm/surveyor/util/YuuLogFormatter.java b/src/main/java/osm/surveyor/util/YuuLogFormatter.java deleted file mode 100644 index f78bf16..0000000 --- a/src/main/java/osm/surveyor/util/YuuLogFormatter.java +++ /dev/null @@ -1,48 +0,0 @@ -package osm.surveyor.util; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.logging.Formatter; -import java.util.logging.Level; -import java.util.logging.LogRecord; - -/** - * シンプルなサンプルログフォーマッタ - */ -public class YuuLogFormatter extends Formatter { - private final SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); - - @Override - public String format(final LogRecord argLogRecord) { - final StringBuffer buf = new StringBuffer(); - - buf.append(sdFormat.format(new Date(argLogRecord.getMillis()))).append(" "); - - if (argLogRecord.getLevel() == Level.FINEST) { - buf.append("[FINEST]"); - } - else if (argLogRecord.getLevel() == Level.FINER) { - buf.append("[FINER]"); - } - else if (argLogRecord.getLevel() == Level.FINE) { - buf.append("[FINE]"); - } - else if (argLogRecord.getLevel() == Level.CONFIG) { - buf.append("[CONFIG]"); - } - else if (argLogRecord.getLevel() == Level.INFO) { - buf.append("[INFO]"); - } - else if (argLogRecord.getLevel() == Level.WARNING) { - buf.append("[WARN]"); - } - else if (argLogRecord.getLevel() == Level.SEVERE) { - buf.append("[SEVERE]"); - } - else { - buf.append(Integer.toString(argLogRecord.getLevel().intValue())).append(" "); - } - buf.append(" ").append(argLogRecord.getMessage()).append("\n"); - return buf.toString(); - } -} \ No newline at end of file diff --git a/src/test/java/osm/surveyor/matchtime/AppParametersTest.java b/src/test/java/osm/surveyor/matchtime/AppParametersTest.java deleted file mode 100644 index 6ff0a01..0000000 --- a/src/test/java/osm/surveyor/matchtime/AppParametersTest.java +++ /dev/null @@ -1,191 +0,0 @@ -package osm.surveyor.matchtime; - -import static org.junit.Assert.*; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.channels.FileChannel; -import java.util.Properties; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.experimental.runners.*; - -@RunWith(Enclosed.class) -public class AppParametersTest { - static final String DEFUALT_FILE_NAME = "ReStamp.properties"; - - public static class 定義ファイルが存在しない場合 { - - @Before - public void setUp() throws Exception { - delTestData(DEFUALT_FILE_NAME); - } - - @After - public void tearDown() throws Exception { - delTestData(DEFUALT_FILE_NAME); - delTestData("ReStamp.nosource.properties"); - delTestData("ReStamp.xx.properties"); - } - - - @Test - public void 引数なしで起動されたとき() { - // デフォルトプロパティファイルが適用されること - try { - AppParameters params = new AppParameters(); - String valueStr = params.getProperty(AppParameters.IMG_SOURCE_FOLDER); - assertNotNull(valueStr); - File sourceDir = new File(valueStr); - String sourcePath = sourceDir.getAbsolutePath(); - File cDir = new File("."); - String cPath = cDir.getAbsolutePath(); - assertEquals(sourcePath, cPath); - } - catch (IOException e) { - fail("Exceptionが発生した。"); - } - } - - @Test - public void IMG_SOURCE_FOLDERが定義されていない時() { - try { - // デフォルトに カレントディレクトリが戻ること - AppParameters params = new AppParameters("target/test-classes/ReStamp.nosource.properties"); - String valueStr = params.getProperty(AppParameters.IMG_SOURCE_FOLDER); - assertNotNull(valueStr); - File sourceDir = new File(valueStr); - String sourcePath = sourceDir.getAbsolutePath(); - File cDir = new File("."); - String cPath = cDir.getAbsolutePath(); - assertEquals(sourcePath, cPath); - } - catch (IOException e) { - fail("Exceptionが発生した。"); - } - } - - @Test - public void propertyファイルが存在しないとき() { - try { - // デフォルトプロパティファイルが適用されること - AppParameters params = new AppParameters("target/test-classes/ReStamp.xx.properties"); - String valueStr = params.getProperty(AppParameters.IMG_SOURCE_FOLDER); - assertNotNull(valueStr); - File sourceDir = new File(valueStr); - String sourcePath = sourceDir.getAbsolutePath(); - File cDir = new File("."); - String cPath = cDir.getAbsolutePath(); - assertEquals(sourcePath, cPath); - } - catch (IOException e) { - fail("Exceptionが発生した。"); - } - } - - @Test - public void propertyが指定されたとき() { - // デフォルトプロパティファイルが適用されること - try { - Properties prop = new Properties(); - AppParameters params = new AppParameters(prop); - String valueStr = params.getProperty(AppParameters.IMG_SOURCE_FOLDER); - assertNotNull(valueStr); - File sourceDir = new File(valueStr); - String sourcePath = sourceDir.getAbsolutePath(); - File cDir = new File("."); - String cPath = cDir.getAbsolutePath(); - assertEquals(sourcePath, cPath); - } - catch (IOException e) { - fail("Exceptionが発生した。"); - } - } - } - - public static class 空の定義ファイルが指定された場合 { - - @Before - public void setUp() throws Exception { - delTestData(DEFUALT_FILE_NAME); - setupTestData("ReStamp.nosource.properties", "ReStamp.properties"); - } - - @After - public void tearDown() throws Exception { - delTestData(DEFUALT_FILE_NAME); - } - - @Test - public void IMG_SOURCE_FOLDERが定義されていない時() { - try { - // デフォルトに カレントディレクトリが戻ること - AppParameters params = new AppParameters("target/test-classes/ReStamp.properties"); - String valueStr = params.getProperty(AppParameters.IMG_SOURCE_FOLDER); - assertNotNull(valueStr); - File sourceDir = new File(valueStr); - String sourcePath = sourceDir.getAbsolutePath(); - File cDir = new File("."); - String cPath = cDir.getAbsolutePath(); - assertEquals(sourcePath, cPath); - - // 書き換える - params.setProperty(AppParameters.IMG_SOURCE_FOLDER, "xxx"); - params.store(); - } - catch (IOException e) { - fail("Exceptionが発生した。"); - } - try { - // デフォルトに カレントディレクトリが戻ること - Properties prop = new Properties(); - File f = new File("target/test-classes/ReStamp.properties"); - prop.load(new FileInputStream(f)); - - String valueStr = prop.getProperty(AppParameters.IMG_SOURCE_FOLDER); - assertNotNull(valueStr); - assertEquals(valueStr, "xxx"); - } - catch (IOException e) { - fail("Exceptionが発生した。"); - } - } - } - - static void delTestData(String filename) { - File ddir = new File("target/test-classes/"); - File iniFile = new File(ddir, filename); - if (iniFile.exists()) { - iniFile.delete(); - } - ddir = new File("."); - iniFile = new File(ddir, filename); - if (iniFile.exists()) { - iniFile.delete(); - } - } - - static void setupTestData(String sfilename, String dfilename) throws IOException { - File ddir = new File("target/test-classes/"); - File sdir = new File("target/test-classes/props/"); - File testFile = new File(sdir, sfilename); - FileInputStream inStream = new FileInputStream(testFile); - FileOutputStream outStream = new FileOutputStream(new File(ddir, dfilename)); - FileChannel inChannel = inStream.getChannel(); - FileChannel outChannel = outStream.getChannel(); - try { - inChannel.transferTo(0, inChannel.size(),outChannel); - } - finally { - if (inChannel != null) inChannel.close(); - if (outChannel != null) outChannel.close(); - inStream.close(); - outStream.close(); - } - } -} diff --git a/src/test/java/osm/surveyor/matchtime/UnZip.java b/src/test/java/osm/surveyor/matchtime/UnZip.java deleted file mode 100644 index 76eac6f..0000000 --- a/src/test/java/osm/surveyor/matchtime/UnZip.java +++ /dev/null @@ -1,75 +0,0 @@ -package osm.surveyor.matchtime; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -public class UnZip { - - /** - * Zipファイルを展開します - * @param aZipFile zipファイル - * @param aOutDir 出力先ディレクトリ - * @throws java.io.IOException - */ - public static void decode(File aZipFile, String aOutDir) throws IOException { - FileInputStream fileIn = null; - FileOutputStream fileOut = null; - ZipInputStream zipIn = null; - - try { - File outDir = new File(aOutDir); - outDir.mkdirs(); - - fileIn = new FileInputStream(aZipFile); - zipIn = new ZipInputStream(fileIn); - - ZipEntry entry = null; - while ((entry = zipIn.getNextEntry()) != null) { - if (entry.isDirectory()) { - String relativePath = entry.getName(); - outDir = new File(outDir, relativePath); - outDir.mkdirs(); - } - else { - String relativePath = entry.getName(); - File outFile = new File( outDir, relativePath ); - - File parentFile = outFile.getParentFile(); - parentFile.mkdirs(); - - fileOut = new FileOutputStream( outFile ); - - byte[] buf = new byte[ 256 ]; - int size = 0; - while ((size = zipIn.read(buf)) > 0){ - fileOut.write(buf, 0, size); - } - fileOut.close(); - fileOut = null; - } - zipIn.closeEntry(); - } - } - catch (IOException e) { - e.printStackTrace(); - } - finally { - if (fileIn != null) { - try { - fileIn.close(); - } - catch (IOException e) {} - } - if (fileOut != null) { - try { - fileOut.close(); - } - catch(IOException e) {} - } - zipIn.close(); - } - } -}