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

    Modifier and Type
    Method
    Description
    org.geotools.coverage.grid.GridCoverage2D
    Creates a GridCoverage2D from the Raster.
    int
     
    org.opengis.referencing.crs.CoordinateReferenceSystem
     
    double
     
    org.geotools.coverage.grid.GridGeometry2D
     
    double
     
    double
     
    int
     
    double
     
    double
     
    double
     
    double
     
    int[]
    gridAt(double x, double y)
    Get grid col and row from a world coordinate.
    boolean
    isNoValue(double value)
     
    double
     
    double[]
    positionAt(int col, int row)
    Get world position from col, row.
    static Raster
    read(String path)
    Read a raster from file.
    void
    setValueAt(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.
    double
    valueAt(int col, int row)
    Get the raster value at a given col/row.
    static boolean
    valuesEqual(double value1, double value2)
     
    void
    write(String path)
    Write the raster to file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • 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 Details

    • 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 null if 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 null if 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 a GridCoverage2D from the Raster.
      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
    • read

      public static Raster read(String path) throws Exception
      Read a raster from file.
      Parameters:
      path - the path to the raster to read.
      Returns:
      the read raster in readonly mode.
      Throws:
      Exception