Class ProjectedTransformTry
- All Implemented Interfaces:
Comparable<ProjectedTransformTry>
,Map.Entry<String,
org.opengis.referencing.operation.MathTransform>
LinearTransformBuilder
needs only
to keep the best attempt.
Purpose: localization grids in netCDF files contain (longitude, latitude) values for all pixels.
LocalizationGridBuilder
first computes a linear (affine) approximation of a localization grid, then stores the residuals.
This approach works well when the residuals are small. However if the localization grid is non-linear, then the affine transform
is a poor approximation of that grid and the residuals are high. High residuals make inverse transforms hard to compute, which
sometimes cause a TransformException
with "no convergence" error message.
In practice, localization grids in netCDF files are often used for storing the results of a map projection, e.g. Mercator.
This class allows LocalizationGridBuilder
to try to transform the grid using a given list of map projections and see
if one of those projections results in a grid closer to an affine transform. In other words, we use this class for trying to
guess what the projection may be. It is okay if the guess is not a perfect match; if the residuals become smalls enough,
it will resolve the "no convergence" errors.
Note: compareTo(ProjectedTransformTry)
is inconsistent with equals(Object)
.
The fact that ProjectedTransformTry
instances are comparable should not be visible in public API.
- Since:
- 1.0
- Version:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
Number of points in the temporary buffer used for transforming data.(package private) float
A global correlation factor, stored for information purpose only.private org.opengis.referencing.operation.TransformException
If an error occurred during coordinate operations, the error.private final String
A name by witch this projection attempt is identified.(package private) final org.opengis.referencing.operation.MathTransform
A conversion from a non-linear grid (typically with longitude and latitude values) to something that may be more linear (typically, but not necessarily, a map projection).private final int[]
Mapsprojection
dimensions toLinearTransformBuilder
target dimensions.(package private) final boolean
Whether the inverse ofprojection
shall be concatenated to the final interpolated transform. -
Constructor Summary
ConstructorsConstructorDescriptionProjectedTransformTry
(String name, org.opengis.referencing.operation.MathTransform projection, int[] projToGrid, int expectedDimension, boolean reverseAfterLinearization) Prepares a new attempt to project a localization grid.Creates a new instance initialized to a copy of the given instance but without result. -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(ProjectedTransformTry other) Orders by the inverse of correlation coefficients.boolean
Implements theMap.Entry.equals(Object)
contract.(package private) static org.opengis.referencing.operation.TransformException
getError
(List<ProjectedTransformTry> linearizers) Returns the first error in the given list of linearizers.getKey()
Returns the name by witch this projection attempt is identified.org.opengis.referencing.operation.MathTransform
getValue()
Returns the projection, taking in account axis swapping ifprojToGrid
is not an arithmetic progression.int
hashCode()
Implements theMap.Entry.hashCode()
contract.(package private) static void
Makes the given arrays available for reuse by other transforms.(package private) final double[][]
replaceTransformed
(double[][] targets, double[][] newValues) Replaces old target arrays by new values in the dimensions where a projection has been applied.(package private) final double[]
replaceTransformed
(double[] correlations, double[] newValues) Replaces old correlation values by new values in the dimensions where a projection has been applied.(package private) final MatrixSIS
replaceTransformed
(MatrixSIS transform, MatrixSIS newValues) Replaces old transform coefficients by new values in the dimensions where a projection has been applied.org.opengis.referencing.operation.MathTransform
setValue
(org.opengis.referencing.operation.MathTransform value) Do not allow modification of this entry.(package private) final NumberFormat
summarize
(TableAppender table, NumberFormat nf, Locale locale) Formats a summary of this projection attempt.toString()
Returns a string representation of this projection attempt for debugging purpose.(package private) final double[][]
Transforms target coordinates of a localization grid.private boolean
Returnstrue
ifprojToGrid[i] == i
for all i.
-
Field Details
-
BUFFER_CAPACITY
private static final int BUFFER_CAPACITYNumber of points in the temporary buffer used for transforming data. The buffer length will be this capacity multiplied by the number of dimensions.- See Also:
-
name
A name by witch this projection attempt is identified.- See Also:
-
projection
final org.opengis.referencing.operation.MathTransform projectionA conversion from a non-linear grid (typically with longitude and latitude values) to something that may be more linear (typically, but not necessarily, a map projection).- See Also:
-
projToGrid
private final int[] projToGridMapsprojection
dimensions toLinearTransformBuilder
target dimensions. For example if this array is{2,1}
, then dimensions 0 and 1 ofprojection
(both source and target dimensions) will map dimensions 2 and 1 ofLinearTransformBuilder.targets
. The length of this array shall be equal to the number ofprojection
source dimensions. -
reverseAfterLinearization
final boolean reverseAfterLinearizationWhether the inverse ofprojection
shall be concatenated to the final interpolated transform. Iftrue
, theprojection
effect will be cancelled in the final result, i.e. the target coordinates will be approximately the same as if no projection were applied. In such case, the advantage of applying a projection is to improve numerical stability with a better linear approximation in the first step of the coordinate transformation process. -
correlation
float correlationA global correlation factor, stored for information purpose only. -
error
private org.opengis.referencing.operation.TransformException errorIf an error occurred during coordinate operations, the error. Otherwisenull
.- See Also:
-
-
Constructor Details
-
ProjectedTransformTry
ProjectedTransformTry(ProjectedTransformTry other) Creates a new instance initialized to a copy of the given instance but without result. This is used by copy constructors.- See Also:
-
ProjectedTransformTry
ProjectedTransformTry(String name, org.opengis.referencing.operation.MathTransform projection, int[] projToGrid, int expectedDimension, boolean reverseAfterLinearization) Prepares a new attempt to project a localization grid. All arguments are stored as-is (arrays are not cloned).- Parameters:
name
- a name by witch this projection attempt is identified.projection
- conversion from non-linear grid to something that may be more linear.projToGrid
- mapsprojection
dimensions toLinearTransformBuilder
target dimensions.expectedDimension
- number ofLinearTransformBuilder
target dimensions.- Throws:
org.opengis.geometry.MismatchedDimensionException
- if the projection does not have the expected number of dimensions.
-
-
Method Details
-
getKey
Returns the name by witch this projection attempt is identified. -
getValue
public org.opengis.referencing.operation.MathTransform getValue()Returns the projection, taking in account axis swapping ifprojToGrid
is not an arithmetic progression. -
setValue
public org.opengis.referencing.operation.MathTransform setValue(org.opengis.referencing.operation.MathTransform value) Do not allow modification of this entry. -
transform
Transforms target coordinates of a localization grid. Thecoordinates
argument is the value ofLinearTransformBuilder.targets
, without clone (this method will only read those arrays). Only arrays at indices given byprojToGrid
will be read; the other arrays will be ignored. The coordinate operation result will be stored in arrays of size[numDimensions][numPoints]
wherenumDimensions
is the length of theprojToGrid
array. Indices are as below, with 0 ≤ d ≤numDimensions
:results[d]
contains the coordinates in dimension d.results[d][i]
is a coordinate of the point at index i.
replaceTransformed(double[][], double[][])
before final storage inLinearTransformBuilder
.Pool of arrays
Thepool
queue is initially empty. Arrays created by this method and later discarded will be added to that queue, for recycling if this method is invoked again for anotherProjectedTransformTry
instance.- Parameters:
coordinates
- theLinearTransformBuilder.targets
arrays of coordinates to transform.numPoints
- number of points to transform:numPoints
≤coordinates[i].length
.pool
- pre-allocated arrays of lengthnumPoints
that can be recycled.- Returns:
- results of coordinate operations (see method javadoc), or
null
if an error occurred.
-
recycle
Makes the given arrays available for reuse by other transforms. -
useSameDimensions
private boolean useSameDimensions()Returnstrue
ifprojToGrid[i] == i
for all i. -
replaceTransformed
final double[][] replaceTransformed(double[][] targets, double[][] newValues) Replaces old target arrays by new values in the dimensions where a projection has been applied. Thetargets
array is copied if necessary, then values are replaced in the copied array. May returnnewValues
directly if suitable.- Parameters:
targets
- the original targets values. This array will not be modified.newValues
- targets computed bytransform(…)
for the dimensions specified at construction time.- Returns:
- a copy of the given
targets
array with new values overwriting the old values.
-
replaceTransformed
final double[] replaceTransformed(double[] correlations, double[] newValues) Replaces old correlation values by new values in the dimensions where a projection has been applied. Thecorrelations
array is copied if necessary, then values are replaced in the copied array. May returnnewValues
directly if suitable.- Parameters:
correlations
- the original correlation values. This array will not be modified.newValues
- correlations computed byLinearTransformBuilder
for the dimensions specified at construction time.- Returns:
- a copy of the given
correlation
array with new values overwriting the old values.
-
replaceTransformed
Replaces old transform coefficients by new values in the dimensions where a projection has been applied. Thetransform
matrix is copied if necessary, then values are replaced in the copied matrix. May returnnewValues
directly if suitable.- Parameters:
transform
- the original affine transform. This matrix will not be modified.newValues
- coefficients computed byLinearTransformBuilder
for the dimensions specified at construction time.- Returns:
- a copy of the given
transform
matrix with new coefficients overwriting the old values.
-
getError
static org.opengis.referencing.operation.TransformException getError(List<ProjectedTransformTry> linearizers) Returns the first error in the given list of linearizers. Errors after the first one are added as suppressed exceptions. If no error are found, this method returnsnull
. -
compareTo
Orders by the inverse of correlation coefficients. Highest coefficients (best correlations) are first, lower coefficients are next,Float.NaN
values are last.Note: this comparison is inconsistent with
equals(Object)
. The fact thatProjectedTransformTry
instances are comparable should not be visible in public API.- Specified by:
compareTo
in interfaceComparable<ProjectedTransformTry>
-
equals
Implements theMap.Entry.equals(Object)
contract. -
hashCode
public int hashCode()Implements theMap.Entry.hashCode()
contract. -
summarize
Formats a summary of this projection attempt. This method formats the following columns:- The projection name.
- The corelation coefficient, or the error message if an error occurred.
- Parameters:
table
- the table where to write a row.nf
- format to use for writing coefficients, ornull
if not yet created.locale
- the locale to use for messages or if a number format must be created.- Returns:
- format used for writing coefficients, or
null
.
-
toString
Returns a string representation of this projection attempt for debugging purpose.
-