Class GridExtent
- java.lang.Object
-
- org.openjump.core.rasterimage.sextante.rasterWrappers.GridExtent
-
public class GridExtent extends Object
This class defines a grid system (coordinates and cellsize)- Author:
- Victor Olaya
-
-
Constructor Summary
Constructors Constructor Description GridExtent()
GridExtent(ISextanteLayer 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addExtent(GridExtent extent)
Modifies this extent to incorporate another one into its boundariesboolean
contains(double x, double y)
Returns true if the given point falls within the area covered by this extentboolean
containsCell(int x, int y)
Returns true if the cell is within the limits of this grid extentvoid
enlargeOneCell()
Enlarges this grid extent one cell in each directionboolean
equals(GridExtent extent)
Returns true if this extent has them same characteristics as a given oneboolean
fitsIn(GridExtent extent)
Returns true if the given extents matches the grid defined by this grid extent (has same size and cell boundaries match)Rectangle2D
getAsRectangle2D()
Returns this extent as a Java Rectangle2DPoint2D.Double
getCellSize()
Returns the cellsize of this extentorg.locationtech.jts.geom.Envelope
getEnvelope()
Returns the extension of Grid as org.locationtech.jts.geom.EnvelopeGridCell
getGridCoordsFromWorldCoords(double x, double y)
Converts a world coordinate to grid coordinatesGridCell
getGridCoordsFromWorldCoords(Point2D pt)
Converts a world coordinate to grid coordinatesPoint
getGridCoordsFromWorldCoords(org.locationtech.jts.geom.Coordinate coordinate)
Convert World coordinates to grid coordinatesdouble
getHeight()
Returns the real Y distance spanned by this extentint
getNX()
Returns the number of columns in the extentint
getNY()
Returns the number of rows in the extentWritableRaster
getRaster()
double
getWidth()
Returns the real X distance spanned by this extentPoint2D
getWorldCoordsFromGridCoords(int x, int y)
Converts a grid cell into a world coordinate representing the center of that cellPoint2D
getWorldCoordsFromGridCoords(GridCell cell)
/** Converts a grid cell into a world coordinate representing the center of that celldouble
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 cellSizeX, double cellSizeY)
void
setValuesAndRaster(double cellSizeX, double cellSizeY, org.locationtech.jts.geom.Envelope envelope, double nodata)
Method to build a GridExtent with a defined Rastervoid
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.String
toString()
-
-
-
Constructor Detail
-
GridExtent
public GridExtent()
-
GridExtent
public GridExtent(ISextanteLayer 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. Note, the CellSize needs to be set first before this method is used.- 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. Note, the CellSize needs to be set first before this method is used.- Parameters:
dYMin
- the minimum Y coordinate of the extent.dYMax
- the maximum Y coordinate of the extent
-
getCellSize
public Point2D.Double getCellSize()
Returns the cellsize of this extent- Returns:
- the cells size of this extent
-
setCellSize
public void setCellSize(double cellSizeX, double cellSizeY)
-
setValuesAndRaster
public void setValuesAndRaster(double cellSizeX, double cellSizeY, org.locationtech.jts.geom.Envelope envelope, double nodata)
Method to build a GridExtent with a defined Raster- Parameters:
cellSizeX
- cell size along XcellSizeY
- cell size along Yenvelope
- envelope of this GridExtentnodata
- nodata value
-
getRaster
public WritableRaster getRaster()
-
getEnvelope
public org.locationtech.jts.geom.Envelope getEnvelope()
Returns the extension of Grid as org.locationtech.jts.geom.Envelope- Returns:
- Envelope
-
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 pointy
- 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
- another gridExtent to compare this gridExtent to- 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
- another gridExtent to compare this gridExtent to- 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(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 pointy
- the y coordinate of the point- Returns:
- a grid cell representing the given point in grid coordinates referred to this grid extent
-
getWorldCoordsFromGridCoords
public 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 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 celly
- the y coordinate (row) of the cell- Returns:
- a point representing the given cell in world coordinates
-
getGridCoordsFromWorldCoords
public Point getGridCoordsFromWorldCoords(org.locationtech.jts.geom.Coordinate coordinate)
Convert World coordinates to grid coordinates- Parameters:
coordinate
- the model Coordinate to convert to image Coordinate- Returns:
- java.awt.Point
-
enlargeOneCell
public void enlargeOneCell()
Enlarges this grid extent one cell in each direction
-
getAsRectangle2D
public 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 celly
- the y coordinate (row) of the cell- Returns:
- whether the cell is within the limits of this grid extent
-
-