Package org.hortonmachine.modules
Class Raster
- java.lang.Object
-
- org.hortonmachine.modules.Raster
-
public class Raster extends Object
A simple raster wrapper for scripting environment.- Author:
- Andrea Antonello (www.hydrologis.com)
-
-
Constructor Summary
Constructors Constructor Description Raster(int cols, int rows, double res, double ulEasting, double ulNorthing, String epsg)Create a new raster based on the region properties.Raster(org.geotools.coverage.grid.GridCoverage2D raster)Create a raster for reading purposes.Raster(org.geotools.coverage.grid.GridCoverage2D raster, boolean makeNew)Create a new raster using a given raster as template.Raster(Raster raster)Create a new raster using a given raster as template.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.geotools.coverage.grid.GridCoverage2DbuildRaster()Creates aGridCoverage2Dfrom theRaster.intgetCols()org.opengis.referencing.crs.CoordinateReferenceSystemgetCrs()doublegetEast()org.geotools.coverage.grid.GridGeometry2DgetGridGeometry()doublegetNorth()doublegetRes()intgetRows()doublegetSouth()doublegetWest()doublegetxRes()doublegetyRes()int[]gridAt(double x, double y)Get grid col and row from a world coordinate.booleanisNoValue(double value)doublenovalue()double[]positionAt(int col, int row)Get world position from col, row.static Rasterread(String path)Read a raster from file.voidsetValueAt(int col, int row, double value)Sets a raster value if the raster is writable.double[]surrounding(int col, int row)Get the values of the surrounding cells.doublevalueAt(int col, int row)Get the raster value at a given col/row.static booleanvaluesEqual(double value1, double value2)voidwrite(String path)Write the raster to file.
-
-
-
Constructor Detail
-
Raster
public Raster(org.geotools.coverage.grid.GridCoverage2D raster)
Create a raster for reading purposes.- Parameters:
raster- the raster to access.
-
Raster
public Raster(org.geotools.coverage.grid.GridCoverage2D raster, boolean makeNew)Create a new raster using a given raster as template.- Parameters:
coverage-makeNew-
-
Raster
public Raster(Raster raster)
Create a new raster using a given raster as template.- Parameters:
raster- the raster to copy the properties from.
-
Raster
public Raster(int cols, int rows, double res, double ulEasting, double ulNorthing, String epsg)Create a new raster based on the region properties.- Parameters:
cols-rows-res-ulEasting-ulNorthing-epsg-
-
-
Method Detail
-
getRows
public int getRows()
-
getCols
public int getCols()
-
getNorth
public double getNorth()
-
getSouth
public double getSouth()
-
getWest
public double getWest()
-
getEast
public double getEast()
-
getxRes
public double getxRes()
-
getyRes
public double getyRes()
-
getRes
public double getRes()
-
getCrs
public org.opengis.referencing.crs.CoordinateReferenceSystem getCrs()
-
valueAt
public double valueAt(int col, int row)Get the raster value at a given col/row.- Parameters:
col-row-- Returns:
- the value.
-
positionAt
public double[] positionAt(int col, int row)Get world position from col, row.- Parameters:
col-row-- Returns:
- the [x, y] position or
nullif outside the bounds.
-
gridAt
public int[] gridAt(double x, double y)Get grid col and row from a world coordinate.- Parameters:
x-y-- Returns:
- the [col, row] or
nullif the position is outside the bounds.
-
setValueAt
public void setValueAt(int col, int row, double value)Sets a raster value if the raster is writable.- Parameters:
col-row-value-
-
surrounding
public double[] surrounding(int col, int row)Get the values of the surrounding cells. The order of the values is [E, EN, N, NW, W, WS, S, SE].- Parameters:
col- the col of the center cell.row- the row of the center cell.- Returns:
- the array of cell values around them as [E, EN, N, NW, W, WS, S, SE].
-
isNoValue
public boolean isNoValue(double value)
-
novalue
public double novalue()
-
valuesEqual
public static boolean valuesEqual(double value1, double value2)
-
getGridGeometry
public org.geotools.coverage.grid.GridGeometry2D getGridGeometry()
-
buildRaster
public org.geotools.coverage.grid.GridCoverage2D buildRaster()
Creates aGridCoverage2Dfrom theRaster.- Returns:
- the coverage.
-
write
public void write(String path) throws Exception
Write the raster to file.- Parameters:
path- th epath to write to.- Throws:
Exception
-
-