/** * Creates the inverse CoordinateOperation. This method can be used to chain * {@link org.cts.op.CoordinateOperation}s and/or inverse CoordinateOperation in * a unique CoordinateOperationSequence. This method is not declared * abstract, so that implementation classes have not to implement it if they * represent non invertible operation. */ public CoordinateOperation inverse() throws NonInvertibleOperationException { throw new NonInvertibleOperationException(this.toString() + " is non invertible"); }
/** * Creates the inverse CoordinateOperation. */ @Override public CoordinateOperation inverse() throws NonInvertibleOperationException { return new LongitudeRotation(-rotationAngle); }
/** * Return a pessimistic estimation of the precision where precision * of every sub-operation is simply added to the previous. * @return */ public double getPrecision() { double combinedPrecision = 0.0; for (CoordinateOperation op : sequence) { combinedPrecision += op.getPrecision(); } return combinedPrecision; }
@Override public double[] transform(double[] coord) throws IllegalCoordinateException, CoordinateOperationException { boolean iter = false; int count = 0; for (int i = 0; i < realValueIndex.length; i++) { iter = iter || Math.abs(coord[realValueIndex[i]] - coord[calculatedValueIndex[i]]) > tolerance[i]; } while (iter) { coord = op.transform(coord); iter = false; for (int i = 0; i < realValueIndex.length; i++) { iter = iter || Math.abs(coord[realValueIndex[i]] - coord[calculatedValueIndex[i]]) > tolerance[i]; } if (++count > maxIterations ) throw new TooManyIterationsException(this, count); } return coord; }
/** * Creates the inverse CoordinateOperation. * @return * @throws org.cts.op.NonInvertibleOperationException */ @Override public CoordinateOperation inverse() throws NonInvertibleOperationException { CoordinateOperation[] inverse_sequence = new CoordinateOperation[sequence.length]; for (int i = 0; i < sequence.length; i++) { // If one of the CoordinateOperation is not invertible, it // will throw a NonInvertibleOperationException. inverse_sequence[sequence.length - i - 1] = sequence[i].inverse(); //if (inverse_sequence[sequence.length-i-1] == null) return null; } return new CoordinateOperationSequence(getIdentifier(), inverse_sequence, precision); }
/** * Create a CoordinateOperationSequence from an identifier and an array of * {@linkplain org.cts.op.CoordinateOperation CoordinateOperations}. Precision * of this sequence is considered as the sum of all single * {@link org.cts.op.CoordinateOperation}. * * @param identifier this operation sequence identifier * @param sequence an array containing ordered operations to apply to * coordinates */ public CoordinateOperationSequence(Identifier identifier, CoordinateOperation... sequence) { super(identifier); this.sequence = sequence; this.sequence = cleanSequence(sequence); for (CoordinateOperation op : sequence) { precision += op.getPrecision(); } }
/** * Creates a coordinate rounding operation from the smallest representable * value. * * @param resolution smallest representable value */ public static CoordinateRounding createCoordinateRoundingOperation(double resolution) { return new CoordinateRounding(resolution); } }
/** * This method can identify sequences with no operations as equivalent to * Identity, but it does not try to nullify sequences of two opposite * operations. * @return true if this operation does not change coordinates. */ public boolean isIdentity() { for (CoordinateOperation op : sequence) { if (!op.isIdentity()) return false; } return true; } }
/** * Creates the inverse CoordinateOperation. */ @Override public CoordinateOperation inverse() throws NonInvertibleOperationException { return new UnitConversion(targetUnits, sourceUnits); }
/** * Create a new InterpolationMethodException. * * @param op the interpolation method * @param count max number of iterations */ public TooManyIterationsException(IterativeTransformation op, int count) { super("Iterative process " + op.getName() + " exceeded the maximum number of iterations (" + count + ")"); } }
/** * Return a String representation of this Geographic/Geocentric converter. */ @Override public String toString() { return getName() + " ( " + rotationAngle * 180 / Math.PI + "\u00B0 )"; }
/** * Creates the inverse CoordinateOperation. */ @Override public CoordinateOperation inverse() throws NonInvertibleOperationException { return new Geographic2Geocentric(ellipsoid); }
/** * Create a new InterpolationMethodException. * * @param op the interpolation method */ public NonInvertibleOperationException(CoordinateOperation op) { super("" + op.getName() + " is not invertible"); } }
/** * Creates the inverse CoordinateOperation. */ @Override public CoordinateOperation inverse() throws NonInvertibleOperationException { return new Geocentric2Geographic(ellipsoid, epsilon); }
/** * Create a CoordinateOperationSequence from an identifier an array of * {@linkplain org.cts.op.CoordinateOperation CoordinateOperations} and a * precision. * * @param identifier this operation sequence identifier * @param sequence a list containing ordered operations to apply to * coordinates * @param precision precision of this CoordinateOperation as a whole. */ public CoordinateOperationSequence(Identifier identifier, CoordinateOperation[] sequence, double precision) { super(identifier); this.sequence = sequence; this.sequence = cleanSequence(sequence); this.precision = precision; }
@Override public double getPrecision() { // Precision of this iterative operation is difficult to guess // because we don't know it uses radians, degrees or meters // We just suppose it is less than the base transformation return op.getPrecision()/2.0; }
/** * Creates a coordinate rounding operation from a decimal place number. * * @param decimalPlaces number of decimal places */ public static CoordinateRounding createCoordinateRoundingOperationFromDecimalPlaces(int decimalPlaces) { double u = 1.0; for (int i = 0; i < decimalPlaces; i++) { u *= 10.0; } return new CoordinateRounding(1.0 / u); }
/** * Returns true if o is also an Identity CoordinateOperation. * * @param o The object to compare this ProjectedCRS against */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof CoordinateOperation) { return ((CoordinateOperation)o).isIdentity(); } return false; }
/** * Returns the most precise among the list of {@link org.cts.op.CoordinateOperation}s. * @param ops * @return */ public static CoordinateOperation getMostPrecise3DTransformation(Collection<? extends CoordinateOperation> ops) { CoordinateOperation preciseOp = null; double currentPrecision = Double.MAX_VALUE; for (CoordinateOperation op : ops) { if (op.getPrecision() < currentPrecision && op instanceof GeocentricTransformation) { preciseOp = op; currentPrecision = op.getPrecision(); } } return preciseOp; }
/** * Returns the most precise among the list of {@link org.cts.op.CoordinateOperation}s. * @param ops * @return */ public static CoordinateOperation getMostPrecise(Collection<? extends CoordinateOperation> ops) { CoordinateOperation preciseOp = null; double currentPrecision = Double.MAX_VALUE; for (CoordinateOperation op : ops) { if (op.getPrecision() < currentPrecision) { preciseOp = op; currentPrecision = op.getPrecision(); } } return preciseOp; }