Class DomainLinearizer

java.lang.Object
org.apache.sis.coverage.grid.DomainLinearizer

public class DomainLinearizer extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    Whether to force lower grid coordinates to (0,0,…).
    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
    Constructor
    Description
    Creates a new linearizer.
  • Method Summary

    Modifier and Type
    Method
    Description
    apply(GridCoverage coverage)
    Returns a grid coverage with a linear approximation of the grid to CRS conversion.
    Creates a grid geometry with a linear approximation of the grid to CRS conversion.
    boolean
    Returns whether GridExtent 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
    Callback for custom modification of linear approximation.
    Returns the grid coverage processor associated to this linearizer.
    void
    setGridStartsAtZero(boolean force)
    Sets whether GridExtent should have their lower grid coordinates set to zero.
    void
    setScaleFactor(double factor)
    Sets the scale factor to apply on coordinates in all dimensions.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • gridStartsAtZero

      private boolean gridStartsAtZero
      Whether to force lower grid coordinates to (0,0,…).
      See Also:
    • scale

      private double scale
      Scale factor applied on grid coordinates, or 1 if none.
      See Also:
    • processor

      private GridCoverageProcessor 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 whether GridExtent should have their lower grid coordinates set to zero. If true, then DomainLinearizer will opportunistically apply translation on the "grid to CRS" conversion in such a way that GridExtent.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 whether GridExtent should have their lower grid coordinates set to zero. The default value is false.
      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

      private GridCoverageProcessor 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 by apply(GridGeometry). If the grid to CRS conversion of the given coverage is already linear, then this method returns coverage.
      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 (positionlinear 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 returns gg.
      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

      private org.opengis.referencing.operation.MathTransform modify(LinearTransform gridToCRS)
      Callback for custom modification of linear approximation. This method is invoked by apply(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 before gridToCRS, 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 by DomainLinearizer.
      Returns:
      the approximation to use for creating a new GridGeometry. Should be linear.