Class GridGeometryBuilder

java.lang.Object
org.apache.sis.storage.geotiff.GeoKeysLoader
org.apache.sis.storage.geotiff.GridGeometryBuilder

final class GridGeometryBuilder extends GeoKeysLoader
Helper class for creating a GridGeometry from GeoTIFF data. The coordinate reference system part is built by CRSBuilder.

Pixel center versus pixel corner

The policy about whether the conversion maps pixel corner or pixel center in GeoTIFF files does not seem totally clear. But the practice at least with GDAL seems to consider the following as equivalent: and The former is PixelInCell.CELL_CORNER convention while the latter is PixelInCell.CELL_CENTER. Note that the translation coefficients in the grid to CRS matrix is crs - grid × scale. So compared to the CELL_CORNER case, the CELL_CENTER case has a translation of +0.5 × scale.
Since:
1.0
Version:
1.2
  • Field Details

    • modelTiePoints

      public Vector modelTiePoints
      Raster model tie points. This vector contains coordinate values structured as (I,J,K, X,Y,Z) records. The (I,J,K) coordinate values specify the point at location (I,J) in raster space with pixel-value K, and (X,Y,Z) coordinate values specify the point in the Coordinate Reference System. In most cases the coordinate system is only two-dimensional, in which case both K and Z should be set to zero.
    • affine

      private MatrixSIS affine
      The conversion from grid coordinates to CRS coordinates as an affine transform. The "grid to CRS" transform can be determined in different ways, from simpler to more complex:
      • By a combination of a single modelTiePoints with the 3 values given in Tags.ModelPixelScaleTag as documented in the Javadoc of that tag.
      • By a Tags.ModelTransformation giving all coefficients of the 4×4 matrix}. Note that the third row and the third column have all their value set to 0 if the space model (or the coordinate reference system) should be two-dimensional.
      • By building a non-linear transformation from all modelTiePoints. Such transformation cannot be stored in a matrix, so will leave this field null.
      By convention, the translation column is set to NaN values if it needs to be computed from the tie point.
    • completeMatrixSpecified

      private boolean completeMatrixSpecified
      true if affine has been specified by a complete matrix (Tags.ModelTransformation), or false if it has been specified by the scale factors only (Tags.ModelPixelScaleTag).
    • description

      private String description
      Suggested value for a general description of the transformation form grid coordinates to "real world" coordinates. This information is obtained as a side-effect of build(Reader, long, long) call.
    • cellGeometry

      private org.opengis.metadata.spatial.CellGeometry cellGeometry
      POINT if GeoKeys.RasterType is GeoCodes.RasterPixelIsPoint, AREA if it is GeoCodes.RasterPixelIsArea, or null if unspecified. This information is obtained as a side-effect of build(Reader, long, long) call.
  • Constructor Details

    • GridGeometryBuilder

      GridGeometryBuilder()
      Creates a new builder.
  • Method Details

    • setGridToCRS

      public void setGridToCRS(Vector terms, int size)
      Sets the affine transform from a complete matrix.
      Parameters:
      terms - the matrix in a row-major fashion.
      size - the matrix size, either 3 or 4.
    • setScaleFactors

      public void setScaleFactors(Vector terms)
      Sets only the scale terms of the affine transform. The translation terms are set to NaN, meaning they will need to be determined later.
    • validateMandatoryTags

      public boolean validateMandatoryTags()
      If affine has been specified with only the scale factor, computes the translation terms now. If needed, this method computes the translation terms from the (usually singleton) tie point. This happen when the GeoTIFF file has a Tags.ModelPixelScaleTag and Tags.ModelTiePoints. The latter should have a single record.
      Returns:
      true on success (including nothing to compute), or false if the computation attempt failed because of missing Tags.ModelTiePoints.
      See Also:
    • build

      public GridGeometry build(Reader reader, long width, long height) throws org.opengis.util.FactoryException
      Creates the grid geometry and collect related metadata. This method shall be invoked exactly once after validateMandatoryTags(). After this method call (if successful), the returned value is guaranteed non-null and can be used as a flag for determining that the build has been completed.
      Parameters:
      width - the image width in pixels.
      height - the image height in pixels.
      Returns:
      the grid geometry, guaranteed non-null.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while creating a CRS or a transform.
    • completeMetadata

      public void completeMetadata(GridGeometry gridGeometry, MetadataBuilder metadata)
      Completes ISO 19115 metadata with some GeoTIFF values inferred from the geotags.

      Prerequisite

      This method invokes MetadataBuilder.newGridRepresentation(MetadataBuilder.GridType) with the appropriate GEORECTIFIED or GEOREFERENCEABLE type. Storage locations are:
      • metadata/spatialRepresentationInfo/*
      • metadata/identificationInfo/spatialRepresentationType
      • metadata/referenceSystemInfo
      Parameters:
      gridGeometry - the grid geometry computed by build(Reader, long, long).
      metadata - the helper class where to write metadata values.
      Throws:
      NumberFormatException - if a numeric value was stored as a string and cannot be parsed.
    • canNotCreate

      private static void canNotCreate(Reader reader, Exception e)
      Logs a warning telling that we cannot create a grid geometry for the given reason.