try {
final String unitSize = metadata.getGeoKey(userDefinedKey);
// throw descriptive exception if required key is not there.
if (unitSize == null) {
throw new GeoTiffException(
metadata,
new StringBuffer(
"GeoTiffMetadata2CRSAdapter::createUnit:Must define unit length when using a user ")
.append("defined unit").toString(), null);
}
double sz = Double.parseDouble(unitSize);
return base.times(sz);
} catch (NumberFormatException nfe) {
final IOException ioe = new GeoTiffException(metadata, nfe
.getLocalizedMessage(), nfe);
throw ioe;
}
} else {
try {
// using epsg code for this unit
return (Unit) this.allAuthoritiesFactory
.createUnit(new StringBuffer("EPSG:").append(unitCode)
.toString());
} catch (FactoryException fe) {
final IOException io = new GeoTiffException(metadata, fe
.getLocalizedMessage(), fe);
throw io;
}
}
}