@Test public void testAxisSwapping() { CoordinateSystem cs1, cs2; cs1 = new DefaultEllipsoidalCS("cs1", DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE, DefaultCoordinateSystemAxis.GEODETIC_LATITUDE); cs2 = new DefaultEllipsoidalCS("cs2", DefaultCoordinateSystemAxis.GEODETIC_LATITUDE, DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE); assertTrue(AbstractCS.swapAndScaleAxis(cs1, cs1).isIdentity()); assertTrue(AbstractCS.swapAndScaleAxis(cs2, cs2).isIdentity()); compareMatrix(cs1, cs2, new double[] { 0, 1, 0, 1, 0, 0, 0, 0, 1 }); cs1 = new DefaultEllipsoidalCS("cs1", DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE, DefaultCoordinateSystemAxis.GEODETIC_LATITUDE, DefaultCoordinateSystemAxis.ELLIPSOIDAL_HEIGHT); cs2 = new DefaultEllipsoidalCS("cs2", DefaultCoordinateSystemAxis.GEODETIC_LATITUDE, DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE, DefaultCoordinateSystemAxis.ELLIPSOIDAL_HEIGHT); compareMatrix(cs1, cs2, new double[] { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }); cs1 = new DefaultCartesianCS("cs1", DefaultCoordinateSystemAxis.ELLIPSOIDAL_HEIGHT, DefaultCoordinateSystemAxis.EASTING, DefaultCoordinateSystemAxis.NORTHING); cs2 = new DefaultCartesianCS("cs2", DefaultCoordinateSystemAxis.SOUTHING, DefaultCoordinateSystemAxis.EASTING, DefaultCoordinateSystemAxis.ELLIPSOIDAL_HEIGHT); compareMatrix(cs1, cs2, new double[] { 0, 0,-1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 }); }
public static Matrix swapAndScaleAxis(final CoordinateSystem sourceCS, final CoordinateSystem targetCS) throws IllegalArgumentException, ConversionException { if (!Classes.sameInterfaces(sourceCS.getClass(), targetCS.getClass(), CoordinateSystem.class)) { throw new IllegalArgumentException(Errors.format( ErrorKeys.INCOMPATIBLE_COORDINATE_SYSTEM_TYPE)); } final AxisDirection[] sourceAxis = getAxisDirections(sourceCS); final AxisDirection[] targetAxis = getAxisDirections(targetCS); final GeneralMatrix matrix = new GeneralMatrix(sourceAxis, targetAxis); assert Arrays.equals(sourceAxis, targetAxis) == matrix.isIdentity() : matrix; final int sourceDim = matrix.getNumCol()-1; final int targetDim = matrix.getNumRow()-1; assert sourceDim == sourceCS.getDimension() : sourceCS; assert targetDim == targetCS.getDimension() : targetCS; for (int j=0; j<targetDim; j++) { final Unit<?> targetUnit = targetCS.getAxis(j).getUnit(); for (int i=0; i<sourceDim; i++) { final double element = matrix.getElement(j,i); if (element == 0) { continue; } final Unit<?> sourceUnit = sourceCS.getAxis(i).getUnit(); if (Utilities.equals(sourceUnit, targetUnit)) { continue; } final UnitConverter converter = sourceUnit.getConverterTo(targetUnit); if (!converter.isLinear()) { throw new ConversionException(Errors.format( ErrorKeys.NON_LINEAR_UNIT_CONVERSION_$2, sourceUnit, targetUnit)); } final double offset = converter.convert(0); final double scale = converter.convert(1) - offset; matrix.setElement(j,i, element*scale); matrix.setElement(j,sourceDim, matrix.getElement(j,sourceDim) + element*offset); } } return matrix; }
AbstractCS extends AbstractIdentifiedObject implements CoordinateSystem { public static Matrix swapAndScaleAxis(final CoordinateSystem sourceCS, final CoordinateSystem targetCS) throws IllegalArgumentException, ConversionException { if (!Classes.sameInterfaces(sourceCS.getClass(), targetCS.getClass(), CoordinateSystem.class)) { throw new IllegalArgumentException(Errors.format( ErrorKeys.INCOMPATIBLE_COORDINATE_SYSTEM_TYPE)); } final AxisDirection[] sourceAxis = getAxisDirections(sourceCS); final AxisDirection[] targetAxis = getAxisDirections(targetCS); final GeneralMatrix matrix = new GeneralMatrix(sourceAxis, targetAxis); assert Arrays.equals(sourceAxis, targetAxis) == matrix.isIdentity() : matrix; final int sourceDim = matrix.getNumCol()-1; final int targetDim = matrix.getNumRow()-1; assert sourceDim == sourceCS.getDimension() : sourceCS; assert targetDim == targetCS.getDimension() : targetCS; for (int j=0; j<targetDim; j++) { final Unit<?> targetUnit = targetCS.getAxis(j).getUnit(); for (int i=0; i<sourceDim; i++) { final double element = matrix.getElement(j,i); if (element == 0) { continue; } final Unit<?> sourceUnit = sourceCS.getAxis(i).getUnit(); if (Utilities.equals(sourceUnit, targetUnit)) { continue; } final UnitConverter converter = sourceUnit.getConverterTo(targetUnit); if (!converter.isLinear()) { throw new ConversionException(Errors.format( ErrorKeys.NON_LINEAR_UNIT_CONVERSION_$2, sourceUnit, targetUnit)); } final double offset = converter.convert(0); final double scale = converter.convert(1) - offset; matrix.setElement(j,i, element*scale); matrix.setElement(j,sourceDim, matrix.getElement(j,sourceDim) + element*offset); } } return matrix; } }
AbstractCS extends AbstractIdentifiedObject implements CoordinateSystem { public static Matrix swapAndScaleAxis(final CoordinateSystem sourceCS, final CoordinateSystem targetCS) throws IllegalArgumentException, ConversionException { if (!Classes.sameInterfaces(sourceCS.getClass(), targetCS.getClass(), CoordinateSystem.class)) { throw new IllegalArgumentException(Errors.format( ErrorKeys.INCOMPATIBLE_COORDINATE_SYSTEM_TYPE)); } final AxisDirection[] sourceAxis = getAxisDirections(sourceCS); final AxisDirection[] targetAxis = getAxisDirections(targetCS); final GeneralMatrix matrix = new GeneralMatrix(sourceAxis, targetAxis); assert Arrays.equals(sourceAxis, targetAxis) == matrix.isIdentity() : matrix; final int sourceDim = matrix.getNumCol()-1; final int targetDim = matrix.getNumRow()-1; assert sourceDim == sourceCS.getDimension() : sourceCS; assert targetDim == targetCS.getDimension() : targetCS; for (int j=0; j<targetDim; j++) { final Unit<?> targetUnit = targetCS.getAxis(j).getUnit(); for (int i=0; i<sourceDim; i++) { final double element = matrix.getElement(j,i); if (element == 0) { continue; } final Unit<?> sourceUnit = sourceCS.getAxis(i).getUnit(); if (Utilities.equals(sourceUnit, targetUnit)) { continue; } final UnitConverter converter = sourceUnit.getConverterTo(targetUnit); if (!converter.isLinear()) { throw new ConversionException(Errors.format( ErrorKeys.NON_LINEAR_UNIT_CONVERSION_$2, sourceUnit, targetUnit)); } final double offset = converter.convert(0); final double scale = converter.convert(1) - offset; matrix.setElement(j,i, element*scale); matrix.setElement(j,sourceDim, matrix.getElement(j,sourceDim) + element*offset); } } return matrix; } AbstractCS(final CoordinateSystem cs);  AbstractCS(final String name, final CoordinateSystemAxis[] axis);  AbstractCS(final Map<String,?> properties, final CoordinateSystemAxis[] axis); }
AbstractCS extends AbstractIdentifiedObject implements CoordinateSystem { public static Matrix swapAndScaleAxis(final CoordinateSystem sourceCS, final CoordinateSystem targetCS) throws IllegalArgumentException, ConversionException { if (!Classes.sameInterfaces(sourceCS.getClass(), targetCS.getClass(), CoordinateSystem.class)) { throw new IllegalArgumentException(Errors.format( ErrorKeys.INCOMPATIBLE_COORDINATE_SYSTEM_TYPE)); } final AxisDirection[] sourceAxis = getAxisDirections(sourceCS); final AxisDirection[] targetAxis = getAxisDirections(targetCS); final GeneralMatrix matrix = new GeneralMatrix(sourceAxis, targetAxis); assert Arrays.equals(sourceAxis, targetAxis) == matrix.isIdentity() : matrix; final int sourceDim = matrix.getNumCol()-1; final int targetDim = matrix.getNumRow()-1; assert sourceDim == sourceCS.getDimension() : sourceCS; assert targetDim == targetCS.getDimension() : targetCS; for (int j=0; j<targetDim; j++) { final Unit<?> targetUnit = targetCS.getAxis(j).getUnit(); for (int i=0; i<sourceDim; i++) { final double element = matrix.getElement(j,i); if (element == 0) { continue; } final Unit<?> sourceUnit = sourceCS.getAxis(i).getUnit(); if (Utilities.equals(sourceUnit, targetUnit)) { continue; } final UnitConverter converter = sourceUnit.getConverterTo(targetUnit); if (!converter.isLinear()) { throw new ConversionException(Errors.format( ErrorKeys.NON_LINEAR_UNIT_CONVERSION_$2, sourceUnit, targetUnit)); } final double offset = converter.convert(0); final double scale = converter.convert(1) - offset; matrix.setElement(j,i, element*scale); matrix.setElement(j,sourceDim, matrix.getElement(j,sourceDim) + element*offset); } } return matrix; } AbstractCS(final CoordinateSystem cs);  AbstractCS(final String name, final CoordinateSystemAxis[] axis);  AbstractCS(final Map<String,?> properties, final CoordinateSystemAxis[] axis); int getDimension(); CoordinateSystemAxis getAxis(final int dimension); static Matrix swapAndScaleAxis(final CoordinateSystem sourceCS,
                                          final CoordinateSystem targetCS); static CoordinateSystem standard(final CoordinateSystem cs); Measure distance(final double[] coord1, final double[] coord2); @Override boolean equals(final AbstractIdentifiedObject object, final boolean compareMetadata); @Override int hashCode(); }
