Class LinearInterpolator1D
java.lang.Object
org.apache.sis.io.wkt.FormattableObject
org.apache.sis.referencing.operation.transform.AbstractMathTransform
org.apache.sis.referencing.operation.transform.AbstractMathTransform1D
org.apache.sis.referencing.operation.transform.LinearInterpolator1D
- All Implemented Interfaces:
Serializable,Parameterized,LenientComparable,org.opengis.referencing.operation.MathTransform,org.opengis.referencing.operation.MathTransform1D
A transform that performs linear interpolation between values.
The transform is invertible if, and only if, the values are in increasing order.
If desired values in decreasing order can be supported by inverting the sign of all values, then concatenating this transform with a transform that multiply all output values by -1.
Extrapolation
If an input value is outside the expected range of values, this class extrapolates using the slope defined by the two first points if the requested value is before, or the slope defined by the two last points if the requested value is after. In other words, extrapolations are computed using only values at the extremum where extrapolation happen. This rule causes less surprising behavior when computing a data cube envelope, which may need extrapolation by 0.5 pixel before the first value or after the last value.Example:
if a vertical dimension is made of slices at y₀=5, y₁=10, y₂=100 and y₃=250 meters, then linear
interpolation at 0.5 is 7.5 meters and extrapolation at -0.5 is expected to give 2.5 meters.
- Since:
- 0.7
- Version:
- 1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classThe inverse of the enclosingLinearInterpolator1D. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.opengis.referencing.operation.MathTransform1DIf the transform is invertible, the inverse.private static final longFor cross-version compatibility.private final double[]The sequence values specified at construction time.Fields inherited from class org.apache.sis.referencing.operation.transform.AbstractMathTransform
MAXIMUM_BUFFER_SIZE, MAXIMUM_FAILURES -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateLinearInterpolator1D(double[] values) Creates a new transform which will interpolate in the given table of values. -
Method Summary
Modifier and TypeMethodDescriptionprotected intComputes a hash code value for this transform.private static org.opengis.referencing.operation.MathTransform1Dcreate(double[] values) Creates a transform for the given values.(package private) static org.opengis.referencing.operation.MathTransform1Dcreate(double[] preimage, double[] values) Creates a y=f(x) transform for the given preimage (x) and values (y).doublederivative(double x) Returns the derivative of y for the given x.booleanequals(Object object, ComparisonMode mode) Compares this transform with the given object for equality.org.opengis.parameter.ParameterDescriptorGroupReturns the parameter descriptors for this math transform.org.opengis.parameter.ParameterValueGroupReturns the parameter values for this math transform.org.opengis.referencing.operation.MathTransform1Dinverse()Returns the inverse of this transform, or throw an exception if there is no inverse.booleanReturnstrueif this transform is the identity transform.doubletransform(double x) Interpolates a y values for the given x.org.opengis.referencing.operation.Matrixtransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, boolean derivate) Combinestransform(double),derivative(double)in a single method call.Methods inherited from class org.apache.sis.referencing.operation.transform.AbstractMathTransform1D
derivative, getSourceDimensions, getTargetDimensionsMethods inherited from class org.apache.sis.referencing.operation.transform.AbstractMathTransform
beforeFormat, equals, formatTo, getContextualParameters, getDomain, hashCode, isInverseEquals, mismatchedDimension, transform, transform, transform, transform, transform, tryConcatenateMethods inherited from class org.apache.sis.io.wkt.FormattableObject
print, toString, toString, toWKTMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.opengis.referencing.operation.MathTransform
toWKT, transform, transform, transform, transform, transform
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
values
private final double[] valuesThe sequence values specified at construction time. Must contain at least 2 values. -
inverse
private final org.opengis.referencing.operation.MathTransform1D inverseIf the transform is invertible, the inverse. Otherwisenull. The transform is invertible only if values are in increasing order.
-
-
Constructor Details
-
LinearInterpolator1D
private LinearInterpolator1D(double[] values) Creates a new transform which will interpolate in the given table of values. The inputs are {0, 1, … , N} where N is length of output values.This constructor assumes that the
valuesarray has already been cloned, so it will not clone it again. That array shall contain at least two values.- Parameters:
values- the y values in y=f(x) where x = {0, 1, … ,values.length-1}.
-
-
Method Details
-
create
private static org.opengis.referencing.operation.MathTransform1D create(double[] values) Creates a transform for the given values. This method returns an affine transform instead of an interpolator if the given values form a series with a constant increment. The given array shall contain at least two values.- Parameters:
values- a copy of the user-provided values. This array may be modified.
-
create
static org.opengis.referencing.operation.MathTransform1D create(double[] preimage, double[] values) Creates a y=f(x) transform for the given preimage (x) and values (y). SeeMathTransforms.interpolate(double[], double[])javadoc for more information. -
getParameterDescriptors
public org.opengis.parameter.ParameterDescriptorGroup getParameterDescriptors()Returns the parameter descriptors for this math transform.- Specified by:
getParameterDescriptorsin interfaceParameterized- Overrides:
getParameterDescriptorsin classAbstractMathTransform- Returns:
- the parameter descriptors for this math transform, or
nullif unspecified. - See Also:
-
getParameterValues
public org.opengis.parameter.ParameterValueGroup getParameterValues()Returns the parameter values for this math transform.- Specified by:
getParameterValuesin interfaceParameterized- Overrides:
getParameterValuesin classAbstractMathTransform- Returns:
- the parameter values for this math transform, or
nullif unspecified. Note that those parameters may be normalized (e.g. represent a transformation of an ellipsoid of semi-major axis length of 1). - See Also:
-
isIdentity
public boolean isIdentity()Returnstrueif this transform is the identity transform. This method should never returnstruesince we verified the inputs in thecreate(…)method. We nevertheless verify as a paranoiac safety.- Specified by:
isIdentityin interfaceorg.opengis.referencing.operation.MathTransform- Overrides:
isIdentityin classAbstractMathTransform
-
transform
public org.opengis.referencing.operation.Matrix transform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, boolean derivate) throws org.opengis.referencing.operation.TransformException Combinestransform(double),derivative(double)in a single method call.- Overrides:
transformin classAbstractMathTransform1D- Parameters:
srcPts- the array containing the source coordinates (cannot benull).srcOff- the offset to the point to be transformed in the source array.dstPts- the array into which the transformed coordinates is returned. May be the same thansrcPts. May benullif only the derivative matrix is desired.dstOff- the offset to the location of the transformed point that is stored in the destination array.derivate-truefor computing the derivative, orfalseif not needed.- Returns:
- the matrix of the transform derivative at the given source position,
or
nullif thederivateargument isfalse. - Throws:
org.opengis.referencing.operation.TransformException- if the point cannot be transformed or if a problem occurred while calculating the derivative.- See Also:
-
transform
public double transform(double x) Interpolates a y values for the given x. The given x value should be between 0 tovalues.length - 1inclusive. If the given input value is outside that range, then the output value will be extrapolated.- Specified by:
transformin interfaceorg.opengis.referencing.operation.MathTransform1D- Specified by:
transformin classAbstractMathTransform1D- Parameters:
x- the value to transform.- Returns:
- the transformed value.
-
derivative
public double derivative(double x) Returns the derivative of y for the given x. Note: for each segment, the derivative is considered constant between x inclusive and x+1 exclusive.- Specified by:
derivativein interfaceorg.opengis.referencing.operation.MathTransform1D- Specified by:
derivativein classAbstractMathTransform1D- Parameters:
x- the value where to evaluate the derivative.- Returns:
- the derivative at the specified point.
-
inverse
public org.opengis.referencing.operation.MathTransform1D inverse() throws org.opengis.referencing.operation.NoninvertibleTransformExceptionReturns the inverse of this transform, or throw an exception if there is no inverse.- Specified by:
inversein interfaceorg.opengis.referencing.operation.MathTransform- Specified by:
inversein interfaceorg.opengis.referencing.operation.MathTransform1D- Overrides:
inversein classAbstractMathTransform1D- Throws:
org.opengis.referencing.operation.NoninvertibleTransformException
-
computeHashCode
protected int computeHashCode()Computes a hash code value for this transform.- Overrides:
computeHashCodein classAbstractMathTransform- Returns:
- the hash code value. This value may change between different execution of the Apache SIS library.
-
equals
Compares this transform with the given object for equality.- Specified by:
equalsin interfaceLenientComparable- Overrides:
equalsin classAbstractMathTransform- Parameters:
object- the object to compare with this transform.mode- the strictness level of the comparison. Default toSTRICT.- Returns:
trueif the given object is considered equals to this math transform.- See Also:
-