Package org.geotools.gce.grassraster
Class JGrassUtilities
- Object
-
- JGrassUtilities
-
public class JGrassUtilities extends Object
A facade of often used methods by the JGrass engine- Since:
- 1.1.0
- Author:
- Andrea Antonello - www.hydrologis.com
-
-
Constructor Summary
Constructors Constructor Description JGrassUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static GridCoverage2D
buildCoverage(String name, double[][] dataMatrix, double n, double s, double w, double e, CoordinateReferenceSystem crs, boolean matrixIsRowCol)
Creates acoverage
from a double[][] matrix and the necessary geographic Information.static BufferedImage
ByteBufferImage(byte[] data, int width, int height)
create a buffered image from a set of color tripletsstatic boolean
checkRasterMapConsistence(String mapsetPath, String mapname)
Returns the list of files involved in the raster map issues.static int[]
coordinateToNearestRowCol(JGrassRegion active, Coordinate coord)
Return the row and column of the active region matrix for a give coordinate *static WritableRaster
createDoubleWritableRaster(int width, int height, Class<?> dataClass, SampleModel sampleModel, Double value)
Creates awritable raster
.static WritableRaster
createWritableRasterFromMatrix(double[][] matrix, boolean matrixIsRowCol)
Create aWritableRaster
from a double matrix.static int
factorial(int n)
static String[]
filesOfRasterMap(String mapsetPath, String mapname)
Returns the list of files involved in the raster map issues.static JGrassRegion
getJGrassRegionFromGridCoverage(GridCoverage2D gridCoverage2D)
static JGrassRegion
getRectangleAroundPoint(JGrassRegion activeRegion, double x, double y)
return the rectangle of the cell of the active region, that surrounds the given coordinatesstatic int[]
getTilesBasedOnFreeMemory(int rows, int cols)
Calculates optimal tile size for the actual free memory.static boolean
isGrass(String path)
Checks if the given path is a GRASS raster file.static void
makeColorRulesPersistent(File colrFile, List<String> rules, double[] minMax, int alpha)
static void
printImage(RenderedImage renderedImage)
static void
printImage(GridCoverage2D coverage2D)
static Envelope
reprojectEnvelopeByEpsg(int srcEpsg, int destEpsg, Envelope srcEnvelope)
static Coordinate
rowColToCenterCoordinates(JGrassRegion active, int row, int col)
Transforms row and column index of the active region into the regarding northing and easting coordinates.static double[]
rowColToNodeboundCoordinates(JGrassRegion active, int row, int col)
Transforms row and column index of the active region into an array of the coordinates of the edgaes, i.e. n, s, e, wstatic RenderedImage
scaleJAIImage(int requestedCols, int requestedRows, RenderedImage translatedImage, Interpolation interpolation)
-
-
-
Field Detail
-
NORTH
public static final String NORTH
- See Also:
- Constant Field Values
-
SOUTH
public static final String SOUTH
- See Also:
- Constant Field Values
-
WEST
public static final String WEST
- See Also:
- Constant Field Values
-
EAST
public static final String EAST
- See Also:
- Constant Field Values
-
XRES
public static final String XRES
- See Also:
- Constant Field Values
-
YRES
public static final String YRES
- See Also:
- Constant Field Values
-
ROWS
public static final String ROWS
- See Also:
- Constant Field Values
-
COLS
public static final String COLS
- See Also:
- Constant Field Values
-
interpolation
public static Interpolation interpolation
-
-
Method Detail
-
checkRasterMapConsistence
public static boolean checkRasterMapConsistence(String mapsetPath, String mapname)
Returns the list of files involved in the raster map issues. If for example a map has to be deleted, then all these files have to.- Parameters:
mapsetPath
- - the path of the mapsetmapname
- -the name of the map- Returns:
- the array of strings containing the full path to the involved files
-
ByteBufferImage
public static BufferedImage ByteBufferImage(byte[] data, int width, int height)
create a buffered image from a set of color triplets
-
reprojectEnvelopeByEpsg
public static Envelope reprojectEnvelopeByEpsg(int srcEpsg, int destEpsg, Envelope srcEnvelope) throws FactoryException, TransformException
- Throws:
FactoryException
TransformException
-
getRectangleAroundPoint
public static JGrassRegion getRectangleAroundPoint(JGrassRegion activeRegion, double x, double y)
return the rectangle of the cell of the active region, that surrounds the given coordinates- Parameters:
x
- the given easting coordinatey
- given northing coordinate- Returns:
- the rectangle localizing the cell inside which the x and y stay
-
rowColToCenterCoordinates
public static Coordinate rowColToCenterCoordinates(JGrassRegion active, int row, int col)
Transforms row and column index of the active region into the regarding northing and easting coordinates. The center of the cell is taken.NOTE: basically the inverse of
coordinateToNearestRowCol(JGrassRegion, Coordinate)
- Parameters:
active
- - the active region (can be null)row
- - row number of the point to transformcol
- - column number of the point to transform- Returns:
- the point in N/E coordinates of the supplied row and column
-
coordinateToNearestRowCol
public static int[] coordinateToNearestRowCol(JGrassRegion active, Coordinate coord)
Return the row and column of the active region matrix for a give coordinate *NOTE: basically the inverse of
rowColToCenterCoordinates(JGrassRegion, int, int)
- Parameters:
active
- the active region- Returns:
- and int array containing row and col
-
filesOfRasterMap
public static String[] filesOfRasterMap(String mapsetPath, String mapname)
Returns the list of files involved in the raster map issues. If for example a map has to be deleted, then all these files have to.- Parameters:
mapsetPath
- - the path of the mapsetmapname
- -the name of the map- Returns:
- the array of strings containing the full path to the involved files
-
rowColToNodeboundCoordinates
public static double[] rowColToNodeboundCoordinates(JGrassRegion active, int row, int col)
Transforms row and column index of the active region into an array of the coordinates of the edgaes, i.e. n, s, e, w- Parameters:
active
- - the active region (can be null)row
- - row number of the point to transformcol
- - column number of the point to transform- Returns:
- the array of north, south, east, west
-
factorial
public static int factorial(int n)
-
makeColorRulesPersistent
public static void makeColorRulesPersistent(File colrFile, List<String> rules, double[] minMax, int alpha) throws IOException
- Throws:
IOException
-
getTilesBasedOnFreeMemory
public static int[] getTilesBasedOnFreeMemory(int rows, int cols)
Calculates optimal tile size for the actual free memory.- Parameters:
rows
- the rows of the complete image the tiles are calculated for.cols
- the cols of the complete image the tiles are calculated for.
-
getJGrassRegionFromGridCoverage
public static JGrassRegion getJGrassRegionFromGridCoverage(GridCoverage2D gridCoverage2D) throws InvalidGridGeometryException, TransformException
-
scaleJAIImage
public static RenderedImage scaleJAIImage(int requestedCols, int requestedRows, RenderedImage translatedImage, Interpolation interpolation)
-
buildCoverage
public static GridCoverage2D buildCoverage(String name, double[][] dataMatrix, double n, double s, double w, double e, CoordinateReferenceSystem crs, boolean matrixIsRowCol)
Creates acoverage
from a double[][] matrix and the necessary geographic Information.- Parameters:
name
- the name of the coverage.dataMatrix
- the matrix containing the data.crs
- theCoordinateReferenceSystem
.matrixIsRowCol
- a flag to tell if the matrix has rowCol or colRow order.- Returns:
- the
coverage
.
-
createWritableRasterFromMatrix
public static WritableRaster createWritableRasterFromMatrix(double[][] matrix, boolean matrixIsRowCol)
Create aWritableRaster
from a double matrix.- Parameters:
matrix
- the matrix to take the data from.matrixIsRowCol
- a flag to tell if the matrix has rowCol or colRow order.- Returns:
- the produced raster.
-
createDoubleWritableRaster
public static WritableRaster createDoubleWritableRaster(int width, int height, Class<?> dataClass, SampleModel sampleModel, Double value)
Creates awritable raster
.- Parameters:
width
- width of the raster to create.height
- height of the raster to create.dataClass
- data type for the raster. Ifnull
, defaults to double.sampleModel
- the samplemodel to use. Ifnull
, defaults tonew ComponentSampleModel(dataType, width, height, 1, width, new int[]{0});
.value
- value to which to set the raster to. If null, the default of the raster creation is used, which is 0.- Returns:
- a
writable raster
.
-
isGrass
public static boolean isGrass(String path)
Checks if the given path is a GRASS raster file.Note that there is no check on the existence of the file.
- Parameters:
path
- the path to check.- Returns:
- true if the file is a grass raster.
-
printImage
public static void printImage(GridCoverage2D coverage2D)
-
printImage
public static void printImage(RenderedImage renderedImage)
-
-