org.geotools.gce.grassraster
Class JGrassUtilities

Object
  extended by 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

Field Summary
static String COLS
           
static String EAST
           
static Interpolation interpolation
           
static String NORTH
           
static String ROWS
           
static String SOUTH
           
static String WEST
           
static String XRES
           
static String YRES
           
 
Constructor Summary
JGrassUtilities()
           
 
Method Summary
static GridCoverage2D buildCoverage(String name, double[][] dataMatrix, double n, double s, double w, double e, CoordinateReferenceSystem crs, boolean matrixIsRowCol)
          Creates a coverage 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 triplets
static 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 * NOTE: basically the inverse of rowColToCenterCoordinates(JGrassRegion, int, int)
static WritableRaster createDoubleWritableRaster(int width, int height, Class<?> dataClass, SampleModel sampleModel, Double value)
          Creates a writable raster.
static WritableRaster createWritableRasterFromMatrix(double[][] matrix, boolean matrixIsRowCol)
          Create a WritableRaster 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 coordinates
static 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(GridCoverage2D coverage2D)
           
static void printImage(RenderedImage renderedImage)
           
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, w
static RenderedImage scaleJAIImage(int requestedCols, int requestedRows, RenderedImage translatedImage, Interpolation interpolation)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

JGrassUtilities

public JGrassUtilities()
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 mapset
mapname - -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

Parameters:
data -
width -
height -
Returns:

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:
activeRegion -
x - the given easting coordinate
y - 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 transform
col - - 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
coord -
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 mapset
mapname - -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 transform
col - - 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.
Returns:

getJGrassRegionFromGridCoverage

public static JGrassRegion getJGrassRegionFromGridCoverage(GridCoverage2D gridCoverage2D)
                                                    throws InvalidGridGeometryException,
                                                           TransformException
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 a coverage from a double[][] matrix and the necessary geographic Information.

Parameters:
name - the name of the coverage.
dataMatrix - the matrix containing the data.
n -
s -
w -
e -
crs - the CoordinateReferenceSystem.
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 a WritableRaster 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 a writable raster.

Parameters:
width - width of the raster to create.
height - height of the raster to create.
dataClass - data type for the raster. If null, defaults to double.
sampleModel - the samplemodel to use. If null, defaults to new 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)


Copyright © 1996-2014 Geotools. All Rights Reserved.