public class GridGeometry2D extends GeneralGridGeometry
GridGeometry2D
class (some peoples said 2.5D) because a twodimensional grid coordinate is enough for
referencing a pixel without ambiguity. But a grid size of 512×512×2 pixels can not be
represented by this GridGeometry2D
, because a threedimensional coordinate is mandatory
for referencing a pixel without ambiguity.ImageGeometry
,
GeneralGridGeometry
,
Serialized FormModifier and Type  Field and Description 

int 
axisDimensionX
The (
gridDimensionX , gridDimensionY ) dimensions in the envelope space. 
int 
axisDimensionY
The (
gridDimensionX , gridDimensionY ) dimensions in the envelope space. 
int 
gridDimensionX
Index of column (
gridDimensionX ) and row (gridDimensionY ) ordinates in a
grid point. 
int 
gridDimensionY
Index of column (
gridDimensionX ) and row (gridDimensionY ) ordinates in a
grid point. 
CRS_BITMASK, ENVELOPE_BITMASK, GRID_RANGE_BITMASK, GRID_TO_CRS_BITMASK, gridRange, gridToCRS
Constructor and Description 

GridGeometry2D(GridEnvelope gridRange,
Envelope userRange)
Constructs a new grid geometry from an envelope.

GridGeometry2D(GridEnvelope gridRange,
MathTransform gridToCRS,
CoordinateReferenceSystem crs)
Constructs a new grid geometry from a grid range and a math transform.

GridGeometry2D(GridEnvelope gridRange,
PixelInCell anchor,
MathTransform gridToCRS,
CoordinateReferenceSystem crs,
Hints hints)
Constructs a new grid geometry from a math transform.

GridGeometry2D(GridEnvelope gridRange,
PixelOrientation anchor,
MathTransform gridToCRS,
CoordinateReferenceSystem crs,
Hints hints)
Constructs a new grid geometry from a math transform.

GridGeometry2D(GridGeometry other)
Creates a new grid geometry with the same values than the given grid geometry.

GridGeometry2D(PixelInCell anchor,
MathTransform gridToCRS,
Envelope envelope,
Hints hints)
Constructs a new grid geometry from an envelope and a math
transform.

GridGeometry2D(Rectangle gridRange,
Rectangle2D userRange)
Constructs a new twodimensional grid geometry.

Modifier and Type  Method and Description 

boolean 
equals(Object object)
Compares the specified object with this grid geometry for equality.

CoordinateReferenceSystem 
getCoordinateReferenceSystem2D()
Returns the twodimensional part of this grid geometry CRS.

MathTransform2D 
getCRSToGrid2D()
Returns a math transform for the two dimensional part for conversion from world to grid
coordinates.

MathTransform2D 
getCRSToGrid2D(PixelOrientation orientation)
Returns a math transform for the two dimensional part.

Envelope2D 
getEnvelope2D()
Returns the twodimensional bounding box for the coverage domain in coordinate reference
system coordinates.

GridEnvelope2D 
getGridRange2D()
Returns the twodimensional part of the grid range as a rectangle.

MathTransform 
getGridToCRS(PixelOrientation orientation)
Returns a math transform mapping the specified pixel part.

MathTransform2D 
getGridToCRS2D()
Returns a math transform for the two dimensional part.

MathTransform2D 
getGridToCRS2D(PixelOrientation orientation)
Returns a math transform for the two dimensional part.

DirectPosition 
gridToWorld(GridCoordinates2D point)
Transforms a point represented by a GridCoordinates2D object from grid to world coordinates.

Envelope2D 
gridToWorld(GridEnvelope2D gridEnv)
Transforms a rectangle represented by a GridEnvelope2D object from grid to world coordinates.

int 
hashCode()
Returns a hash value for this grid geometry.

CoordinateReferenceSystem 
reduce(CoordinateReferenceSystem crs)
Reduces the specified CRS to a twodimensional one.

Envelope2D 
reduce(Envelope envelope)
Reduces the specified envelope to a twodimensional one.

GridGeometry2D 
toCanonical()
Returns a "canonical" representation of the grid geometry, that is, one whose grid range
originates in 0,0, but maps to the same real world coordinates.

GridCoordinates2D 
worldToGrid(DirectPosition point)
Transforms a point represented by a DirectPosition object from world to grid coordinates.

GridEnvelope2D 
worldToGrid(Envelope2D envelope)
Transforms a rectangle represented by an Envelope2D object from world to grid coordinates.

