Class 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 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
      • 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 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
        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.
      • 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.
        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)