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 intNumber of points in the temporary buffer used for transforming data.(package private) floatA global correlation factor, stored for information purpose only.private org.opengis.referencing.operation.TransformExceptionIf an error occurred during coordinate operations, the error.private final StringA name by witch this projection attempt is identified.(package private) final org.opengis.referencing.operation.MathTransformA 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[]Mapsprojectiondimensions toLinearTransformBuildertarget dimensions.(package private) final booleanWhether the inverse ofprojectionshall 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 TypeMethodDescriptionintcompareTo(ProjectedTransformTry other) Orders by the inverse of correlation coefficients.booleanImplements theMap.Entry.equals(Object)contract.(package private) static org.opengis.referencing.operation.TransformExceptiongetError(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.MathTransformgetValue()Returns the projection, taking in account axis swapping ifprojToGridis not an arithmetic progression.inthashCode()Implements theMap.Entry.hashCode()contract.(package private) static voidMakes 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 MatrixSISreplaceTransformed(MatrixSIS transform, MatrixSIS newValues) Replaces old transform coefficients by new values in the dimensions where a projection has been applied.org.opengis.referencing.operation.MathTransformsetValue(org.opengis.referencing.operation.MathTransform value) Do not allow modification of this entry.(package private) final NumberFormatsummarize(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 booleanReturnstrueifprojToGrid[i] == ifor 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. -
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[] projToGridMapsprojectiondimensions toLinearTransformBuildertarget 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 ofprojectionsource dimensions. -
reverseAfterLinearization
final boolean reverseAfterLinearizationWhether the inverse ofprojectionshall be concatenated to the final interpolated transform. Iftrue, theprojectioneffect 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. -
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- mapsprojectiondimensions toLinearTransformBuildertarget dimensions.expectedDimension- number ofLinearTransformBuildertarget 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 ifprojToGridis 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. Thecoordinatesargument is the value ofLinearTransformBuilder.targets, without clone (this method will only read those arrays). Only arrays at indices given byprojToGridwill be read; the other arrays will be ignored. The coordinate operation result will be stored in arrays of size[numDimensions][numPoints]wherenumDimensionsis the length of theprojToGridarray. 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
Thepoolqueue 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 anotherProjectedTransformTryinstance.- Parameters:
coordinates- theLinearTransformBuilder.targetsarrays of coordinates to transform.numPoints- number of points to transform:numPoints≤coordinates[i].length.pool- pre-allocated arrays of lengthnumPointsthat can be recycled.- Returns:
- results of coordinate operations (see method javadoc), or
nullif an error occurred.
-
recycle
Makes the given arrays available for reuse by other transforms. -
useSameDimensions
private boolean useSameDimensions()ReturnstrueifprojToGrid[i] == ifor 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. Thetargetsarray is copied if necessary, then values are replaced in the copied array. May returnnewValuesdirectly 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
targetsarray 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. Thecorrelationsarray is copied if necessary, then values are replaced in the copied array. May returnnewValuesdirectly if suitable.- Parameters:
correlations- the original correlation values. This array will not be modified.newValues- correlations computed byLinearTransformBuilderfor the dimensions specified at construction time.- Returns:
- a copy of the given
correlationarray with new values overwriting the old values.
-
replaceTransformed
Replaces old transform coefficients by new values in the dimensions where a projection has been applied. Thetransformmatrix is copied if necessary, then values are replaced in the copied matrix. May returnnewValuesdirectly if suitable.- Parameters:
transform- the original affine transform. This matrix will not be modified.newValues- coefficients computed byLinearTransformBuilderfor the dimensions specified at construction time.- Returns:
- a copy of the given
transformmatrix 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.NaNvalues are last.Note: this comparison is inconsistent with
equals(Object). The fact thatProjectedTransformTryinstances are comparable should not be visible in public API.- Specified by:
compareToin 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, ornullif 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.
-