if (type.equalsIgnoreCase("geographic 2D") ||
type.equalsIgnoreCase("geographic 3D"))
{
final String csCode = getString(result, 7, code);
final String dmCode = result.getString( 8);
final EllipsoidalCS cs = createEllipsoidalCS(csCode);
final GeodeticDatum datum;
if (dmCode != null) {
datum = createGeodeticDatum(dmCode);
} else {
final String geoCode = getString(result, 9, code, 8);
result.close(); // Must be close before createGeographicCRS
result = null;
final GeographicCRS baseCRS = createGeographicCRS(geoCode);
datum = baseCRS.getDatum();
}
final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
crs = factory.createGeographicCRS(properties, datum, cs);
}
/* ----------------------------------------------------------------------
* PROJECTED CRS
*
* NOTE: This method invokes itself indirectly, through createGeographicCRS.
* Consequently, we can't use 'result' anymore. We must close it here.
* ---------------------------------------------------------------------- */
else if (type.equalsIgnoreCase("projected")) {
final String csCode = getString(result, 7, code);
final String geoCode = getString(result, 9, code);
final String opCode = getString(result, 10, code);
result.close(); // Must be close before createGeographicCRS
result = null;
final CartesianCS cs = createCartesianCS(csCode);
final GeographicCRS baseCRS = createGeographicCRS(geoCode);
final CoordinateOperation op = createCoordinateOperation(opCode);
if (op instanceof Conversion) {
final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
crs = factory.createProjectedCRS(properties, baseCRS, (Conversion)op, cs);
} else {
throw noSuchAuthorityCode(Projection.class, opCode);
}
}
/* ----------------------------------------------------------------------
* VERTICAL CRS
* ---------------------------------------------------------------------- */
else if (type.equalsIgnoreCase("vertical")) {
final String csCode = getString(result, 7, code);
final String dmCode = getString(result, 8, code);
final VerticalCS cs = createVerticalCS (csCode);
final VerticalDatum datum = createVerticalDatum(dmCode);
final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
crs = factory.createVerticalCRS(properties, datum, cs);
}
/* ----------------------------------------------------------------------
* COMPOUND CRS
*
* NOTE: This method invokes itself recursively.
* Consequently, we can't use 'result' anymore.
* ---------------------------------------------------------------------- */
else if (type.equalsIgnoreCase("compound")) {
final String code1 = getString(result, 11, code);
final String code2 = getString(result, 12, code);
result.close();
result = null;
final CoordinateReferenceSystem crs1, crs2;
if (!safetyGuard.add(epsg)) {
throw recursiveCall(CompoundCRS.class, epsg);
} try {
crs1 = createCoordinateReferenceSystem(code1);
crs2 = createCoordinateReferenceSystem(code2);
} finally {
safetyGuard.remove(epsg);
}
// Note: Don't invoke 'generateProperties' sooner.
final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
crs = factory.createCompoundCRS(properties,
new CoordinateReferenceSystem[] {crs1, crs2});
}
/* ----------------------------------------------------------------------
* GEOCENTRIC CRS
* ---------------------------------------------------------------------- */
else if (type.equalsIgnoreCase("geocentric")) {
final String csCode = getString(result, 7, code);
final String dmCode = getString(result, 8, code);
final CoordinateSystem cs = createCoordinateSystem(csCode);
final GeodeticDatum datum = createGeodeticDatum (dmCode);
final Map<String,Object> properties = generateProperties(name, epsg, area, scope, remarks);
if (cs instanceof CartesianCS) {
crs = factory.createGeocentricCRS(properties, datum, (CartesianCS) cs);
} else if (cs instanceof SphericalCS) {
crs = factory.createGeocentricCRS(properties, datum, (SphericalCS) cs);
} else {
result.close();
throw new FactoryException(Errors.format(
ErrorKeys.ILLEGAL_COORDINATE_SYSTEM_FOR_CRS_$2,
cs.getClass(), GeocentricCRS.class));
}
}
/* ----------------------------------------------------------------------
* ENGINEERING CRS
* ---------------------------------------------------------------------- */