| | package osm.jp.gpx; |
---|
| | import java.io.*; |
---|
| | import java.nio.channels.FileChannel; |
---|
| | import java.text.DecimalFormat; |
---|
| | import java.text.ParseException; |
---|
| | import java.text.SimpleDateFormat; |
---|
| | import java.util.ArrayList; |
---|
| |
---|
| | } |
---|
| | |
---|
| | paramStr = obj.params.getProperty(AppParameters.IMG_OUTPUT_ALL); |
---|
| | if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) { |
---|
| | obj.param_GpxOutputWpt = true; |
---|
| | obj.param_ImgOutputAll = true; |
---|
| | } |
---|
| | |
---|
| | paramStr = obj.params.getProperty(AppParameters.GPX_OUTPUT_WPT); |
---|
| | if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) { |
---|
| |
---|
| | } |
---|
| | |
---|
| | // 時刻uktimeにおける<magver>をtrkptに追加する |
---|
| | Element trkptE = trkpt(map, uktime); |
---|
| | String eleStr = "-"; |
---|
| | String magvarStr = "-"; |
---|
| | String speedStr = "-"; |
---|
| | double latitude = 90.5D; |
---|
| | double longitude = 180.5D; |
---|
| | TagTrkpt trkptT = null; |
---|
| | if (trkptE == null) { |
---|
| | System.out.println(String.format("%20s ", "Out of GPX logging time.")); |
---|
| | continue; |
---|
| | } |
---|
| | |
---|
| | TagTrkpt trkptT = new TagTrkpt(trkptE); |
---|
| | |
---|
| | //Element wpt = createWptTag(image, uktime.getTime(), trkptE); |
---|
| | //String latStr = trkptT.lat.toString(); |
---|
| | //String lonStr = trkptT.lon.toString(); |
---|
| | double latitude = trkptT.lat; |
---|
| | double longitude = trkptT.lon; |
---|
| | |
---|
| | String eleStr = "-"; |
---|
| | if (trkptT.eleStr != null) { |
---|
| | eleStr = new String(trkptT.eleStr); |
---|
| | } |
---|
| | |
---|
| | String magvarStr = "-"; |
---|
| | if (trkptT.magvarStr != null) { |
---|
| | magvarStr = new String(trkptT.magvarStr); |
---|
| | } |
---|
| | |
---|
| | String speedStr = "-"; |
---|
| | if (trkptT.speedStr != null) { |
---|
| | speedStr = new String(trkptT.speedStr); |
---|
| | } |
---|
| | |
---|
| | System.out.print(String.format("%12s %12s|", (new Double(latitude)).toString(), (new Double(longitude)).toString())); |
---|
| | System.out.println(String.format("%8s|%6s|%6s|", eleStr, magvarStr, speedStr)); |
---|
| | if (!this.param_ImgOutputAll) { |
---|
| | continue; |
---|
| | } |
---|
| | } |
---|
| | else { |
---|
| | trkptT = new TagTrkpt(trkptE); |
---|
| | |
---|
| | //Element wpt = createWptTag(image, uktime.getTime(), trkptE); |
---|
| | //String latStr = trkptT.lat.toString(); |
---|
| | //String lonStr = trkptT.lon.toString(); |
---|
| | latitude = trkptT.lat; |
---|
| | longitude = trkptT.lon; |
---|
| | |
---|
| | if (trkptT.eleStr != null) { |
---|
| | eleStr = new String(trkptT.eleStr); |
---|
| | } |
---|
| | |
---|
| | if (trkptT.magvarStr != null) { |
---|
| | magvarStr = new String(trkptT.magvarStr); |
---|
| | } |
---|
| | |
---|
| | if (trkptT.speedStr != null) { |
---|
| | speedStr = new String(trkptT.speedStr); |
---|
| | } |
---|
| | System.out.print(String.format("%12s %12s|", (new Double(latitude)).toString(), (new Double(longitude)).toString())); |
---|
| | System.out.println(String.format("%8s|%6s|%6s|", eleStr, magvarStr, speedStr)); |
---|
| | } |
---|
| | |
---|
| | ret = true; |
---|
| | FileOutputStream fos = null; |
---|
| | outDir.mkdir(); |
---|
| | |
---|
| | if (exifWrite) { |
---|
| | TiffOutputSet outputSet = null; |
---|
| | FileOutputStream fos = null; |
---|
| | |
---|
| | ImageMetadata meta = Imaging.getMetadata(image); |
---|
| | JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; |
---|
| | if (jpegMetadata != null) { |
---|
| |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP, dateStamp); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS elevation/ALTITUDE ---- |
---|
| | if (eleStr.equals("-") == false) { |
---|
| | final double altitude = Double.parseDouble(eleStr); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE, RationalNumber.valueOf(altitude)); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS magvar/IMG_DIRECTION ---- |
---|
| | if (magvarStr.equals("-") == false) { |
---|
| | final double magvar = Double.parseDouble(magvarStr); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION, RationalNumber.valueOf(magvar)); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS_ ---- |
---|
| | final String longitudeRef = (longitude < 0 ? "W" : "E"); |
---|
| | longitude = Math.abs(longitude); |
---|
| | final String latitudeRef = (latitude < 0 ? "S" : "N"); |
---|
| | latitude = Math.abs(latitude); |
---|
| | |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF, longitudeRef); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF, latitudeRef); |
---|
| | { |
---|
| | double value = longitude; |
---|
| | final double longitudeDegrees = (long) value; |
---|
| | value %= 1; |
---|
| | value *= 60.0; |
---|
| | final double longitudeMinutes = (long) value; |
---|
| | value %= 1; |
---|
| | value *= 60.0; |
---|
| | final double longitudeSeconds = value; |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LONGITUDE, |
---|
| | RationalNumber.valueOf(longitudeDegrees), |
---|
| | RationalNumber.valueOf(longitudeMinutes), |
---|
| | RationalNumber.valueOf(longitudeSeconds)); |
---|
| | } |
---|
| | { |
---|
| | double value = latitude; |
---|
| | final double latitudeDegrees = (long) value; |
---|
| | value %= 1; |
---|
| | value *= 60.0; |
---|
| | final double latitudeMinutes = (long) value; |
---|
| | value %= 1; |
---|
| | value *= 60.0; |
---|
| | final double latitudeSeconds = value; |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LATITUDE, |
---|
| | RationalNumber.valueOf(latitudeDegrees), |
---|
| | RationalNumber.valueOf(latitudeMinutes), |
---|
| | RationalNumber.valueOf(latitudeSeconds)); |
---|
| | } |
---|
| | |
---|
| | outDir.mkdir(); |
---|
| | if (trkptE != null) { |
---|
| | //---- EXIF GPS elevation/ALTITUDE ---- |
---|
| | if (eleStr.equals("-") == false) { |
---|
| | final double altitude = Double.parseDouble(eleStr); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE, RationalNumber.valueOf(altitude)); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS magvar/IMG_DIRECTION ---- |
---|
| | if (magvarStr.equals("-") == false) { |
---|
| | final double magvar = Double.parseDouble(magvarStr); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION, RationalNumber.valueOf(magvar)); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS_ ---- |
---|
| | final String longitudeRef = (longitude < 0 ? "W" : "E"); |
---|
| | longitude = Math.abs(longitude); |
---|
| | final String latitudeRef = (latitude < 0 ? "S" : "N"); |
---|
| | latitude = Math.abs(latitude); |
---|
| | |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF, longitudeRef); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF, latitudeRef); |
---|
| | { |
---|
| | double value = longitude; |
---|
| | final double longitudeDegrees = (long) value; |
---|
| | value %= 1; |
---|
| | value *= 60.0; |
---|
| | final double longitudeMinutes = (long) value; |
---|
| | value %= 1; |
---|
| | value *= 60.0; |
---|
| | final double longitudeSeconds = value; |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LONGITUDE, |
---|
| | RationalNumber.valueOf(longitudeDegrees), |
---|
| | RationalNumber.valueOf(longitudeMinutes), |
---|
| | RationalNumber.valueOf(longitudeSeconds)); |
---|
| | } |
---|
| | { |
---|
| | double value = latitude; |
---|
| | final double latitudeDegrees = (long) value; |
---|
| | value %= 1; |
---|
| | value *= 60.0; |
---|
| | final double latitudeMinutes = (long) value; |
---|
| | value %= 1; |
---|
| | value *= 60.0; |
---|
| | final double latitudeSeconds = value; |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_LATITUDE); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_LATITUDE, |
---|
| | RationalNumber.valueOf(latitudeDegrees), |
---|
| | RationalNumber.valueOf(latitudeMinutes), |
---|
| | RationalNumber.valueOf(latitudeSeconds)); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | ExifRewriter rewriter = new ExifRewriter(); |
---|
| | try { |
---|
| | fos = new FileOutputStream(new File(outDir, imageName)); |
---|
| | rewriter.updateExifMetadataLossy(image, fos, outputSet); |
---|
| |
---|
| | if (fos != null) { |
---|
| | fos.close(); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | if (Boolean.parseBoolean(params.getProperty(AppParameters.GPX_OUTPUT_WPT))) { |
---|
| | Element temp = createWptTag(image, itime.getTime(), trkptT.trkpt); |
---|
| | gpx.appendChild(temp); |
---|
| | |
---|
| | if (Boolean.parseBoolean(params.getProperty(AppParameters.GPX_OUTPUT_WPT))) { |
---|
| | if (trkptT != null) { |
---|
| | Element temp = createWptTag(image, itime.getTime(), trkptT.trkpt); |
---|
| | gpx.appendChild(temp); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | else { |
---|
| | if (this.param_ImgOutputAll) { |
---|
| | // EXIFの変換を伴わない単純なファイルコピー |
---|
| | FileInputStream sStream = new FileInputStream(image); |
---|
| | FileInputStream dStream = new FileInputStream(new File(outDir, imageName)); |
---|
| | FileChannel srcChannel = sStream.getChannel(); |
---|
| | FileChannel destChannel = dStream.getChannel(); |
---|
| | try { |
---|
| | srcChannel.transferTo(0, srcChannel.size(), destChannel); |
---|
| | } |
---|
| | finally { |
---|
| | srcChannel.close(); |
---|
| | destChannel.close(); |
---|
| | sStream.close(); |
---|
| | dStream.close(); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | return ret; |
---|
| | } |
---|
| | |
---|
| | static Document document; |
---|
| | |
---|
| | |
---|
| | /** |
---|
| | * 2012-06-10T05:09:46Z (日本時間の'2012-06-10T14:09:46') |
---|
| | */ |
---|
| |
---|
| | |