GeodeticDatum datum = null;
final String datumCode = metadata
.getGeoKey(GeoTiffGCSCodes.GeogGeodeticDatumGeoKey);
if (datumCode == null) {
throw new GeoTiffException(
metadata,
"GeoTiffMetadata2CRSAdapter::createGeodeticDatum(Unit unit):A user defined Geographic Coordinate system must include a predefined datum!",
null);
}
if (datumCode.equals(GeoTiffConstants.GTUserDefinedGeoKey_String)) {
/**
*
*
* USER DEFINED DATUM
*
*
*
*/
// datum name
final String datumName = (metadata
.getGeoKey(GeoTiffGCSCodes.GeogCitationGeoKey) != null ? metadata
.getGeoKey(GeoTiffGCSCodes.GeogCitationGeoKey)
: "unnamed");
// is it WGS84?
if (datumName.trim().equalsIgnoreCase("WGS84"))
return DefaultGeodeticDatum.WGS84;
// ELLIPSOID
final Ellipsoid ellipsoid = createEllipsoid(unit, metadata);
// PRIME MERIDIAN
// lookup the Prime Meridian.
final PrimeMeridian primeMeridian = createPrimeMeridian(metadata,
unit);
// DATUM
datum = new DefaultGeodeticDatum(datumName, ellipsoid,
primeMeridian);
} else {
/**
* NOT USER DEFINED DATUM
*/
// we are going to use the provided EPSG code
try {
datum = (GeodeticDatum) (this.allAuthoritiesFactory
.createDatum(new StringBuffer("EPSG:")
.append(datumCode).toString()));
} catch (FactoryException fe) {
final GeoTiffException ex = new GeoTiffException(metadata, fe
.getLocalizedMessage(), fe);
throw ex;
} catch (ClassCastException cce) {
final GeoTiffException ex = new GeoTiffException(metadata, cce
.getLocalizedMessage(), cce);
throw ex;
}
}