es.unex.sextante.rasterWrappers
Class GridExtent

java.lang.Object
  extended by es.unex.sextante.rasterWrappers.GridExtent

public class GridExtent
extends java.lang.Object

This class defines a grid system (coordinates and cellsize)

Author:
Victor Olaya

Constructor Summary
GridExtent()
           
GridExtent(ILayer layer)
          Creates a new grid extent using the extent of a layer If it is a raster layer, it will also use its cellsize
 
Method Summary
 void addExtent(GridExtent extent)
          Modifies this extent to incorporate another one into its boundaries
 boolean contains(double x, double y)
          Returns true if the given point falls within the area covered by this extent
 boolean containsCell(int x, int y)
          Returns true if the cell is within the limits of this grid extent
 void enlargeOneCell()
          Enlarges this grid extent one cell in each direction
 boolean equals(GridExtent extent)
          Returns true if this extent has them same characteristics as a given one
 boolean fitsIn(GridExtent extent)
          Returns true if the given extents matches the grid defined by this grid extent (has same size and cell boundaries match)
 java.awt.geom.Rectangle2D getAsRectangle2D()
          Returns this extent as a Java Rectangle2D
 double getCellSize()
          Returns the cellsize of this extent
 GridCell getGridCoordsFromWorldCoords(double x, double y)
          Converts a world coordinate to grid coordinates
 GridCell getGridCoordsFromWorldCoords(java.awt.geom.Point2D pt)
          Converts a world coordinate to grid coordinates
 double getHeight()
          Returns the real Y distance spanned by this extent
 int getNX()
          Returns the number of columns in the extent
 int getNY()
          Returns the number of rows in the extent
 double getWidth()
          Returns the real X distance spanned by this extent
 java.awt.geom.Point2D getWorldCoordsFromGridCoords(GridCell cell)
          /** Converts a grid cell into a world coordinate representing the center of that cell
 java.awt.geom.Point2D getWorldCoordsFromGridCoords(int x, int y)
          Converts a grid cell into a world coordinate representing the center of that cell
 double getXMax()
          Return the maximum x coordinate of the extent.
 double getXMin()
          Return the minimum x coordinate of the extent.
 double getYMax()
          Return the maximum y coordinate of the extent.
 double getYMin()
          Return the minimum x coordinateof the extent.
 void setCellSize(double cellSize)
          Sets a new cellsize for this extent
 void setXRange(double dXMin, double dXMax)
          Sets a new range for X coordinates.
 void setYRange(double dYMin, double dYMax)
          Sets a new range for Y coordinates.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GridExtent

public GridExtent()

GridExtent

public GridExtent(ILayer layer)
Creates a new grid extent using the extent of a layer If it is a raster layer, it will also use its cellsize

Parameters:
layer - a layer
Method Detail

setXRange

public void setXRange(double dXMin,
                      double dXMax)
Sets a new range for X coordinates. Coordinates are not center cell ones, but border ones

Parameters:
dXMin - the minimum x coordinate of the extent.
dXMax - the maximum x coordinate of the extent

setYRange

public void setYRange(double dYMin,
                      double dYMax)
Sets a new range for Y coordinates. Coordinates are not center cell ones, but border ones

Parameters:
dYMin - the minimum Y coordinate of the extent.
dYMax - the maximum Y coordinate of the extent

getCellSize

public double getCellSize()
Returns the cellsize of this extent

Returns:
the cells size of this extent

setCellSize

public void setCellSize(double cellSize)
Sets a new cellsize for this extent

Parameters:
cellSize - the new cellsize

getNX

public int getNX()
Returns the number of columns in the extent

Returns:
the number of columns

getNY

public int getNY()
Returns the number of rows in the extent

Returns:
the number of rows

getXMin

public double getXMin()
Return the minimum x coordinate of the extent. This is not the coordinate of the center of the left-most cell, but the the coordinate of its left border

Returns:
the minimum x coordinate of the extent

getXMax

public double getXMax()
Return the maximum x coordinate of the extent. This is not the coordinate of the center of the right-most cell, but the the coordinate of its right border

Returns:
the maximum x coordinate of the extent

getYMin

public double getYMin()
Return the minimum x coordinateof the extent. This is not the coordinate of the center of the lower cell, but the the coordinate of its lower border

Returns:
the minimum y coordinate of the extent

getYMax

public double getYMax()
Return the maximum y coordinate of the extent. This is not the coordinate of the center of the upper cell, but the the coordinate of its upper border

Returns:
the maximum x coordinate of the extent

getWidth

public double getWidth()
Returns the real X distance spanned by this extent

Returns:
the real X distance spanned by this extent

getHeight

public double getHeight()
Returns the real Y distance spanned by this extent

Returns:
the real Y distance spanned by this extent

contains

public boolean contains(double x,
                        double y)
Returns true if the given point falls within the area covered by this extent

Parameters:
x - the x coordinate of the point
y - the y coordinate of the point
Returns:
whether the given point falls within the area covered by this extent

fitsIn

public boolean fitsIn(GridExtent extent)
Returns true if the given extents matches the grid defined by this grid extent (has same size and cell boundaries match)

Parameters:
extent -
Returns:
whether the passed extent matches fits into this extent

equals

public boolean equals(GridExtent extent)
Returns true if this extent has them same characteristics as a given one

Parameters:
extent -
Returns:
whether this extent equals the given extent

addExtent

public void addExtent(GridExtent extent)
Modifies this extent to incorporate another one into its boundaries

Parameters:
extent - the extent to add

getGridCoordsFromWorldCoords

public GridCell getGridCoordsFromWorldCoords(java.awt.geom.Point2D pt)
Converts a world coordinate to grid coordinates

Parameters:
pt - a point in world coordinates
Returns:
a grid cell with coordinates of the given point in grid coordinates referred to this grid extent

getGridCoordsFromWorldCoords

public GridCell getGridCoordsFromWorldCoords(double x,
                                             double y)
Converts a world coordinate to grid coordinates

Parameters:
x - the x coordinate of the point
y - the y coordinate of the point
Returns:
a grid cell representing the given point in grid coordinates referred to this grid extent

getWorldCoordsFromGridCoords

public java.awt.geom.Point2D getWorldCoordsFromGridCoords(GridCell cell)
/** Converts a grid cell into a world coordinate representing the center of that cell

Parameters:
cell - the cell to convert
Returns:
a point representing the given cell in world coordinates

getWorldCoordsFromGridCoords

public java.awt.geom.Point2D getWorldCoordsFromGridCoords(int x,
                                                          int y)
Converts a grid cell into a world coordinate representing the center of that cell

Parameters:
x - the x coordinate (col) of the cell
y - the y coordinate (row) of the cell
Returns:
a point representing the given cell in world coordinates

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

enlargeOneCell

public void enlargeOneCell()
Enlarges this grid extent one cell in each direction


getAsRectangle2D

public java.awt.geom.Rectangle2D getAsRectangle2D()
Returns this extent as a Java Rectangle2D

Returns:
the extent of this grid extent as a Jave Rectangle2D

containsCell

public boolean containsCell(int x,
                            int y)
Returns true if the cell is within the limits of this grid extent

Parameters:
x - the x coordinate (col) of the cell
y - the y coordinate (row) of the cell
Returns:
whether the cell is within the limits of this grid extent