static GridGeometry2D 
wrap(GridGeometry other)
Returns the given grid geometry as a
GridGeometry2D . 
getCoordinateReferenceSystem, getDimension, getEnvelope, getGridRange, getGridToCRS, getGridToCRS, isDefined, toString
public final int gridDimensionX
gridDimensionX
) and row (gridDimensionY
) ordinates in a
grid point. They are the index of the first two dimensions with a span greater than 1 in the grid range. Their
values are usually 0 and 1 respectively.
It is garanteed that gridDimensionX
< gridDimensionY
.
public final int gridDimensionY
gridDimensionX
) and row (gridDimensionY
) ordinates in a
grid point. They are the index of the first two dimensions with a span greater than 1 in the grid range. Their
values are usually 0 and 1 respectively.
It is garanteed that gridDimensionX
< gridDimensionY
.
public final int axisDimensionX
gridDimensionX
, gridDimensionY
) dimensions in the envelope space. They
are index of (x, y) ordinates in a direct position after the
grid to CRS transform.
There is no garantee that gridDimensionX
maps to axisDimensionX
and
gridDimensionY
maps to axisDimensionY
, since axis may be interchanged.
It is garanteed that axisDimensionX
< axisDimensionY
.
public final int axisDimensionY
gridDimensionX
, gridDimensionY
) dimensions in the envelope space. They
are index of (x, y) ordinates in a direct position after the
grid to CRS transform.
There is no garantee that gridDimensionX
maps to axisDimensionX
and
gridDimensionY
maps to axisDimensionY
, since axis may be interchanged.
It is garanteed that axisDimensionX
< axisDimensionY
.
public GridGeometry2D(GridGeometry other)
GridGeometry2D
.other
 The other grid geometry to copy.wrap(org.opengis.coverage.grid.GridGeometry)
public GridGeometry2D(GridEnvelope gridRange, MathTransform gridToCRS, CoordinateReferenceSystem crs) throws IllegalArgumentException, MismatchedDimensionException
gridRange
 The valid coordinate range of a grid coverage, or null
if none. The
lowest valid grid coordinate is zero for BufferedImage
, but may be
nonzero for arbitrary RenderedImage
. A grid with 512 cells can
have a minimum coordinate of 0 and maximum of 512, with 511 as the highest valid index.gridToCRS
 The math transform which allows for the transformations from grid