AbstractCS extends AbstractIdentifiedObject implements CoordinateSystem { public static Matrix swapAndScaleAxis(final CoordinateSystem sourceCS, final CoordinateSystem targetCS) throws IllegalArgumentException, ConversionException { if (!Classes.sameInterfaces(sourceCS.getClass(), targetCS.getClass(), CoordinateSystem.class)) { throw new IllegalArgumentException(Errors.format( ErrorKeys.INCOMPATIBLE_COORDINATE_SYSTEM_TYPE)); } final AxisDirection[] sourceAxis = getAxisDirections(sourceCS); final AxisDirection[] targetAxis = getAxisDirections(targetCS); final GeneralMatrix matrix = new GeneralMatrix(sourceAxis, targetAxis); assert Arrays.equals(sourceAxis, targetAxis) == matrix.isIdentity() : matrix; final int sourceDim = matrix.getNumCol()-1; final int targetDim = matrix.getNumRow()-1; assert sourceDim == sourceCS.getDimension() : sourceCS; assert targetDim == targetCS.getDimension() : targetCS; for (int j=0; j<targetDim; j++) { final Unit<?> targetUnit = targetCS.getAxis(j).getUnit(); for (int i=0; i<sourceDim; i++) { final double element = matrix.getElement(j,i); if (element == 0) { continue; } final Unit<?> sourceUnit = sourceCS.getAxis(i).getUnit(); if (Utilities.equals(sourceUnit, targetUnit)) { continue; } final UnitConverter converter = sourceUnit.getConverterTo(targetUnit); if (!converter.isLinear()) { throw new ConversionException(Errors.format( ErrorKeys.NON_LINEAR_UNIT_CONVERSION_$2, sourceUnit, targetUnit)); } final double offset = converter.convert(0); final double scale = converter.convert(1) - offset; matrix.setElement(j,i, element*scale); matrix.setElement(j,sourceDim, matrix.getElement(j,sourceDim) + element*offset); } } return matrix; } AbstractCS(final CoordinateSystem cs);  AbstractCS(final String name, final CoordinateSystemAxis[] axis);  AbstractCS(final Map<String,?> properties, final CoordinateSystemAxis[] axis); int getDimension(); CoordinateSystemAxis getAxis(final int dimension); static Matrix swapAndScaleAxis(final CoordinateSystem sourceCS,
                                          final CoordinateSystem targetCS); static CoordinateSystem standard(final CoordinateSystem cs); Measure distance(final double[] coord1, final double[] coord2); @Override boolean equals(final AbstractIdentifiedObject object, final boolean compareMetadata); @Override int hashCode();  }