Package org.apache.sis.coverage.grid
Class DomainLinearizer
java.lang.Object
org.apache.sis.coverage.grid.DomainLinearizer
Method for replacing a non-linear "grid to CRS" conversion by a linear conversion (affine transform).
The
GridGeometry
class allows non-linear "grid to CRS"
conversions, but some GridGeometry
usages are restricted to linear (affine) conversions.
The DomainLinearizer
class encapsulates the method used for replacing non-linear conversions
by a linear approximation.
The same instance can be reused by invoking apply(…)
methods for many GridCoverage
or GridGeometry
instances.
Limitations
Current implementation is designed for two-dimensional grid geometries. Support for higher dimensions is not guaranteed.- Since:
- 1.1
- Version:
- 1.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
Whether to force lower grid coordinates to (0,0,…).private GridCoverageProcessor
The processor to use for coverage ressampling, created when first needed.private double
Scale factor applied on grid coordinates, or 1 if none. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply
(GridCoverage coverage) Returns a grid coverage with a linear approximation of the grid to CRS conversion.apply
(GridGeometry gg) Creates a grid geometry with a linear approximation of the grid to CRS conversion.boolean
Returns whetherGridExtent
should have their lower grid coordinates set to zero.double
Returns the scale factor applied on coordinates in all dimensions.private org.opengis.referencing.operation.MathTransform
modify
(LinearTransform gridToCRS) Callback for custom modification of linear approximation.private GridCoverageProcessor
Returns the grid coverage processor associated to this linearizer.void
setGridStartsAtZero
(boolean force) Sets whetherGridExtent
should have their lower grid coordinates set to zero.void
setScaleFactor
(double factor) Sets the scale factor to apply on coordinates in all dimensions.
-
Field Details
-
gridStartsAtZero
private boolean gridStartsAtZeroWhether to force lower grid coordinates to (0,0,…).- See Also:
-
scale
private double scaleScale factor applied on grid coordinates, or 1 if none.- See Also:
-
processor
The processor to use for coverage ressampling, created when first needed.- See Also:
-
-
Constructor Details
-
DomainLinearizer
public DomainLinearizer()Creates a new linearizer.
-
-
Method Details
-
getGridStartsAtZero
public boolean getGridStartsAtZero()Returns whetherGridExtent
should have their lower grid coordinates set to zero. Iftrue
, thenDomainLinearizer
will opportunistically apply translation on the "grid to CRS" conversion in such a way thatGridExtent.getLow()
is 0 for all dimensions.- Returns:
- whether to force lower grid coordinates to (0,0,…).
- See Also:
-
setGridStartsAtZero
public void setGridStartsAtZero(boolean force) Sets whetherGridExtent
should have their lower grid coordinates set to zero. The default value isfalse
.- Parameters:
force
- whether to force lower grid coordinates to (0,0,…).
-
getScaleFactor
public double getScaleFactor()Returns the scale factor applied on coordinates in all dimensions.- Returns:
- scale factor applied on coordinates in all dimensions, or 1 if none.
-
setScaleFactor
public void setScaleFactor(double factor) Sets the scale factor to apply on coordinates in all dimensions. Must be a value greater than zero. The default value is 1.- Parameters:
factor
- scale factor applied on coordinates in all dimensions, or 1 if none.
-
processor
Returns the grid coverage processor associated to this linearizer. -
apply
public GridCoverage apply(GridCoverage coverage) throws org.opengis.referencing.operation.TransformException Returns a grid coverage with a linear approximation of the grid to CRS conversion. The linear approximation is computed byapply(GridGeometry)
. If the grid to CRS conversion of the given coverage is already linear, then this method returnscoverage
.- Parameters:
coverage
- the grid coverage in which to make the grid to CRS conversion linear.- Returns:
- a grid coverage with a linear approximation of the grid to CRS conversion.
- Throws:
org.opengis.referencing.operation.TransformException
- if some cell coordinates cannot be computed.
-
apply
public GridGeometry apply(GridGeometry gg) throws org.opengis.referencing.operation.TransformException Creates a grid geometry with a linear approximation of the grid to CRS conversion. The approximation is computed by Least Mean Squares method: the affine transform coefficients are chosen in way making the average value of (position − linear approximation of position)² as small as possible for all cells in given grid geometry. If the grid to CRS conversion of the given grid geometry is already linear, then this method returnsgg
.- Parameters:
gg
- the grid geometry in which to make the grid to CRS conversion linear.- Returns:
- a grid geometry with a linear approximation of the grid to CRS conversion.
- Throws:
org.opengis.referencing.operation.TransformException
- if some cell coordinates cannot be computed.
-
modify
Callback for custom modification of linear approximation. This method is invoked byapply(GridGeometry)
after a linear "grid to CRS" approximation has been computed by the Least Mean Squares method. Subclasses can override this method for example in order to scale the conversion by some arbitrary factor.Tip: scales (if desired) should be applied beforegridToCRS
, i.e. on grid coordinates. Scales applied after the transform (i.e. on "real world" coordinates) may give unexpected results if the conversion contains a rotation.- Parameters:
gridToCRS
- an approximation of the "grid to CRS" conversion computed byDomainLinearizer
.- Returns:
- the approximation to use for creating a new
GridGeometry
. Should be linear.
-