@Override
public boolean writeExifGpsInfo(File jpeg, Wpt wpt, boolean overwrite){
try{
TiffOutputSet outputSet = SanselanExifWriter.getExif(jpeg);
outputSet.setGPSInDegrees(wpt.getLon().doubleValue(), wpt.getLat().doubleValue());
TiffOutputDirectory gpsIfd = outputSet.getGPSDirectory();
TiffOutputField field;
final int byteOrder = outputSet.byteOrder;
/* version */
field = makeField(
TiffConstants.GPS_TAG_GPS_VERSION_ID,
new byte[]{
(byte) 2, (byte) 2, (byte) 0, (byte) 0});
gpsIfd.removeField(TiffConstants.GPS_TAG_GPS_VERSION_ID);
gpsIfd.add(field);
/* map datum */
//System.err.println("Writing map datum.");
field = makeField(
TiffConstants.GPS_TAG_GPS_MAP_DATUM,
byteOrder, "WGS-84");
gpsIfd.removeField(TiffConstants.GPS_TAG_GPS_MAP_DATUM);
gpsIfd.add(field);
/* elevation */
if(wpt.getEle() != null){
//System.err.println("Writing ele ref.");
double ele = wpt.getEle().doubleValue();
final Byte eleref = new Byte(
(byte) ((ele < 0)
? TiffConstants.GPS_TAG_GPS_ALTITUDE_REF_VALUE_BELOW_SEA_LEVEL
: TiffConstants.GPS_TAG_GPS_ALTITUDE_REF_VALUE_ABOVE_SEA_LEVEL)
);
// use custom tag info because GPS_TAG_GPS_ALTITUDE_REF has length -1
TagInfo tag = new TagInfo(
"GPS Altitude Ref",
0x0005,
TiffConstants.FIELD_TYPE_DESCRIPTION_BYTE,
1,
TiffConstants.EXIF_DIRECTORY_GPS);
field = TiffOutputField.create(
tag, byteOrder, eleref);
gpsIfd.removeField(TiffConstants.GPS_TAG_GPS_ALTITUDE_REF);
gpsIfd.add(field);
//System.err.println("Writing ele.");
// use custom tag info because GPS_TAG_GPS_ALTITUDE_REF has length -1
tag = new TagInfo(
"GPS Altitude",
0x0006,
TiffConstants.FIELD_TYPE_DESCRIPTION_RATIONAL,
1,
TiffConstants.EXIF_DIRECTORY_GPS);
field = TiffOutputField.create(
tag,
byteOrder, new Double(ele));
gpsIfd.removeField(TiffConstants.GPS_TAG_GPS_ALTITUDE);
gpsIfd.add(field);
}
/* dateTime */
//System.err.println("Writing date/time.");
if(wpt.getTime() != null){
Date dateTime = wpt.getTime();
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.setTime(dateTime);
field = TiffOutputField.create(
TiffConstants.GPS_TAG_GPS_TIME_STAMP,
byteOrder, new Double[]{
new Double(cal.get(Calendar.HOUR_OF_DAY)),
new Double(cal.get(Calendar.MINUTE)),
new Double(cal.get(Calendar.SECOND))
});
gpsIfd.removeField(TiffConstants.GPS_TAG_GPS_TIME_STAMP);
gpsIfd.add(field);
field = makeField(
TiffConstants.GPS_TAG_GPS_DATE_STAMP,
byteOrder,
AbstractExecExifWriter.formatAsExifDate(dateTime));
gpsIfd.removeField(TiffConstants.GPS_TAG_GPS_DATE_STAMP);
gpsIfd.add(field);
}
return writeExif(jpeg, outputSet);
} catch (Exception ex) {
System.err.println(ex);
ex.printStackTrace();