coordinates (pixel's center) to real world earth coordinates.crs
 The coordinate reference system for the "real world" coordinates, or null
if unknown. This CRS is given to the envelope.MismatchedDimensionException
 if the math transform and the CRS don't have consistent
dimensions.IllegalArgumentException
 if gridRange
has more than 2 dimensions with a
span larger than 1, or if the math transform can't
transform coordinates in the domain of the specified grid range.public GridGeometry2D(GridEnvelope gridRange, PixelInCell anchor, MathTransform gridToCRS, CoordinateReferenceSystem crs, Hints hints) throws MismatchedDimensionException, IllegalArgumentException
GridGeometry2D(gridRange, gridToCRS, crs)
with the addition of an explicit anchor and
an optional set of hints giving more control on the MathTransform2D
to be inferred
from the ndimensional transform.
The anchor
argument tells whatever the gridToCRS
transform maps
cell center (OGC convention) or cell corner (Java2D/JAI convention). At the opposite of the
constructor expecting a PixelOrientation
argument, the translation (if any) applies
to every dimensions, not just the ones mapping the 2D part.
gridRange
 The valid coordinate range of a grid coverage, or null
if none.anchor
 Whatever the gridToCRS
transform maps cell center (OGC convention) or cell corner (Java2D/JAI convention).gridToCRS
 The math transform which allows for the transformations from grid
coordinates to real world earth coordinates.crs
 The coordinate reference system for the "real world" coordinates, or null
if unknown. This CRS is given to the envelope.hints
 An optional set of hints controlling the DimensionFilter
to be used for
deriving the MathTransform2D
instance from the given gridToCRS
transform.MismatchedDimensionException
 if the math transform and the CRS don't have consistent
dimensions.IllegalArgumentException
 if the math transform can't transform coordinates in the
domain of the specified grid range.public GridGeometry2D(GridEnvelope gridRange, PixelOrientation anchor, MathTransform gridToCRS, CoordinateReferenceSystem crs, Hints hints) throws IllegalArgumentException, MismatchedDimensionException
GridGeometry2D(gridRange, gridToCRS, crs)
with the addition of an explicit anchor and
an optional set of hints giving more control on the MathTransform2D
to be inferred
from the ndimensional transform.
The anchor
argument tells whatever the gridToCRS
transform maps pixel
center or some corner. Use CENTER
for OGC conventions or
UPPER_LEFT
for Java2D/JAI conventions. A translation (if
needed) is applied only on the gridDimensionX
and gridDimensionY
parts of
the transform  all other dimensions are assumed mapping pixel center.
gridRange
 The valid coordinate range of a grid coverage, or null
if none.anchor
 Whatever the twodimensional part of the gridToCRS
transform maps pixel
center or some corner.gridToCRS
 The math transform from grid coordinates to real world earth coordinates.crs
 The coordinate reference system for the "real world" coordinates, or null
if unknown.hints
 An optional set of hints controlling the DimensionFilter
to be used for
deriving the MathTransform2D
instance from the given gridToCRS
transform.MismatchedDimensionException
 if the math transform and the CRS don't have consistent
dimensions.IllegalArgumentException
 if gridRange
has more than 2 dimensions with a
span larger than 1, or if the math transform can't
transform coordinates in the domain of the specified grid range.public GridGeometry2D(PixelInCell anchor, MathTransform gridToCRS, Envelope envelope, Hints hints) throws MismatchedDimensionException, IllegalArgumentException
anchor
argument.anchor
 CELL_CENTER
for OGC conventions or CELL_CORNER
for Java2D/JAI conventions.gridToCRS
 The math transform which allows for the transformations from grid
coordinates to real world earth coordinates. May be null
, but this is not
recommended.envelope
 The envelope (including CRS) of a grid coverage, or null
if none.hints
 An optional set of hints controlling the DimensionFilter
to be used for
deriving the MathTransform2D
instance from the given gridToCRS
transform.MismatchedDimensionException
 if the math transform and the envelope doesn't have
consistent dimensions.IllegalArgumentException
 if the math transform can't transform coordinates in the
domain of the grid range.public GridGeometry2D(GridEnvelope gridRange, Envelope userRange) throws IllegalArgumentException, MismatchedDimensionException
gridRange
 The valid coordinate range of a grid coverage.userRange
 The corresponding coordinate range in user coordinate.IllegalArgumentException
 if gridRange
has more than 2 dimensions with a
length larger than 1.MismatchedDimensionException
 if the grid range and the CRS doesn't have consistent
dimensions.public GridGeometry2D(Rectangle gridRange, Rectangle2D userRange)
gridRange
and userRange
are assumed to have y axis in opposite direction).gridRange
 The valid coordinate range of a grid coverage. Increasing x
values goes right and increasing y values goes down.userRange
 The corresponding coordinate range in user coordinate. Increasing
x values goes right and increasing y values goes
up. This rectangle must contains entirely all pixels, i.e. the
rectangle's upper left corner must coincide with the upper left corner of the first pixel
and the rectangle's lower right corner must coincide with the lower right corner of the
last pixel.public static GridGeometry2D wrap(GridGeometry other)
GridGeometry2D
. If the given object is already
an instance of GridGeometry2D
, then it is returned unchanged. Otherwise a new GridGeometry2D
instance is created using the copy
constructor.other
 The grid geometry to wrap.null
if other
was null.public Envelope2D reduce(Envelope envelope)
axisDimensionX
, axisDimensionY
) index.
The coordinate reference system
of the
source envelope is ignored. The coordinate reference system of the target envelope will be
getCoordinateReferenceSystem2D()
or null
.
envelope
 The envelope to reduce, or null
. This envelope will not be modified.null
if envelope
was null.
The returned envelope is always a new instance, so it can be modified safely.public CoordinateReferenceSystem reduce(CoordinateReferenceSystem crs) throws FactoryException
axisDimensionX
, axisDimensionY
) index.crs
 The coordinate reference system to reduce, or null
.null
if
crs
was null.FactoryException
 if the given CRS can't be reduced to two dimensions.public CoordinateReferenceSystem getCoordinateReferenceSystem2D() throws InvalidGridGeometryException
