* @return
* @throws IOException
*/
private GeographicCRS createGeographicCoordinateSystem(
final GeoTiffIIOMetadataDecoder metadata) throws IOException {
GeographicCRS gcs = null;
// ////////////////////////////////////////////////////////////////////
//
// Get the crs code
//
// ////////////////////////////////////////////////////////////////////
final String tempCode = metadata
.getGeoKey(GeoTiffGCSCodes.GeographicTypeGeoKey);
// lookup the angular units used in this geotiff image
Unit angularUnit = null;
try {
angularUnit = createUnit(GeoTiffGCSCodes.GeogAngularUnitsGeoKey,
GeoTiffGCSCodes.GeogAngularUnitSizeGeoKey, SI.RADIAN,
NonSI.DEGREE_ANGLE, metadata);
} catch (GeoTiffException e) {
angularUnit = null;
}
// linear unit
Unit linearUnit = null;
try {
linearUnit = createUnit(GeoTiffGCSCodes.GeogLinearUnitsGeoKey,
GeoTiffGCSCodes.GeogLinearUnitSizeGeoKey, SI.METER,
SI.METER, metadata);
} catch (GeoTiffException e) {
linearUnit = null;
}
// if it's user defined, there's a lot of work to do
if (tempCode == null
|| tempCode.equals(GeoTiffConstants.GTUserDefinedGeoKey_String)) {
// ////////////////////////////////////////////////////////////////////
//
// it is user-defined we have to parse a lot of information in order
// to built it.
//
// ////////////////////////////////////////////////////////////////////
gcs = createUserDefinedGCS(metadata, linearUnit, angularUnit);
} else {
try {
// ////////////////////////////////////////////////////////////////////
//
// If it's not user defined, just use the EPSG factory to create
// the coordinate system but check if the user specified a
// different angular unit. In this case we need to create a
// user-defined GCRS.
//
// ////////////////////////////////////////////////////////////////////
final StringBuffer geogCode = new StringBuffer(tempCode);
if (!tempCode.startsWith("EPSG")
&& !tempCode.startsWith("epsg")) {
geogCode.insert(0, "EPSG:");
}
gcs = (GeographicCRS) CRS.decode(geogCode.toString(), true);
if (angularUnit != null
&& !angularUnit.equals(gcs.getCoordinateSystem()
.getAxis(0).getUnit())) {
// //
//
// Create a user-defined GCRS using the provided angular
// unit.
//
// //
gcs = new DefaultGeographicCRS(DefaultEllipsoidalCS
.getName(gcs, new CitationImpl("EPSG")),
(GeodeticDatum) gcs.getDatum(),
DefaultEllipsoidalCS.GEODETIC_2D
.usingUnit(angularUnit));
}
} catch (FactoryException fe) {
final IOException ex = new GeoTiffException(metadata, fe