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 class
The inverse of the enclosingLinearInterpolator1D
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.opengis.referencing.operation.MathTransform1D
If the transform is invertible, the inverse.private static final long
For 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
ConstructorsModifierConstructorDescriptionprivate
LinearInterpolator1D
(double[] values) Creates a new transform which will interpolate in the given table of values. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Computes a hash code value for this transform.private static org.opengis.referencing.operation.MathTransform1D
create
(double[] values) Creates a transform for the given values.(package private) 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).double
derivative
(double x) Returns the derivative of y for the given x.boolean
equals
(Object object, ComparisonMode mode) Compares this transform with the given object for equality.org.opengis.parameter.ParameterDescriptorGroup
Returns the parameter descriptors for this math transform.org.opengis.parameter.ParameterValueGroup
Returns the parameter values for this math transform.org.opengis.referencing.operation.MathTransform1D
inverse()
Returns the inverse of this transform, or throw an exception if there is no inverse.boolean
Returnstrue
if this transform is the identity transform.double
transform
(double x) Interpolates a y values for the given x.org.opengis.referencing.operation.Matrix
transform
(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, getTargetDimensions
Methods inherited from class org.apache.sis.referencing.operation.transform.AbstractMathTransform
beforeFormat, equals, formatTo, getContextualParameters, getDomain, hashCode, isInverseEquals, mismatchedDimension, transform, transform, transform, transform, transform, tryConcatenate
Methods inherited from class org.apache.sis.io.wkt.FormattableObject
print, toString, toString, toWKT
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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
values
array 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:
getParameterDescriptors
in interfaceParameterized
- Overrides:
getParameterDescriptors
in classAbstractMathTransform
- Returns:
- the parameter descriptors for this math transform, or
null
if unspecified. - See Also:
-
getParameterValues
public org.opengis.parameter.ParameterValueGroup getParameterValues()Returns the parameter values for this math transform.- Specified by:
getParameterValues
in interfaceParameterized
- Overrides:
getParameterValues
in classAbstractMathTransform
- Returns:
- the parameter values for this math transform, or
null
if 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()Returnstrue
if this transform is the identity transform. This method should never returnstrue
since we verified the inputs in thecreate(…)
method. We nevertheless verify as a paranoiac safety.- Specified by:
isIdentity
in interfaceorg.opengis.referencing.operation.MathTransform
- Overrides:
isIdentity
in 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:
transform
in 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 benull
if only the derivative matrix is desired.dstOff
- the offset to the location of the transformed point that is stored in the destination array.derivate
-true
for computing the derivative, orfalse
if not needed.- Returns:
- the matrix of the transform derivative at the given source position,
or
null
if thederivate
argument 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 - 1
inclusive. If the given input value is outside that range, then the output value will be extrapolated.- Specified by:
transform
in interfaceorg.opengis.referencing.operation.MathTransform1D
- Specified by:
transform
in 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:
derivative
in interfaceorg.opengis.referencing.operation.MathTransform1D
- Specified by:
derivative
in 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:
inverse
in interfaceorg.opengis.referencing.operation.MathTransform
- Specified by:
inverse
in interfaceorg.opengis.referencing.operation.MathTransform1D
- Overrides:
inverse
in classAbstractMathTransform1D
- Throws:
org.opengis.referencing.operation.NoninvertibleTransformException
-
computeHashCode
protected int computeHashCode()Computes a hash code value for this transform.- Overrides:
computeHashCode
in 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:
equals
in interfaceLenientComparable
- Overrides:
equals
in classAbstractMathTransform
- Parameters:
object
- the object to compare with this transform.mode
- the strictness level of the comparison. Default toSTRICT
.- Returns:
true
if the given object is considered equals to this math transform.- See Also:
-