axisDimensionX
, axisDimensionY
)
axis. Note that those axis are garanteed to appears in the same order than in the complete
CRS.null
).InvalidGridGeometryException
 if this grid geometry has no CRS (i.e.
isDefined(CRS)
returned false
).GeneralGridGeometry.getCoordinateReferenceSystem()
public Envelope2D getEnvelope2D() throws InvalidGridGeometryException
null
).InvalidGridGeometryException
 if this grid geometry has no envelope (i.e.
isDefined(ENVELOPE_BITMASK)
returned false
).GeneralGridGeometry.getEnvelope()
public GridEnvelope2D getGridRange2D() throws InvalidGridGeometryException
Rectangle
subclass.null
).InvalidGridGeometryException
 if this grid geometry has no grid range (i.e.
isDefined(GRID_RANGE_BITMASK)
returned false
).GeneralGridGeometry.getGridRange()
public MathTransform2D getGridToCRS2D() throws InvalidGridGeometryException
AffineTransform
, which make it convenient for
interoperability with Java2D.InvalidGridGeometryException
 if a twodimensional transform is not available for this
grid geometry.getGridToCRS(org.opengis.metadata.spatial.PixelOrientation)
public MathTransform2D getCRSToGrid2D() throws InvalidGridGeometryException
AffineTransform
, which makes it convenient for interoperability with
Java2D.InvalidGridGeometryException
 if a twodimensional transform is not available for this
grid geometry.getGridToCRS(org.opengis.metadata.spatial.PixelOrientation)
public MathTransform2D getGridToCRS2D(PixelOrientation orientation)
getGridToCRS2D()
except that the transform may maps a pixel corner instead of pixel center.orientation
 The pixel part to map. The default value is CENTER
.InvalidGridGeometryException
 if a twodimensional transform is not available for this
grid geometry.public MathTransform2D getCRSToGrid2D(PixelOrientation orientation)
getCRSToGrid2D()
except that the transform may map a pixel corner instead of pixel center.orientation
 The pixel part to map. The default value is CENTER
.InvalidGridGeometryException
 if a twodimensional transform is not available for this
grid geometry.public MathTransform getGridToCRS(PixelOrientation orientation)
gridDimensionX
and gridDimensionY
parts of the transform;
all other dimensions are assumed mapping pixel center. For applying a translation on all
dimensions, use GeneralGridGeometry.getGridToCRS(PixelInCell)
instead.orientation
 The pixel part to map. The default value is CENTER
.InvalidGridGeometryException
 if a transform is not available for this grid geometry.public final GridCoordinates2D worldToGrid(DirectPosition point) throws InvalidGridGeometryException, TransformException
CoordinateReferenceSystem
, and it differs from that of the
coverage, it will be reprojected on the fly. The the nearest grid cell centre to the input
point is found.
Users needing more control over the nature of the conversion can access the MathsTransform provided by getCRSToGrid2D(PixelOrientation) which is accessed via #getGridGeometry().
point
 The point in world coordinate system.InvalidGridGeometryException
 if a twodimensional inverse transform is not available.TransformException
 if the transformation failed.public final GridEnvelope2D worldToGrid(Envelope2D envelope) throws TransformException, InvalidGridGeometryException
CoordinateReferenceSystem
, it must be the same as that
of this coverage, otherwise an exception is thrown.
The GridEnvelope2D
returned contains the range of cells whose centers lie inside
the input Envelope2D
Users needing more control over the nature of the conversion can access the MathsTransform provided by getCRSToGrid2D(PixelOrientation) which is accessed via #getGridGeometry().
env
 The envelope in world coordinate system.GridEnvelope2D
objectIllegalArgumentException
 if the coordinate reference system of the envelope is not
null
and does not match that of the coverageInvalidGridGeometryException
 if a twodimensional inverse transform is not available
for this grid geometry.TransformException
 if the transformation failed.public final DirectPosition gridToWorld(GridCoordinates2D point) throws TransformException
Users needing more control over the nature of the conversion (e.g. calculating cell corner
coordinates) can use the MathsTransform
provided by getGridToCRS2D(PixelOrientation) which is accessed via #getGridGeometry().
point
 The point in world coordinate system.TransformException
 if the transformation failed.IllegalArgumentException
 if the point lies outside the coveragepublic final Envelope2D gridToWorld(GridEnvelope2D gridEnv) throws TransformException
Users needing more control over the nature of the conversion can use the MathsTransform
provided by getGridToCRS2D(PixelOrientation)
which is accessed via #getGridGeometry().
gridEnv
 The rectangle of grid coordinates to convertTransformException
 if the transformation failed.IllegalArgumentException
 if the input rectangle lies outside the coveragepublic boolean equals(Object object)
equals
in class GeneralGridGeometry
object
 The object to compare with.true
if the given object is equals to this grid geometry.public int hashCode()
GeneralGridGeometry
hashCode
in class GeneralGridGeometry
public GridGeometry2D toCanonical()
Copyright © 1996–2019 Geotools. All rights reserved.