if (crs instanceof ProjectedCRS) {
modified = crsFactory.createProjectedCRS(properties,
(GeographicCRS) baseCRS, fromBase, (CartesianCS) cs);
} else {
// TODO: Need a createDerivedCRS method.
throw new FactoryException(Errors.format(
ErrorKeys.UNSUPPORTED_CRS_$1, crs.getName().getCode()));
}
} else if (sameCS) {
return crs;
} else {
final Map properties = getProperties(crs);
final ReferencingFactoryContainer factories = getFactoryContainer(true);
final CRSFactory crsFactory = factories.getCRSFactory();
if (crs instanceof GeographicCRS) {
modified = crsFactory.createGeographicCRS(properties,
(GeodeticDatum) datum, (EllipsoidalCS) cs);
} else if (crs instanceof GeocentricCRS) {
final GeodeticDatum gd = (GeodeticDatum) datum;
if (cs instanceof CartesianCS) {
modified = crsFactory.createGeocentricCRS(properties, gd, (CartesianCS) cs);
} else {
modified = crsFactory.createGeocentricCRS(properties, gd, (SphericalCS) cs);
}
} else if (crs instanceof VerticalCRS) {
modified = crsFactory.createVerticalCRS(properties,
(VerticalDatum) datum, (VerticalCS) cs);
} else if (crs instanceof TemporalCRS) {
modified = crsFactory.createTemporalCRS(properties,
(TemporalDatum) datum, (TimeCS) cs);
} else if (crs instanceof ImageCRS) {
modified = crsFactory.createImageCRS(properties,
(ImageDatum) datum, (AffineCS) cs);
} else if (crs instanceof EngineeringCRS) {
modified = crsFactory.createEngineeringCRS(properties,
(EngineeringDatum) datum, cs);
} else if (crs instanceof CompoundCRS) {
final List/* <CoordinateReferenceSystem> */elements =
((CompoundCRS) crs).getCoordinateReferenceSystems();
final CoordinateReferenceSystem[] m = new CoordinateReferenceSystem[elements.size()];
for (int i=0; i<m.length; i++) {
m[i] = replace((CoordinateReferenceSystem) elements.get(i));
}
modified = crsFactory.createCompoundCRS(properties, m);
} else {
throw new FactoryException(Errors.format(
ErrorKeys.UNSUPPORTED_CRS_$1, crs.getName().getCode()));
}
}
modified = (CoordinateReferenceSystem) pool.unique(modified);
return modified;