return null;
}
Wpt result = new Wpt();
Number[] r3;
TiffField e;
/* map datum */
e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_MAP_DATUM);
if(e == null){
warn("GPS datum missing. Assuming WGS84.");
} else {
String svalue = (String) e.getValue();
if(svalue.equals("")){
System.err.println("Warning: GPS datum missing. Assuming WGS84.");
} else if(!svalue.toUpperCase().replaceAll("[^0-9A-Z]", "").equals("WGS84")){
throw new MetadataException("GPS datum is " + svalue +
". Currently only coordinates in the WGS84 "+
"map datum can be handled.");
}
}
/* latitude */
e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_LATITUDE);
if(e == null){
throw new MetadataException("GPS latitude missing.");
}
r3 = (Number[]) e.getValue();
e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
if(e == null){
String sysprop = System.getProperty("DefaultGPSLatitudeRef");
char s0 = (sysprop == null || sysprop.length() == 0)
? 'X'
: sysprop.toUpperCase().charAt(0);
if(s0 != 'N' && s0 != 'S'){
throw new MetadataException("GPS latitude found but GPS latitude reference missing or invalid.\n"+
" To use the GPS latitude information set the DefaultGPSLatitudeRef system property to N or S, e. g.\n"+
" java -DDefaultGPSLatitudeRef=N -jar gpsdings.jar ...");
}
result.setLat(asBigDecimalDegrees(r3, String.valueOf(s0)));
} else {
result.setLat(asBigDecimalDegrees(r3, (String) e.getValue()));
}
/* longitude */
e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_LONGITUDE);
if(e == null){
throw new MetadataException("GPS longitude missing.");
}
r3 = (Number[]) e.getValue();
e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
if(e == null){
String sysprop = System.getProperty("DefaultGPSLongitudeRef");
final char s0 = (sysprop == null || sysprop.length() == 0)
? 'X'
: sysprop.toUpperCase().charAt(0);
if(s0 != 'E' && s0 != 'W'){
throw new MetadataException("GPS longitude found but GPS longitude reference missing or invalid.\n"+
" To use the GPS longitude information set the DefaultGPSLongitudeRef system property to W or E, e. g.\n"+
" java -DDefaultGPSLongitudeRef=E -jar gpsdings.jar ...");
}
result.setLon(asBigDecimalDegrees(r3, String.valueOf(s0)));
} else {
result.setLon(asBigDecimalDegrees(r3, (String) e.getValue()));
}
/* elevation */
e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_ALTITUDE);
if(e != null){
double alti = ((Number) e.getValue()).doubleValue();
e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_ALTITUDE_REF);
if (e == null){
warn("GPSAltitudeRef missing. Assuming above sea level.");
} else {
int altref = ((Number) e.getValue()).intValue() * (-2) + 1; // 0 -> 1 && 1 -> -1
if (Math.abs(altref) != 1 ){
System.err.printf("WARNING: illegal GPSAltitudeRef %d. Assuming above sea level.\n",
altref);
altref = 1;
}
alti *= altref;
}
result.setEle(new BigDecimal(alti));
}
/* dateTime */
e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_TIME_STAMP);
if(e != null){
r3 = (Number[]) e.getValue();
long millis = Math.round(asDouble(r3, 3.6e6));
e = gpsIfd.findField(TiffConstants.GPS_TAG_GPS_DATE_STAMP);
if (e != null){
Date d = null;
try{
d = AbstractExecExifWriter.parseExifDate((String) e.getValue());
d = new Date(d.getTime() + millis);
result.setTime(d);
} catch (ParseException ex){
System.err.println(ex);
}