org.geotools.coverage.grid
Class GeneralGridRange

java.lang.Object
  extended byorg.geotools.coverage.grid.GeneralGridRange
All Implemented Interfaces:
org.opengis.coverage.grid.GridRange, java.io.Serializable

public class GeneralGridRange
extends java.lang.Object
implements org.opengis.coverage.grid.GridRange, java.io.Serializable

Defines a range of grid coverage coordinates.

Since:
2.1
Version:
$Id: GeneralGridRange.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Serialized Form

Constructor Summary
GeneralGridRange(org.opengis.spatialschema.geometry.Envelope envelope)
          Cast the specified envelope into a grid range.
GeneralGridRange(int[] lower, int[] upper)
          Constructs a new grid range.
GeneralGridRange(int lower, int upper)
          Constructs one-dimensional grid range.
GeneralGridRange(java.awt.image.Raster raster)
          Constructs two-dimensional range defined by a Raster.
GeneralGridRange(java.awt.Rectangle rect)
          Constructs two-dimensional range defined by a Rectangle.
GeneralGridRange(java.awt.image.RenderedImage image)
          Constructs two-dimensional range defined by a RenderedImage.
 
Method Summary
 boolean equals(java.lang.Object object)
          Compares the specified object with this grid range for equality.
 int getDimension()
          Returns the number of dimensions.
 int getLength(int dimension)
          Returns the number of integer grid coordinates along the specified dimension.
 int getLower(int dimension)
          Returns the valid minimum inclusive grid coordinate along the specified dimension.
 int[] getLowers()
          Returns the valid minimum inclusive grid coordinates along all dimensions.
 GeneralGridRange getSubGridRange(int lower, int upper)
          Returns a new grid range that encompass only some dimensions of this grid range.
 int getUpper(int dimension)
          Returns the valid maximum exclusive grid coordinate along the specified dimension.
 int[] getUppers()
          Returns the valid maximum exclusive grid coordinates along all dimensions.
 int hashCode()
          Returns a hash value for this grid range.
 java.awt.Rectangle toRectangle()
          Returns a Rectangle with the same bounds as this .
 java.lang.String toString()
          Returns a string repr?sentation of this grid range.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeneralGridRange

public GeneralGridRange(int lower,
                        int upper)
Constructs one-dimensional grid range.

Parameters:
lower - The minimal inclusive value.
upper - The maximal exclusive value.

GeneralGridRange

public GeneralGridRange(int[] lower,
                        int[] upper)
Constructs a new grid range.

Parameters:
lower - The valid minimum inclusive grid coordinate. The array contains a minimum value for each dimension of the grid coverage. The lowest valid grid coordinate is zero.
upper - The valid maximum exclusive grid coordinate. The array contains a maximum value for each dimension of the grid coverage.
See Also:
getLowers(), getUppers()

GeneralGridRange

public GeneralGridRange(java.awt.Rectangle rect)
Constructs two-dimensional range defined by a Rectangle.


GeneralGridRange

public GeneralGridRange(java.awt.image.Raster raster)
Constructs two-dimensional range defined by a Raster.


GeneralGridRange

public GeneralGridRange(java.awt.image.RenderedImage image)
Constructs two-dimensional range defined by a RenderedImage.


GeneralGridRange

public GeneralGridRange(org.opengis.spatialschema.geometry.Envelope envelope)
Cast the specified envelope into a grid range. This is sometime useful after an envelope has been transformed from "real world" coordinates to grid coordinates using the "grid to CRS" transform. The floating point values are rounded toward the nearest integers.

Note about rounding mode:
It would have been possible to round the minimal value toward floor and the maximal value toward ceil in order to make sure that the grid range encompass all the envelope (something similar to what Java2D does when casting Rectangle2D to Rectangle). But this approach has an undesirable side effect: it may changes the image width or height. For example the range would be casted to , which leads to unexpected result when using grid range with image operations like "Affine". For avoiding such changes in size, it is necessary to use the same rounding mode for both minimal and maximal values. The selected rounding mode is nearest integer in this implementation.

Since:
2.2
Method Detail

getDimension

public int getDimension()
Returns the number of dimensions.

Specified by:
getDimension in interface org.opengis.coverage.grid.GridRange

getLower

public int getLower(int dimension)
Returns the valid minimum inclusive grid coordinate along the specified dimension.

Specified by:
getLower in interface org.opengis.coverage.grid.GridRange
See Also:
getLowers()

getUpper

public int getUpper(int dimension)
Returns the valid maximum exclusive grid coordinate along the specified dimension.

Specified by:
getUpper in interface org.opengis.coverage.grid.GridRange
See Also:
getUppers()

getLength

public int getLength(int dimension)
Returns the number of integer grid coordinates along the specified dimension. This is equals to .

Specified by:
getLength in interface org.opengis.coverage.grid.GridRange

getLowers

public int[] getLowers()
Returns the valid minimum inclusive grid coordinates along all dimensions.

Specified by:
getLowers in interface org.opengis.coverage.grid.GridRange

getUppers

public int[] getUppers()
Returns the valid maximum exclusive grid coordinates along all dimensions.

Specified by:
getUppers in interface org.opengis.coverage.grid.GridRange

getSubGridRange

public GeneralGridRange getSubGridRange(int lower,
                                        int upper)
Returns a new grid range that encompass only some dimensions of this grid range. This method copy this grid range's index into a new grid range, beginning at dimension and extending to dimension . Thus the dimension of the subgrid range is .

Parameters:
lower - The first dimension to copy, inclusive.
upper - The last dimension to copy, exclusive.
Returns:
The subgrid range.
Throws:
java.lang.IndexOutOfBoundsException - if an index is out of bounds.

toRectangle

public java.awt.Rectangle toRectangle()
                               throws java.lang.IllegalStateException
Returns a Rectangle with the same bounds as this . This is a convenience method for interoperability with Java2D.

Throws:
java.lang.IllegalStateException - if this grid range is not two-dimensional.

hashCode

public int hashCode()
Returns a hash value for this grid range. This value need not remain consistent between different implementations of the same class.


equals

public boolean equals(java.lang.Object object)
Compares the specified object with this grid range for equality.


toString

public java.lang.String toString()
Returns a string repr?sentation of this grid range. The returned string is implementation dependent. It is usually provided for debugging purposes.



Copyright © GeoTools. All Rights Reserved.