Package org.apache.sis.storage.geotiff
Class GridGeometryBuilder
java.lang.Object
org.apache.sis.storage.geotiff.GeoKeysLoader
org.apache.sis.storage.geotiff.GridGeometryBuilder
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 isPixelInCell.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 Summary
FieldsModifier and TypeFieldDescriptionprivate MatrixSIS
The conversion from grid coordinates to CRS coordinates as an affine transform.private org.opengis.metadata.spatial.CellGeometry
POINT
ifGeoKeys.RasterType
isGeoCodes.RasterPixelIsPoint
,AREA
if it isGeoCodes.RasterPixelIsArea
, or null if unspecified.private boolean
true
ifaffine
has been specified by a complete matrix (Tags.ModelTransformation
), orfalse
if it has been specified by the scale factors only (Tags.ModelPixelScaleTag
).private String
Suggested value for a general description of the transformation form grid coordinates to "real world" coordinates.Raster model tie points.Fields inherited from class org.apache.sis.storage.geotiff.GeoKeysLoader
asciiParameters, keyDirectory, logger, majorRevision, minorRevision, numericParameters, SEPARATOR
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates the grid geometry and collect related metadata.private static void
canNotCreate
(Reader reader, Exception e) Logs a warning telling that we cannot create a grid geometry for the given reason.void
completeMetadata
(GridGeometry gridGeometry, MetadataBuilder metadata) Completes ISO 19115 metadata with some GeoTIFF values inferred from the geotags.void
setGridToCRS
(Vector terms, int size) Sets theaffine
transform from a complete matrix.void
setScaleFactors
(Vector terms) Sets only the scale terms of theaffine
transform.boolean
Ifaffine
has been specified with only the scale factor, computes the translation terms now.Methods inherited from class org.apache.sis.storage.geotiff.GeoKeysLoader
load, setAsciiParameters
-
Field Details
-
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
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 inTags.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 fieldnull
.
- By a combination of a single
-
completeMatrixSpecified
private boolean completeMatrixSpecifiedtrue
ifaffine
has been specified by a complete matrix (Tags.ModelTransformation
), orfalse
if it has been specified by the scale factors only (Tags.ModelPixelScaleTag
). -
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 ofbuild(Reader, long, long)
call. -
cellGeometry
private org.opengis.metadata.spatial.CellGeometry cellGeometryPOINT
ifGeoKeys.RasterType
isGeoCodes.RasterPixelIsPoint
,AREA
if it isGeoCodes.RasterPixelIsArea
, or null if unspecified. This information is obtained as a side-effect ofbuild(Reader, long, long)
call.
-
-
Constructor Details
-
GridGeometryBuilder
GridGeometryBuilder()Creates a new builder.
-
-
Method Details
-
setGridToCRS
Sets theaffine
transform from a complete matrix.- Parameters:
terms
- the matrix in a row-major fashion.size
- the matrix size, either 3 or 4.
-
setScaleFactors
Sets only the scale terms of theaffine
transform. The translation terms are set to NaN, meaning they will need to be determined later. -
validateMandatoryTags
public boolean validateMandatoryTags()Ifaffine
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 aTags.ModelPixelScaleTag
andTags.ModelTiePoints
. The latter should have a single record.- Returns:
true
on success (including nothing to compute), orfalse
if the computation attempt failed because of missingTags.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 aftervalidateMandatoryTags()
. 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
Completes ISO 19115 metadata with some GeoTIFF values inferred from the geotags.Prerequisite
build(Reader, long, long)
must have been invoked successfully before this method.ImageFileDirectory
must have filled its part of metadata before to invoke this method.
MetadataBuilder.newGridRepresentation(MetadataBuilder.GridType)
with the appropriateGEORECTIFIED
orGEOREFERENCEABLE
type. Storage locations are:metadata/spatialRepresentationInfo/*
metadata/identificationInfo/spatialRepresentationType
metadata/referenceSystemInfo
- Parameters:
gridGeometry
- the grid geometry computed bybuild(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
Logs a warning telling that we cannot create a grid geometry for the given reason.
-