use of org.opengis.referencing.cs.AxisDirection in project sis by apache.
the class DefaultCartesianCS method ensurePerpendicularAxis.
/**
* Ensures that all axes are perpendicular.
*/
private void ensurePerpendicularAxis(final Map<String, ?> properties) throws IllegalArgumentException {
final int dimension = getDimension();
for (int i = 0; i < dimension; i++) {
final AxisDirection axis0 = getAxis(i).getDirection();
for (int j = i; ++j < dimension; ) {
final AxisDirection axis1 = getAxis(j).getDirection();
final Angle angle = CoordinateSystems.angle(axis0, axis1);
/*
* The angle may be null for grid directions (COLUMN_POSITIVE, COLUMN_NEGATIVE,
* ROW_POSITIVE, ROW_NEGATIVE). We conservatively accept those directions even if
* they are not really for Cartesian CS because we do not know the grid geometry.
*/
if (angle != null && Math.abs(angle.degrees()) != 90) {
throw new IllegalArgumentException(Resources.forProperties(properties).getString(Resources.Keys.NonPerpendicularDirections_2, axis0, axis1));
}
}
}
}
use of org.opengis.referencing.cs.AxisDirection in project sis by apache.
the class DefaultEllipsoidalCS method validateAxes.
/**
* Validates the set of axes after the validation of each individual axis.
*
* @param properties the properties given at construction time.
*/
private void validateAxes(final Map<String, ?> properties) {
int i = super.getDimension();
// Number of vertical axes allowed.
int n = i - 2;
while (--i >= 0) {
final AxisDirection direction = super.getAxis(i).getDirection();
if (AxisDirections.isVertical(direction) && --n < 0) {
throw new IllegalArgumentException(Resources.forProperties(properties).getString(Resources.Keys.IllegalAxisDirection_2, EllipsoidalCS.class, direction));
}
}
}
use of org.opengis.referencing.cs.AxisDirection in project sis by apache.
the class MatricesTest method testCreateTransformFromEnvelopesAndAxes.
/**
* Tests {@link Matrices#createTransform(Envelope, AxisDirection[], Envelope, AxisDirection[])}.
* This method tests the example given in {@code Matrices.createTransform(…)} javadoc.
*/
@Test
@DependsOnMethod({ "testCreateTransformFromEnvelopes", "testCreateTransformWithLessAxes" })
public void testCreateTransformFromEnvelopesAndAxes() {
// swapped (y,-x)
final Envelope srcEnvelope = new Envelope2D(null, -40, +20, 200, 100);
final Envelope dstEnvelope = new Envelope2D(null, -10, -25, 300, 500);
MatrixSIS matrix = Matrices.createTransform(srcEnvelope, new AxisDirection[] { NORTH, WEST }, dstEnvelope, new AxisDirection[] { EAST, NORTH });
assertTrue("isAffine", matrix.isAffine());
assertFalse("isIdentity", matrix.isIdentity());
assertEquals("numRow", 3, matrix.getNumRow());
assertEquals("numCol", 3, matrix.getNumCol());
assertMatrixEquals("(N,E) → (E,N)", Matrices.create(3, 3, new double[] { 0, -3.0, 350, 2.5, 0, 75, 0, 0, 1 }), matrix, STRICT);
/*
* Test dropping a dimension.
*/
final GeneralEnvelope expanded = new GeneralEnvelope(3);
expanded.subEnvelope(0, 2).setEnvelope(srcEnvelope);
expanded.setRange(2, 1000, 2000);
matrix = Matrices.createTransform(expanded, new AxisDirection[] { NORTH, WEST, UP }, dstEnvelope, new AxisDirection[] { EAST, NORTH });
assertEquals("numRow", 3, matrix.getNumRow());
assertEquals("numCol", 4, matrix.getNumCol());
assertMatrixEquals("(N,E,U) → (E,N)", Matrices.create(3, 4, new double[] { 0, -3.0, 0, 350, 2.5, 0, 0, 75, 0, 0, 0, 1 }), matrix, STRICT);
}
use of org.opengis.referencing.cs.AxisDirection in project sis by apache.
the class Angle method valueOf.
/**
* Returns the angular value of the axis having the given direction.
* This helper method is used for subclass constructors expecting a {@link DirectPosition} argument.
*
* @param position the position from which to get an angular value.
* @param positive axis direction of positive values.
* @param negative axis direction of negative values.
* @return angular value in degrees.
* @throws IllegalArgumentException if the given coordinate it not associated to a CRS,
* or if no axis oriented toward the given directions is found, or if that axis
* does not use {@linkplain Units#isAngular angular units}.
*/
static double valueOf(final DirectPosition position, final AxisDirection positive, final AxisDirection negative) {
final CoordinateReferenceSystem crs = position.getCoordinateReferenceSystem();
if (crs == null) {
throw new IllegalArgumentException(Errors.format(Errors.Keys.UnspecifiedCRS));
}
final CoordinateSystem cs = crs.getCoordinateSystem();
final int dimension = cs.getDimension();
IncommensurableException cause = null;
for (int i = 0; i < dimension; i++) {
final CoordinateSystemAxis axis = cs.getAxis(i);
final AxisDirection dir = axis.getDirection();
final boolean isPositive = dir.equals(positive);
if (isPositive || dir.equals(negative)) {
double value = position.getOrdinate(i);
if (!isPositive)
value = -value;
final Unit<?> unit = axis.getUnit();
if (unit != Units.DEGREE)
try {
value = unit.getConverterToAny(Units.DEGREE).convert(value);
} catch (IncommensurableException e) {
cause = e;
break;
}
return value;
}
}
throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalCRSType_1, Classes.getLeafInterfaces(crs.getClass(), CoordinateReferenceSystem.class)[0]), cause);
}
use of org.opengis.referencing.cs.AxisDirection in project sis by apache.
the class VerticalDatumTypes method guess.
/**
* Guesses the type of a datum from its name, aliases or a given vertical axis. This is sometime needed
* after XML unmarshalling or WKT parsing, since GML 3.2 and ISO 19162 do not contain any attribute for
* the datum type.
*
* <p>This method uses heuristic rules and may be changed in any future SIS version.
* If the type can not be determined, defaults to {@link VerticalDatumType#OTHER_SURFACE}.</p>
*
* @param name the name of the datum for which to guess a type, or {@code null} if unknown.
* @param aliases the aliases of the datum for which to guess a type, or {@code null} if unknown.
* @param axis the vertical axis for which to guess a type, or {@code null} if unknown.
* @return a datum type, or {@link VerticalDatumType#OTHER_SURFACE} if none can be guessed.
*/
public static VerticalDatumType guess(final String name, final Collection<? extends GenericName> aliases, final CoordinateSystemAxis axis) {
VerticalDatumType type = guess(name);
if (type != null) {
return type;
}
if (aliases != null) {
for (final GenericName alias : aliases) {
type = guess(alias.tip().toString());
if (type != null) {
return type;
}
}
}
if (axis != null) {
final Unit<?> unit = axis.getUnit();
if (Units.isLinear(unit)) {
final String abbreviation = axis.getAbbreviation();
if (abbreviation.length() == 1) {
// Expected direction for accepting the type.
AxisDirection dir = AxisDirection.UP;
switch(abbreviation.charAt(0)) {
case 'h':
type = ELLIPSOIDAL;
break;
case 'H':
type = VerticalDatumType.GEOIDAL;
break;
case 'D':
type = VerticalDatumType.DEPTH;
dir = AxisDirection.DOWN;
break;
default:
return VerticalDatumType.OTHER_SURFACE;
}
if (dir.equals(axis.getDirection())) {
return type;
}
}
} else if (Units.isPressure(unit)) {
return VerticalDatumType.BAROMETRIC;
}
}
return VerticalDatumType.OTHER_SURFACE;
}
Aggregations