for (int i=0; i<axes.length; i++) {
final CoordinateSystemAxis axis = axes[i];
ensureNonNullElement("axes", i, axis);
final ReferenceIdentifier name = axis.getName();
ensureNonNullElement("axes[#].name", i, name);
final AxisDirection direction = axis.getDirection();
ensureNonNullElement("axes[#].direction", i, direction);
final Unit<?> unit = axis.getUnit();
ensureNonNullElement("axes[#].unit", i, unit);
/*
* Ensures that axis direction and units are compatible with the
* coordinate system to be created. For example CartesianCS will
* accept only linear or dimensionless units.
*/
switch (validateAxis(direction, unit)) {
case INVALID_DIRECTION: {
throw new IllegalArgumentException(Errors.getResources(properties).getString(
Errors.Keys.IllegalAxisDirection_2, getClass(), direction));
}
case INVALID_UNIT: {
throw new IllegalArgumentException(Errors.getResources(properties).getString(
Errors.Keys.IllegalUnitFor_2, name, unit));
}
}
/*
* Ensures there is no axis along the same direction (e.g. two North axes, or an East and a West axis).
* An exception to this rule is the time axis, since ISO 19107 explicitely allows compound CRS to have
* more than one time axis. Such case happen in meteorological models.
*/
final AxisDirection dir = AxisDirections.absolute(direction);
if (!dir.equals(AxisDirection.OTHER)) {
for (int j=i; --j>=0;) {
final AxisDirection other = axes[j].getDirection();
final AxisDirection abs = AxisDirections.absolute(other);
if (dir.equals(abs) && !abs.equals(AxisDirection.FUTURE)) {
throw new IllegalArgumentException(Errors.getResources(properties).getString(
Errors.Keys.ColinearAxisDirections_2, direction, other));
}
}
}