Class GridGeometry
- All Implemented Interfaces:
Serializable
,LenientComparable
GridGeometry
contains:
- A grid extent (a.k.a. grid envelope),
often inferred from the
RenderedImage
size. - A grid to CRS transform, which may be inferred from the grid extent and the georeferenced envelope.
- A georeferenced envelope, which can be inferred from the grid extent and the grid to CRS transform.
- An optional Coordinate Reference System (CRS) specified as part of the georeferenced envelope. This CRS is the target of the grid to CRS transform.
- An estimation of
grid resolution
along each CRS axes, computed from the grid to CRS transform and eventually from the grid extent. - An indication of whether conversion for some axes is linear or not.
GridGeometry
knows nothing about RenderedImage
,
but GridCoverage2D
has this information and may use it for providing a missing grid extent.
By default, any request for an undefined property will throw an IncompleteGridGeometryException
.
In order to check if a property is defined, use isDefined(int)
.
Non-linear referencing
A key property is the "grid to CRS" conversion, which defines how to map pixel coordinates to "real world" coordinates such as latitudes and longitudes. This relationship is often linear (an affine transform), but not necessarily;GridGeometry
accepts non-linear conversions as well. Non-linear conversions may occur with images
using localization grids,
but non-linear conversions should not be used for expressing map projections (projections should be specified
in the Coordinate Reference System (CRS) instead).
Some applications cannot handle non-linear "grid to CRS" conversions.
For example, encoding an image in a GeoTIFF file is much simpler if the "grid to CRS" conversion is linear.
The DomainLinearizer
class can be used for replacing non-linear conversions by linear approximations.
Multi-threading
GridGeometry
instances are immutable and thread-safe.
The same instance can be shared by different GridCoverage
instances.- Since:
- 1.0
- Version:
- 1.3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
Helper class for formatting aGridGeometry
instance. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final org.opengis.referencing.operation.MathTransform
Same conversion thangridToCRS
but from cell corner instead of center.static final int
A bitmask to specify the validity of the Coordinate Reference System property.protected final ImmutableEnvelope
The geodetic envelope, ornull
if unknown.static final int
A bitmask to specify the validity of the geodetic envelope property.protected final GridExtent
The valid domain of a grid coverage, ornull
if unknown.static final int
A bitmask to specify the validity of the grid extent property.static final int
A bitmask to specify the validity of the geographic bounding box.private org.opengis.metadata.extent.GeographicBoundingBox
The geographic bounding box as an unmodifiable metadata instance, ornull
if not yet computed.static final int
A bitmask to specify the validity of the "grid to CRS" transform.protected final org.opengis.referencing.operation.MathTransform
The conversion from grid indices to "real world" coordinates, ornull
if unknown.(package private) final long
Whether the conversions from grid coordinates to the CRS are linear, for each target axis.protected final double[]
An estimation of the grid resolution, in units of the CRS axes.static final int
A bitmask to specify the validity of the grid resolution.private static final long
Serial number for inter-operability with different versions.static final int
A bitmask to specify the validity of the temporal period.private Instant[]
The start time and end time, ornull
if not yet computed.static final GridGeometry
An "empty" grid geometry with no value defined. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Constructor forUNDEFINED
singleton only.GridGeometry
(GridExtent extent, org.opengis.geometry.Envelope envelope, GridOrientation orientation) Creates an axis-aligned grid geometry with an extent and an envelope.GridGeometry
(GridExtent extent, org.opengis.referencing.datum.PixelInCell anchor, org.opengis.referencing.operation.MathTransform gridToCRS, org.opengis.referencing.crs.CoordinateReferenceSystem crs) Creates a new grid geometry from a grid extent and a mapping from cell coordinates to "real world" coordinates.(package private)
GridGeometry
(GridExtent extent, org.opengis.referencing.operation.MathTransform gridToCRS, org.opengis.referencing.operation.MathTransform cornerToCRS, ImmutableEnvelope envelope, double[] resolution, long nonLinears) Creates a new grid geometry from the given components.protected
GridGeometry
(GridGeometry other) Creates a new grid geometry with the same values than the given grid geometry.GridGeometry
(GridGeometry other, GridExtent extent, org.opengis.referencing.operation.MathTransform toOther) Creates a new grid geometry derived from the given grid geometry with a new extent and a modified transform.GridGeometry
(org.opengis.referencing.datum.PixelInCell anchor, org.opengis.referencing.operation.MathTransform gridToCRS, org.opengis.geometry.Envelope envelope, GridRoundingMode rounding) Creates a new grid geometry from a geospatial envelope and a mapping from cell coordinates to "real world" coordinates. -
Method Summary
Modifier and TypeMethodDescriptionprivate ImmutableEnvelope
computeEnvelope
(org.opengis.referencing.operation.MathTransform specified, org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.opengis.geometry.Envelope limits) Computes the envelope with the given coordinate reference system.private static org.opengis.referencing.operation.MathTransform
cornerToCenter
(org.opengis.referencing.operation.MathTransform gridToCRS) Converts a "grid to CRS" transform from "cell corner" convention to "cell center" convention.org.opengis.referencing.crs.DerivedCRS
createImageCRS
(String name, org.opengis.referencing.datum.PixelInCell anchor) Creates a one-, two- or three-dimensional coordinate reference system for cell indices in the grid.org.opengis.referencing.operation.MathTransform
createTransformTo
(GridGeometry target, org.opengis.referencing.datum.PixelInCell anchor) Creates a transform from cell coordinates in this grid to cell coordinates in the given grid.(package private) final int
Returns the default set of flags to use fortoString()
implementations.derive()
Returns an object that can be used for creating a new grid geometry derived from this grid geometry.private static void
ensureDimensionMatches
(int expected, GridExtent extent) Ensures that the given dimension is equal to the expected value.boolean
Compares the specified object with this grid geometry for equality.boolean
equals
(Object object, ComparisonMode mode) Compares the specified object with this grid geometry for equality.(package private) final boolean
equalsApproximately
(ImmutableEnvelope othenv) Returns whether the given envelope is equal to this grid geometry envelope with a tolerance threshold computed from grid resolution.(package private) static ArithmeticException
excessiveDimension
(org.opengis.referencing.operation.MathTransform gridToCRS) Invoked when the number of non-linear dimensions exceeds theGridGeometry
capacity.private static long
findNonLinearTargets
(org.opengis.referencing.operation.MathTransform gridToCRS) Guesses which target dimensions may be non-linear.(package private) final void
formatTo
(Locale locale, Vocabulary vocabulary, int bitmask, TreeTable.Node root) Formats a string representation of this grid geometry in the specified tree.(package private) final org.opengis.metadata.extent.GeographicBoundingBox
Returns thegeographicBBox
value ornull
if none.org.opengis.referencing.crs.CoordinateReferenceSystem
Returns the "real world" coordinate reference system.private static org.opengis.referencing.crs.CoordinateReferenceSystem
getCoordinateReferenceSystem
(org.opengis.geometry.Envelope envelope) Returns the coordinate reference system of the given envelope if defined, ornull
if none.final int
Returns the number of dimensions of the grid.org.opengis.geometry.Envelope
Returns the bounding box of "real world" coordinates for this grid geometry.org.opengis.geometry.Envelope
getEnvelope
(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Returns the "real world" bounding box of this grid geometry transformed to the given CRS.Returns the valid coordinate range of a grid coverage.Optional
<org.opengis.metadata.extent.GeographicBoundingBox> Returns the approximate latitude and longitude coordinates of the grid.org.opengis.referencing.operation.MathTransform
getGridToCRS
(org.opengis.referencing.datum.PixelInCell anchor) Returns the conversion from grid coordinates to "real world" coordinates.getLinearGridToCRS
(org.opengis.referencing.datum.PixelInCell anchor) Returns a linear approximation of the conversion from grid coordinates to "real world" coordinates.double[]
getResolution
(boolean allowEstimates) Returns an estimation of the grid resolution, in units of the coordinate reference system axes.(package private) final int
Returns the number of dimensions of the CRS.Instant[]
Returns the start time and end time of coordinates of the grid.int
hashCode()
Returns a hash value for this grid geometry.private IncompleteGridGeometryException
incomplete
(int bitmask, short errorKey) Invoked when a property has been requested for which we have for information.boolean
isConversionLinear
(int... targets) Indicates whether the grid to CRS conversion is linear for all the specified CRS axes.boolean
isDefined
(int bitmask) Returnstrue
if all the properties specified by the argument are set.(package private) final boolean
Returnstrue
if this grid geometry contains only an envelope and no other information.(package private) final boolean
Returnstrue
if this grid geometry contains only a grid extent and no other information.(package private) static void
recoverableException
(String caller, org.opengis.referencing.operation.TransformException exception) Invoked when a recoverable exception occurred.reduce
(int... dimensions) Deprecated.relocate
(GridExtent newExtent) Returns a grid geometry with the given grid extent, which implies a new "real world" computation.(package private) final org.opengis.referencing.operation.MathTransform
requireGridToCRS
(boolean center) Verifies that this grid geometry defines an extent and acornerToCRS
transform.(package private) static double[]
resolution
(org.opengis.referencing.operation.MathTransform gridToCRS, GridExtent domain, org.opengis.referencing.datum.PixelInCell anchor) Computes the resolution for the given grid extent and transform, or returnsnull
if unknown.private static double[]
resolution
(org.opengis.referencing.operation.Matrix gridToCRS, int numToIgnore) Computes the resolutions from the given matrix.selectDimensions
(int... dimensions) Returns a grid geometry that encompass only some dimensions of this grid geometry.shiftGrid
(long... translation) Translates grid coordinates by the given amount of cells without changing "real world" coordinates.private Instant[]
Returns thetimeRange
value without cloning.toString()
Returns a string representation of this grid geometry.Returns a tree representation of some elements of this grid geometry.translate
(long... translation) Deprecated.RenamedshiftGrid(long...)
for making clearer that this method changes grid coordinates without changing "real world" coordinates.upsample
(int... periods) Creates a new grid geometry upsampled by the given amount of cells along each grid dimensions.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerial number for inter-operability with different versions.- See Also:
-
CRS
public static final int CRSA bitmask to specify the validity of the Coordinate Reference System property.- See Also:
-
ENVELOPE
public static final int ENVELOPEA bitmask to specify the validity of the geodetic envelope property.- See Also:
-
EXTENT
public static final int EXTENTA bitmask to specify the validity of the grid extent property.- See Also:
-
GRID_TO_CRS
public static final int GRID_TO_CRSA bitmask to specify the validity of the "grid to CRS" transform.- See Also:
-
RESOLUTION
public static final int RESOLUTIONA bitmask to specify the validity of the grid resolution.- See Also:
-
GEOGRAPHIC_EXTENT
public static final int GEOGRAPHIC_EXTENTA bitmask to specify the validity of the geographic bounding box. This information can sometimes be derived from the envelope and the CRS. It is an optional element even with a complete grid geometry since the coordinate reference system is not required to have an horizontal component.- See Also:
-
TEMPORAL_EXTENT
public static final int TEMPORAL_EXTENTA bitmask to specify the validity of the temporal period. This information can sometimes be derived from the envelope and the CRS. It is an optional element even with a complete grid geometry since the coordinate reference system is not required to have a temporal component.- See Also:
-
extent
The valid domain of a grid coverage, ornull
if unknown. The lowest valid grid coordinate is zero forBufferedImage
, but may be non-zero for arbitraryRenderedImage
. A grid with 512 cells can have a minimum coordinate of 0 and maximum of 511.- See Also:
-
envelope
The geodetic envelope, ornull
if unknown. If non-null, this envelope is usually the gridextent
transformed to real world coordinates. The Coordinate Reference System} (CRS) of this envelope defines the "real world" CRS of this grid geometry.- See Also:
-
gridToCRS
protected final org.opengis.referencing.operation.MathTransform gridToCRSThe conversion from grid indices to "real world" coordinates, ornull
if unknown. If non-null, the conversion shall map cell center. This conversion is usually, but not necessarily, affine.- See Also:
-
cornerToCRS
final org.opengis.referencing.operation.MathTransform cornerToCRSSame conversion thangridToCRS
but from cell corner instead of center. This transform is preferable togridToCRS
for transforming envelopes. -
resolution
protected final double[] resolutionAn estimation of the grid resolution, in units of the CRS axes. Computed fromgridToCRS
, eventually together withextent
. May benull
if unknown. If non-null, the array length is equal to the number of CRS dimensions.- See Also:
-
nonLinears
final long nonLinearsWhether the conversions from grid coordinates to the CRS are linear, for each target axis. The bit located at1L << dimension
is set to 1 when the conversion at that dimension is non-linear. The dimension indices are those of the CRS, not the grid. The use oflong
type limits the capacity to 64 dimensions. But actuallyGridGeometry
can contain more dimensions provided that index of the last non-linear dimension is not greater than 64.- See Also:
-
geographicBBox
private transient volatile org.opengis.metadata.extent.GeographicBoundingBox geographicBBoxThe geographic bounding box as an unmodifiable metadata instance, ornull
if not yet computed. If no geographic extent can be computed for the envelope, then this is set toNilObject
.- See Also:
-
timeRange
The start time and end time, ornull
if not yet computed. If there is no time range, then the array is empty. If there is only a start time or an end time, then the array length is 1. Otherwise the array length is 2.- See Also:
-
UNDEFINED
An "empty" grid geometry with no value defined. All getter methods invoked on this instance will causeIncompleteGridGeometryException
to be thrown. This instance can be used as a place-holder when the grid geometry cannot be obtained.
-
-
Constructor Details
-
GridGeometry
private GridGeometry()Constructor forUNDEFINED
singleton only. -
GridGeometry
Creates a new grid geometry with the same values than the given grid geometry. This is a copy constructor for subclasses.- Parameters:
other
- the other grid geometry to copy.
-
GridGeometry
public GridGeometry(GridGeometry other, GridExtent extent, org.opengis.referencing.operation.MathTransform toOther) throws org.opengis.referencing.operation.TransformException Creates a new grid geometry derived from the given grid geometry with a new extent and a modified transform. This constructor is used for creating a grid geometry over a subregion (for example with the grid extent computed byGridDerivation.subgrid(Envelope, double...)
) or grid geometry for a subsampled raster.Conversion between old and new grid geometry
IftoOther
is non-null, it defines the conversion from grid coordinates of givenextent
to grid coordinates ofother
. That transform should be a scale and a translation only, but more complex transforms are accepted. ThecornerToCRS
transform of the new grid geometry will be set to the following concatenation:
The new grid geometry envelope will be computed from the new extent and transform, then clipped to the envelope of the other grid geometry. This clip is for preventing the envelope to become larger under the effect of subsampling because each cell become larger. The clip is not applied whenthis.cornerToCRS
=toOther
→other.cornerToCRS
toOther
isnull
because in such case, we presume that the grid extent has been changed for another reason than subsampling (e.g. application of a margin, in which case we want the envelope to be expanded).- Parameters:
other
- the other grid geometry to copy.extent
- the new extent for the grid geometry to construct, ornull
if none.toOther
- transform from this grid coordinates toother
grid coordinates, ornull
if none.- Throws:
NullPointerException
- ifextent
isnull
and the other grid geometry contains no other information.org.opengis.referencing.operation.TransformException
- if the math transform cannot compute the geospatial envelope from the grid extent.- Since:
- 1.2
- See Also:
-
GridGeometry
public GridGeometry(GridExtent extent, org.opengis.referencing.datum.PixelInCell anchor, org.opengis.referencing.operation.MathTransform gridToCRS, org.opengis.referencing.crs.CoordinateReferenceSystem crs) Creates a new grid geometry from a grid extent and a mapping from cell coordinates to "real world" coordinates. At least one ofextent
,gridToCRS
orcrs
arguments shall be non-null. IfgridToCRS
is non-null, thenanchor
shall be non-null too with one of the following values:PixelInCell.CELL_CENTER
if conversions of cell indices bygridToCRS
give "real world" coordinates close to the center of each cell.PixelInCell.CELL_CORNER
if conversions of cell indices bygridToCRS
give "real world" coordinates at the corner of each cell. The cell corner is the one for which all grid indices have the smallest values (closest to negative infinity).
API note: there is no default value foranchor
because experience shows that images shifted by ½ pixel (with pixels that may be tens of kilometres large) is a recurrent problem. We want to encourage developers to always think about wether their grid to CRS transform is mapping pixel corner or center.Upcoming API generalization: theextent
type of this method may be changed toGridEnvelope
interface in a future Apache SIS version. This is pending GeoAPI update. In addition, thePixelInCell
code list currently defined in theorg.opengis.referencing.datum
package may move in another package in a future GeoAPI version because this type is no longer defined by the ISO 19111 standard after the 2018 revision.- Parameters:
extent
- the valid extent of grid coordinates, ornull
if unknown.anchor
- Cell center for OGC conventions or cell corner for Java2D/JAI conventions.gridToCRS
- the mapping from grid coordinates to "real world" coordinates, ornull
if unknown.crs
- the coordinate reference system of the "real world" coordinates, ornull
if unknown.- Throws:
NullPointerException
- ifextent
,gridToCRS
andcrs
arguments are all null.org.opengis.geometry.MismatchedDimensionException
- if the math transform and the CRS do not have consistent dimensions.IllegalGridGeometryException
- if the math transform cannot compute the geospatial envelope or resolution from the grid extent.
-
GridGeometry
public GridGeometry(org.opengis.referencing.datum.PixelInCell anchor, org.opengis.referencing.operation.MathTransform gridToCRS, org.opengis.geometry.Envelope envelope, GridRoundingMode rounding) Creates a new grid geometry from a geospatial envelope and a mapping from cell coordinates to "real world" coordinates. At least one ofgridToCRS
orenvelope
arguments shall be non-null. IfgridToCRS
is non-null, thenanchor
shall be non-null too with one of the values documented in theconstructor expecting a grid extent
.The given envelope shall encompass all cell surfaces, from the left border of leftmost cell to the right border of the rightmost cell and similarly along other axes. This constructor tries to store a geospatial envelope close to the specified envelope, but there is no guarantee that the envelope returned by
getEnvelope()
will be equal to the given envelope. The envelope stored in the newGridGeometry
may be slightly smaller, larger or shifted because the floating point values used in geospatial envelope cannot always be mapped to the integer coordinates used inGridExtent
. The rules for deciding whether coordinates should be rounded toward nearest integers, to floor or to ceil values are specified by theGridRoundingMode
argument.Because of the uncertainties explained in above paragraph, this constructor should be used only in last resort, when the grid extent is unknown. For determinist results, developers should prefer the constructor using grid extent as much as possible. In particular, this constructor is not suitable for computing grid geometry of tiles in a tiled image, because the above-cited uncertainties may result in apparently random black lines between tiles.
Upcoming API change: ThePixelInCell
code list currently defined in theorg.opengis.referencing.datum
package may move in another package in a future GeoAPI version because this type is no longer defined by the ISO 19111 standard after the 2018 revision. This code list may be taken by ISO 19123 in a future revision.- Parameters:
anchor
- Cell center for OGC conventions or cell corner for Java2D/JAI conventions.gridToCRS
- the mapping from grid coordinates to "real world" coordinates, ornull
if unknown.envelope
- the geospatial envelope, including its coordinate reference system if available. There is no guarantee that the envelope actually stored in theGridGeometry
will be equal to this specified envelope.rounding
- controls behavior of rounding from floating point values to integers.- Throws:
IllegalGridGeometryException
- if the math transform cannot compute the grid extent or the resolution.
-
GridGeometry
public GridGeometry(GridExtent extent, org.opengis.geometry.Envelope envelope, GridOrientation orientation) Creates an axis-aligned grid geometry with an extent and an envelope. This constructor can be used when the grid to CRS transform is unknown. If only the coordinate reference system is known, then the envelope coordinates can be all NaN.The main purpose of this constructor is to create "desired" grid geometries, for example for use in read or resample operations. For grid geometries describing preexisting data, it is safer and more flexible to use one of the constructors expecting a
MathTransform
argument.Dimension order
The given envelope shall always declare dimensions in same order than the given extent. This constructor may reorder axes iforientation
is (for example)GridOrientation.DISPLAY
, but in such case this constructor will derive itself an envelope and a CRS with reordered axes.- Parameters:
extent
- the valid extent of grid coordinates, ornull
if unknown.envelope
- the envelope together with CRS of the "real world" coordinates, ornull
if unknown.orientation
- high-level description of desired characteristics of thegridToCRS
transform. Ignored (can be null) ifenvelope
is null.- Throws:
NullPointerException
- ifextent
andenvelope
arguments are both null, or ifenvelope
is non-null butorientation
is null.- Since:
- 1.1
- See Also:
-
GridGeometry
GridGeometry(GridExtent extent, org.opengis.referencing.operation.MathTransform gridToCRS, org.opengis.referencing.operation.MathTransform cornerToCRS, ImmutableEnvelope envelope, double[] resolution, long nonLinears) Creates a new grid geometry from the given components. This constructor performs no verification (unless assertions are enabled).
-
-
Method Details
-
computeEnvelope
private ImmutableEnvelope computeEnvelope(org.opengis.referencing.operation.MathTransform specified, org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.opengis.geometry.Envelope limits) throws org.opengis.referencing.operation.TransformException Computes the envelope with the given coordinate reference system. This method is invoked from constructors. Theextent
,gridToCRS
andcornerToCRS
fields must be set before this method is invoked.- Parameters:
specified
- the transform specified by the user. This is not necessarilygridToCRS
.crs
- the coordinate reference system to declare in the envelope. May benull
.limits
- if non-null, intersect with that envelope. The CRS must be the same thancrs
.- Throws:
org.opengis.referencing.operation.TransformException
-
ensureDimensionMatches
private static void ensureDimensionMatches(int expected, GridExtent extent) throws org.opengis.geometry.MismatchedDimensionException Ensures that the given dimension is equal to the expected value. If not, throws an exception. This method assumes that the argument name is"extent"
.- Parameters:
expected
- the expected number of dimension.extent
- the extent to validate, ornull
if none.- Throws:
org.opengis.geometry.MismatchedDimensionException
-
recoverableException
static void recoverableException(String caller, org.opengis.referencing.operation.TransformException exception) Invoked when a recoverable exception occurred. Those exceptions must be minor enough that they can be silently ignored in most cases.- Parameters:
caller
- the method where exception occurred.exception
- the exception that occurred.
-
cornerToCenter
private static org.opengis.referencing.operation.MathTransform cornerToCenter(org.opengis.referencing.operation.MathTransform gridToCRS) Converts a "grid to CRS" transform from "cell corner" convention to "cell center" convention. This is a helper method for use ofGridGeometry(GridExtent, MathTransform, MathTransform, ImmutableEnvelope, double[], long)
constructor.- Parameters:
gridToCRS
- the transform to convert, ornull
if none.- Returns:
- the converted transform, or
null
if the given transform was null.
-
getDimension
public final int getDimension()Returns the number of dimensions of the grid. This is typically the same than the number of envelope dimensions or the number of coordinate reference system dimensions, but not necessarily.- Returns:
- the number of grid dimensions.
- See Also:
-
getTargetDimension
final int getTargetDimension()Returns the number of dimensions of the CRS. This is typically the same than the number of grid dimensions, but not necessarily. -
getExtent
Returns the valid coordinate range of a grid coverage. The lowest valid grid coordinate is zero forBufferedImage
, but may be non-zero for arbitraryRenderedImage
. A grid with 512 cells can have a minimum coordinate of 0 and maximum of 511.Upcoming API generalization: the return type of this method may be changed toGridEnvelope
interface in a future Apache SIS version. This is pending GeoAPI update.- Returns:
- the valid extent of grid coordinates (never
null
). - Throws:
IncompleteGridGeometryException
- if this grid geometry has no extent — i.e.isDefined(EXTENT)
returnedfalse
.
-
getGridToCRS
public org.opengis.referencing.operation.MathTransform getGridToCRS(org.opengis.referencing.datum.PixelInCell anchor) Returns the conversion from grid coordinates to "real world" coordinates. The conversion is often an affine transform, but not necessarily. Conversions from cell indices to geospatial coordinates can be performed for example as below: Callers must specify whether they want the "real world" coordinates of cell center or cell corner. The cell corner is the one for which all grid indices have the smallest values (closest to negative infinity). As a rule of thumb:- Use
PixelInCell.CELL_CENTER
for transforming points. - Use
PixelInCell.CELL_CORNER
for transforming envelopes with inclusive lower coordinates and exclusive upper coordinates.
API note: there is no default value foranchor
because experience shows that images shifted by ½ pixel (with pixels that may be tens of kilometres large) is a recurrent problem. We want to encourage developers to always think about wether the desired grid to CRS transform shall map pixel corner or center.- Parameters:
anchor
- the cell part to map (center or corner).- Returns:
- the conversion from grid coordinates to "real world" coordinates (never
null
). - Throws:
IllegalArgumentException
- if the givenanchor
is not a known code list value.IncompleteGridGeometryException
- if this grid geometry has no transform — i.e.isDefined(GRID_TO_CRS)
returnedfalse
.
- Use
-
getLinearGridToCRS
public LinearTransform getLinearGridToCRS(org.opengis.referencing.datum.PixelInCell anchor) throws org.opengis.referencing.operation.TransformException Returns a linear approximation of the conversion from grid coordinates to "real world" coordinates. If the value returned bygetGridToCRS(PixelInCell)
is already an instance ofLinearTransform
, then it is returned as is. Otherwise this method computes the tangent of the transform at the grid extent point of interest (usually the center of the grid).- Parameters:
anchor
- the cell part to map (center or corner).- Returns:
- linear approximation of the conversion from grid coordinates to "real world" coordinates.
- Throws:
IllegalArgumentException
- if the givenanchor
is not a known code list value.IncompleteGridGeometryException
- if this grid geometry has no transform, or if the transform is non-linear but this grid geometry has no extent.org.opengis.referencing.operation.TransformException
- if an error occurred while computing the tangent.- Since:
- 1.3
-
getCoordinateReferenceSystem
private static org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem(org.opengis.geometry.Envelope envelope) Returns the coordinate reference system of the given envelope if defined, ornull
if none. Contrarily togetCoordinateReferenceSystem()
, this method does not throw exception. -
getCoordinateReferenceSystem
public org.opengis.referencing.crs.CoordinateReferenceSystem getCoordinateReferenceSystem()Returns the "real world" coordinate reference system.- Returns:
- the coordinate reference system (never
null
). - Throws:
IncompleteGridGeometryException
- if this grid geometry has no CRS — i.e.isDefined(CRS)
returnedfalse
.
-
getEnvelope
public org.opengis.geometry.Envelope getEnvelope()Returns the bounding box of "real world" coordinates for this grid geometry. This envelope is computed from the grid extent, which is transformed to the "real world" coordinate system. The initial envelope encompasses all cell surfaces, from the left border of leftmost cell to the right border of the rightmost cell and similarly along other axes. If this grid geometry is a subgrid, then the envelope is also clipped to the envelope of the original (non subsampled) grid geometry.- Returns:
- the bounding box in "real world" coordinates (never
null
). - Throws:
IncompleteGridGeometryException
- if this grid geometry has no envelope — i.e.isDefined(ENVELOPE)
returnedfalse
.
-
getEnvelope
public org.opengis.geometry.Envelope getEnvelope(org.opengis.referencing.crs.CoordinateReferenceSystem crs) throws org.opengis.referencing.operation.TransformException Returns the "real world" bounding box of this grid geometry transformed to the given CRS. This envelope is computed from the grid extent if available, or from the envelope otherwise.- Parameters:
crs
- the desired coordinate reference system for the returned envelope.- Returns:
- the bounding box in "real world" coordinates (never
null
). - Throws:
IncompleteGridGeometryException
- if this grid geometry has no extent and no envelope.org.opengis.referencing.operation.TransformException
- if the envelope cannot be transformed to the specified CRS.- Since:
- 1.2
-
getGeographicExtent
Returns the approximate latitude and longitude coordinates of the grid. The prime meridian is Greenwich, but the geodetic reference frame is not necessarily WGS 84. This is computed from the envelope if the coordinate reference system contains an horizontal component such as a geographic or projected CRS.API note: this method does not throwIncompleteGridGeometryException
because the geographic extent may be absent even with a complete grid geometry. Grid geometries are not required to have a spatial component on Earth surface; a raster could be a vertical profile for example.- Returns:
- the geographic bounding box in "real world" coordinates.
-
geographicBBox
final org.opengis.metadata.extent.GeographicBoundingBox geographicBBox()Returns thegeographicBBox
value ornull
if none. This method computes the box when first needed. -
getTemporalExtent
Returns the start time and end time of coordinates of the grid. If the grid has no temporal dimension, then this method returns an empty array. If only the start time or end time is defined, then returns an array of length 1. Otherwise this method returns an array of length 2 with the start time in the first element and the end time in the last element.- Returns:
- time range as an array of length 0 (if none), 1 or 2.
-
timeRange
Returns thetimeRange
value without cloning. This method computes the time range when first needed. -
getResolution
public double[] getResolution(boolean allowEstimates) Returns an estimation of the grid resolution, in units of the coordinate reference system axes. The length of the returned array is the number of CRS dimensions, withresolution[0]
being the resolution along the first CRS axis,resolution[1]
the resolution along the second CRS axis, etc. Note that this axis order is not necessarily the same than grid axis order.If the resolution at CRS dimension i is not a constant factor (i.e. the
isConversionLinear(i)
returnsfalse
), thenresolution[i]
is set to one of the following values:Double.NaN
ifallowEstimates
isfalse
.- An arbitrary representative resolution otherwise.
Current implementation computes the resolution at
grid center
, but different implementations may use alternative algorithms.
- Parameters:
allowEstimates
- whether to provide some values even for resolutions that are not constant factors.- Returns:
- an estimation of the grid resolution (never
null
). - Throws:
IncompleteGridGeometryException
- if this grid geometry has no resolution — i.e.isDefined(RESOLUTION)
returnedfalse
.
-
resolution
static double[] resolution(org.opengis.referencing.operation.MathTransform gridToCRS, GridExtent domain, org.opengis.referencing.datum.PixelInCell anchor) Computes the resolution for the given grid extent and transform, or returnsnull
if unknown. Resolutions are given in order of target axes and give a scale factor from source to target coordinates. If thegridToCRS
transform is linear, we do not even need to check the grid extent; it can be null. Otherwise (if the transform is non-linear) the extent is necessary. The easiest way to estimate a resolution is then to ask for the derivative at some arbitrary point (the point of interest).Note that for this computation, it does not matter if
gridToCRS
is the user-specified transform or thethis.gridToCRS
field value; both should produce equivalent results.- Parameters:
gridToCRS
- a transform for which to compute the resolution, ornull
if none.domain
- the domain for which to get a resolution, ornull
if none. If non-null, must be the source ofgridToCRS
.anchor
- the pixel corner versus pixel center convention to use.- Returns:
- the resolutions as positive numbers. May contain NaN values.
-
resolution
private static double[] resolution(org.opengis.referencing.operation.Matrix gridToCRS, int numToIgnore) Computes the resolutions from the given matrix. This is the magnitude of each row vector. Resolutions are given in order of target axes.- Parameters:
gridToCRS
- Jacobian matrix or affine transform for which to compute the resolution.numToIgnore
- number of rows and columns to ignore at the end of the matrix. This is 0 if the matrix is a derivative (i.e. we ignore nothing), or 1 if the matrix is an affine transform (i.e. we ignore the translation column and the [0 0 … 1] row).- Returns:
- the resolutions as positive numbers. May contain NaN values.
-
isConversionLinear
public boolean isConversionLinear(int... targets) Indicates whether the grid to CRS conversion is linear for all the specified CRS axes. The conversion from grid coordinates to real world coordinates is often linear for some dimensions, typically the horizontal ones at indices 0 and 1. But the vertical dimension (usually at index 2) is often non-linear, for example with data at 0, 5, 10, 100 and 1000 metres.- Parameters:
targets
- indices of CRS axes. This is not necessarily the same than indices of grid axes.- Returns:
true
if the conversion from grid coordinates to "real world" coordinates is linear for all the given CRS dimension.
-
findNonLinearTargets
private static long findNonLinearTargets(org.opengis.referencing.operation.MathTransform gridToCRS) Guesses which target dimensions may be non-linear. We currently don't have an API for finding the non-linear dimensions. Current implementation assumes that everything else thanLinearTransform
and pass-through dimensions are non-linear. This is not always true (e.g. in a Mercator projection, the "longitude → easting" part is linear too), but should be okay forGridGeometry
purposes.We keep trace of non-linear dimensions in a bitmask, with bits of non-linear dimensions set to 1. This limit us to 64 dimensions, which is assumed more than enough. Note that
GridGeometry
can contain more dimensions provided that index of the last non-linear dimension is not greater than 64.- Parameters:
gridToCRS
- the transform to "real world" coordinates, ornull
if unknown.- Returns:
- a bitmask of dimensions, or 0 (i.e. conversion assumed fully linear) if the given transform was null.
-
excessiveDimension
static ArithmeticException excessiveDimension(org.opengis.referencing.operation.MathTransform gridToCRS) Invoked when the number of non-linear dimensions exceeds theGridGeometry
capacity. -
incomplete
Invoked when a property has been requested for which we have for information.- Parameters:
bitmask
- the requested property, for assertion purpose.errorKey
- the resource key to use in error message.- Returns:
- the exception to be thrown by the caller.
-
requireGridToCRS
final org.opengis.referencing.operation.MathTransform requireGridToCRS(boolean center) throws IncompleteGridGeometryException Verifies that this grid geometry defines an extent and acornerToCRS
transform. They are the information required for mapping the grid to a spatiotemporal envelope or position. Note that this implies thatenvelope
is non-null (but not necessarily that its CRS is non-null).- Parameters:
center
-true
for "center to CRS" transform,false
for "corner to CRS" transform.- Returns:
gridToCRS
orcornerToCRS
.- Throws:
IncompleteGridGeometryException
-
isDefined
public boolean isDefined(int bitmask) Returnstrue
if all the properties specified by the argument are set. If this method returnstrue
, then invoking the corresponding getter methods will not throwIncompleteGridGeometryException
.- Parameters:
bitmask
- any combination ofCRS
,ENVELOPE
,EXTENT
,GRID_TO_CRS
andRESOLUTION
.- Returns:
true
if all specified properties are defined (i.e. invoking the corresponding getter methods will not throwIncompleteGridGeometryException
).- Throws:
IllegalArgumentException
- if the specified bitmask is not a combination of known masks.- See Also:
-
isExtentOnly
final boolean isExtentOnly()Returnstrue
if this grid geometry contains only a grid extent and no other information. Note: ifgridToCRS
isnull
, thencornerToCRS
andresolution
should be null as well. -
isEnvelopeOnly
final boolean isEnvelopeOnly()Returnstrue
if this grid geometry contains only an envelope and no other information. Note: ifgridToCRS
isnull
, thencornerToCRS
andresolution
should be null as well. -
derive
Returns an object that can be used for creating a new grid geometry derived from this grid geometry.GridDerivation
does not change the state of thisGridGeometry
but instead creates new instances as needed. Examples of modifications include clipping to a sub-area or applying a sub-sampling.Example: for clipping this grid geometry to a sub-area, one can use:EachGridDerivation
instance can be used only once and should be used in a single thread.GridDerivation
preserves the number of dimensions. For example, slicing sets the grid size to 1 in all dimensions specified by a slice point, but does not remove those dimensions from the grid geometry. For dimensionality reduction, seeselectDimensions(int[])
.- Returns:
- an object for deriving a grid geometry from
this
.
-
upsample
Creates a new grid geometry upsampled by the given amount of cells along each grid dimensions. This method multiplies low and high coordinates by the given periods, then scales thegrid to CRS
transform for compensating the grid change. The grid geometryenvelope
is preserved after upsampling.Number of arguments
Theperiods
array length should be equal to the number of grid dimensions. If the array is shorter, missing values default to 1 (i.e. samplings in unspecified dimensions are unchanged). If the array is longer, extraneous values are ignored.- Parameters:
periods
- the upsampling. Length shall be equal to the number of dimension and all values shall be greater than zero.- Returns:
- the upsampled grid geometry, or
this
is upsampling results in the same extent. - Throws:
IllegalArgumentException
- if a period is not greater than zero.- Since:
- 1.3
- See Also:
-
shiftGrid
Translates grid coordinates by the given amount of cells without changing "real world" coordinates. The returned grid has the same size than this grid, i.e. both low and high grid coordinates are displaced by the same amount of cells. The "grid to CRS" transforms are adjusted accordingly in order to map to the same "real world" coordinates.Number of arguments
Thetranslation
array length should be equal to the number of dimensions. If the array is shorter, missing values default to 0 (i.e. no translation in unspecified dimensions). If the array is longer, extraneous values are ignored.- Parameters:
translation
- translation to apply on each grid axis in order.- Returns:
- a grid geometry whose coordinates (both low and high ones) and the "grid to CRS" transforms have been translated by given amounts. If the given translation is a no-op (no value or only 0 ones), then this grid is returned as is.
- Throws:
ArithmeticException
- if the translation results in coordinates that overflow 64-bits integer.- Since:
- 1.3
- See Also:
-
translate
Deprecated.RenamedshiftGrid(long...)
for making clearer that this method changes grid coordinates without changing "real world" coordinates.Returns a grid geometry translated by the given amount of cells compared to this grid.- Parameters:
translation
- translation to apply on each grid axis in order.- Returns:
- a grid geometry whose coordinates and the "grid to CRS" transforms have been translated by given amounts.
- Since:
- 1.1
-
relocate
public GridGeometry relocate(GridExtent newExtent) throws org.opengis.referencing.operation.TransformException Returns a grid geometry with the given grid extent, which implies a new "real world" computation. The "grid to CRS" transforms and the resolution stay the same than thisGridGeometry
. The "real world" envelope is recomputed for the new grid extent using the "grid to CRS" transforms.The given extent is taken verbatim; this method does no clipping. The given extent does not need to intersect the extent of this grid geometry.
- Parameters:
newExtent
- extent of the grid geometry to return.- Returns:
- grid geometry with the given extent. May be
this
if there is no change. - Throws:
org.opengis.referencing.operation.TransformException
- if the geospatial envelope cannot be recomputed with the new grid extent.- Since:
- 1.3
-
selectDimensions
Returns a grid geometry that encompass only some dimensions of this grid geometry. The specified dimensions will be copied into a new grid geometry if necessary. The selection is applied on grid extent dimensions; they are not necessarily the same than the envelope dimensions. The given dimensions must be in strictly ascending order without duplicated values. The number of dimensions of the sub grid geometry will bedimensions.length
.This method performs a dimensionality reduction. This method cannot be used for changing dimension order.
- Parameters:
dimensions
- the grid (not CRS) dimensions to select, in strictly increasing order.- Returns:
- the sub-grid geometry, or
this
if the given array contains all dimensions of this grid geometry. - Throws:
IndexOutOfBoundsException
- if an index is out of bounds.- Since:
- 1.3
- See Also:
-
reduce
Deprecated.RenamedselectDimensions(int...)
for clarity and consistency withGridExtent
.Returns a grid geometry that encompass only some dimensions of this grid geometry.- Parameters:
dimensions
- the grid (not CRS) dimensions to select, in strictly increasing order.- Returns:
- the sub-grid geometry, or
this
if the given array contains all dimensions of this grid geometry.
-
createImageCRS
public org.opengis.referencing.crs.DerivedCRS createImageCRS(String name, org.opengis.referencing.datum.PixelInCell anchor) Creates a one-, two- or three-dimensional coordinate reference system for cell indices in the grid. This method returns a CRS which is derived from the "real world" CRS or a subset of it. If the "real world" CRS is an instance ofSingleCRS
, then the derived CRS has the following properties:GeneralDerivedCRS.getBaseCRS()
isgetCoordinateReferenceSystem()
.GeneralDerivedCRS.getConversionFromBase()
is the inverse ofgetGridToCRS(PixelInCell)
.
CompoundCRS
, then only the firstSingleCRS
(the head) is used. This is usually (but not necessarily) the horizontal component of the spatial CRS. The result is usually two-dimensional, but 1 and 3 dimensions are also possible.Because of above relationship, it is possible to use the derived CRS in a chain of operations with (for example)
CRS.findOperation(…)
.- Parameters:
name
- name of the CRS to create.anchor
- the cell part to map (center or corner).- Returns:
- a derived CRS for coordinates (cell indices) associated to the grid extent.
- Throws:
IncompleteGridGeometryException
- if the CRS, grid extent or "grid to CRS" transform is missing.- Since:
- 1.3
-
createTransformTo
public org.opengis.referencing.operation.MathTransform createTransformTo(GridGeometry target, org.opengis.referencing.datum.PixelInCell anchor) throws org.opengis.referencing.operation.TransformException Creates a transform from cell coordinates in this grid to cell coordinates in the given grid. The returned transform handles change of Coordinate Reference System and wraparound axes (e.g. longitude axis crossing the ±180° meridian) if applicable.Note: the transform created by this method may be non-invertible.
- Parameters:
target
- the grid which will be the target of returned transform.anchor
- Cell center for OGC conventions or cell corner for Java2D/JAI conventions.- Returns:
- transform from cell coordinates in this grid to cell coordinates in the given grid.
- Throws:
org.opengis.referencing.operation.TransformException
- if the math transform cannot be created.- Since:
- 1.1
-
hashCode
public int hashCode()Returns a hash value for this grid geometry. This value needs not to remain consistent between different implementations of the same class. -
equals
Compares the specified object with this grid geometry for equality. This method delegates toequals(object, ComparisonMode.STRICT)
.- Specified by:
equals
in interfaceLenientComparable
- Overrides:
equals
in classObject
- Parameters:
object
- the object to compare with.- Returns:
true
if the given object is equal to this grid geometry.- See Also:
-
equals
Compares the specified object with this grid geometry for equality. If the mode isComparisonMode.IGNORE_METADATA
or more flexible, then the axis types are ignored.- Specified by:
equals
in interfaceLenientComparable
- Parameters:
object
- the object to compare with this grid geometry for equality.mode
- the strictness level of the comparison.- Returns:
true
if the given object is equal to this grid geometry.- Since:
- 1.1
- See Also:
-
equalsApproximately
Returns whether the given envelope is equal to this grid geometry envelope with a tolerance threshold computed from grid resolution. If this grid geometry has no envelope, then this method arbitrarily returnstrue
(this unusual behavior is required byequals(Object, ComparisonMode)
). -
defaultFlags
final int defaultFlags()Returns the default set of flags to use fortoString()
implementations. Current implementation returns all core properties, augmented with only derived properties that are defined. -
toString
Returns a string representation of this grid geometry. The returned string is implementation dependent and may change in any future version. Current implementation is equivalent to a call totoTree(Locale, int)
with at leastEXTENT
,ENVELOPE
andCRS
flags. Whether more flags are present or not is unspecified. -
toTree
Returns a tree representation of some elements of this grid geometry. The tree representation is for debugging or logging purposes and may change in any future SIS version.- Parameters:
locale
- the locale to use for textual labels.bitmask
- combination ofEXTENT
,ENVELOPE
,CRS
,GRID_TO_CRS
,RESOLUTION
,GEOGRAPHIC_EXTENT
andTEMPORAL_EXTENT
.- Returns:
- a tree representation of the specified elements.
-
formatTo
Formats a string representation of this grid geometry in the specified tree.
-
selectDimensions(int...)
for clarity and consistency withGridExtent
.