com.supermap.data

Class DatasetGrid



  • public class DatasetGrid
    extends Dataset

    The DatasetGrid class.

    Grid data belongs to the raster type. A raster is comprised of a two-dimensional matrix of cells, which have attributes that represent qualities such as color, spectral reflectance, or rainfall. The grid dataset is mostly used to do some analysis based on raster, so the value of a pixel represents certain attribute of a geographic feature, such as elevation, soil type, density value, temperature, humidity, etc.

    Note: Before performing any operations, you need to call Dataset.open() method to open the dataset.

    • Method Detail

      • getWidth

        public int getWidth()
        Returns the width of the image dataset. The unit is pixel.
        Returns:
        the width of the raster in the grid dataset.
      • getHeight

        public int getHeight()
        Returns the height of the grid of the DatasetGrid. The unit is pixel.
        Returns:
        the height of the raster in the grid dataset.
      • getHasPyramid

        public boolean getHasPyramid()
        Returns a value indicates that whether the grid dataset has built the pyramid. True represents that the grid dataset has built the pyramid while False represents that has not.
        Returns:
        whether the raster dataset has build pyramid.
      • getPixelFormat

        public PixelFormat getPixelFormat()
        Returns the pixel format of the grid dataset. The pixel can be expressed with the byte, bit is the unit. For more information, please refer to the PixelFormat.
        Returns:
        the specified pixel format of the grid data.
        See Also:
        PixelFormat
      • getBlockSize

        public int getBlockSize()
        Returns the size of the block for storing with the specified pixels in grid dataset, and pixel is the unit. The default value is 128 pixel. The blocking mode is stored the block as the square, for instance, blocking the square with 4*4 pixel, the grid data will be blocked the matrix with 3 rows and 3 columns. Where,if the image or grid data has not enough pixel to be blocked, so using the empty grid to make up for the block.

        Returns:
        the specified block size of the grid dataset.
      • getRowBlockCount

        public int getRowBlockCount()
        Returns the total count of rows which are gotten after the grid dataset has been divided into many blocks.
        Returns:
        the total count of rows which are gotten after the grid dataset has been divided into many blocks.
      • getColumnBlockCount

        public int getColumnBlockCount()
        Returns the total count of columns which are gotten after the grid dataset has been divided into many blocks.
        Returns:
        the total count of columns which are gotten after the grid dataset has been divided into many blocks.
      • getNoValue

        public double getNoValue()
        Returns the empty value of the grid dataset. When the empty value exists in the grid dataset, user can use -9999 to express the empty value.
        Returns:
        The null value of raster dataset.
      • setNoValue

        public void setNoValue(double value)
        Sets the empty value of the grid dataset. When the empty value exists in the grid dataset, user can use -9999 to express the empty value.
        Parameters:
        value - The null value of raster dataset.
      • getMinValue

        public double getMinValue()
        Returns the minimum value of the grid matrix in grid dataset.
        Returns:
        the minimum value of the grid matrix in grid dataset.
        See Also:
        calculateExtremum()
        Example:
        See the sample of DatasetGrid.calculateExtremum() method.
      • getMaxValue

        public double getMaxValue()
        Returns the maximum value in the grid dataset.
        Returns:
        the maximum value of the grid matrix in grid dataset.
        See Also:
        calculateExtremum()
        Example:
        See the sample of DatasetGrid.calculateExtremum() method.
      • getClipRegion

        public GeoRegion getClipRegion()
        Returns the display extent of the grid dataset. When user set the grid dataset display area, the grid dataset will be displayed with the specified region and the out of the region will not be displayed.

        Note:

        1. When the geographic extent of the raster dataset set by the users (namely, call the DatasetGrid.SetGeoReference() method) hasn't overlap region with the clipping region, the raster dataset won't be displayed.

        2. When reset the geographic extent of the raster dataset, it won't modify the clipping region of raster dataset automatically.

        Returns:
        the display extent of the grid dataset.
      • setClipRegion

        public void setClipRegion(GeoRegion value)
        Sets the display extent of the grid dataset.

        When user set this method, the grid data will be displayed with the specified region and the out of the region will not be displayed.

        Note:

        1. When the geographic extent of the raster dataset set by the users (namely, call the DatasetGrid.SetGeoReference() method) hasn't overlap region with the clipping region, the raster dataset won't be displayed.

        2. When reset the geographic extent of the raster dataset, it won't modify the clipping region of raster dataset automatically.

        Parameters:
        value - the display extent of the grid dataset.
        Example:
        The following example demonstrates how to set the display region for a gird dataset.
         public void setClipRegionTest() {
                // Imagines that you open a workspace object, and there is a database datasource object in the workspace
                // The datasource includes a raster dataset Raster (datasetGrid), open the dataset.
                // Defines the range of the display area
                Point2Ds point2Ds = new Point2Ds();
                point2Ds.add(new Point2D(0, 0));
                point2Ds.add(new Point2D(800, 0));
                point2Ds.add(new Point2D(800, 800));
                point2Ds.add(new Point2D(0, 800));
                point2Ds.add(new Point2D(0, 0));
                GeoRegion georegion = new GeoRegion(point2Ds);
                // Sets the display area
                datasetGrid.setClipRegion(georegion);
                datasetGrid.close();
            }
        
      • calculateExtremum

        public boolean calculateExtremum()
        Calculate the extreme value of the grid dataset.
        Returns:
        if successful, returns true; Otherwise, returns false.
        Example:
        The following example demonstrates how to compute the maximum and minimum value in the grid dataset.
         public void calculateExtremumTest() {
                // Imagines that you open a workspace object, and there is a database datasource object in the workspace
                // The datasource includes a raster dataset Raster (datasetGrid), open the dataset.
        
                // Calculates the maximum and minimum values of the raster value in the raster dataset
                DatasetGrid datasetGrid = (DatasetGrid) datasource.getDatasets().get(
                        "Raster");
                datasetGrid.open();
                if (datasetGrid.calculateExtremum()) {
                    double maxValue = datasetGrid.getMaxValue();
                    double minValue = datasetGrid.getMinValue();
                    System.out.println("The maximum value is: " + maxValue + "The maximum value is: " + minValue);
                }
                datasetGrid.close();
            }
         
      • getValue

        public double getValue(int x,
                               int y)
        Returns the grid value of the grid dataset with the specific row number and column number.
        Parameters:
        x - The row of the specified grid dataset.
        y - The column of the specified grid dataset.
        Returns:
        The raster values for the raster of the raster dataset
        See Also:
        gridToXY(Point)
        Example:
        See the sample of DatasetGrid.gridToXY() method.
      • setGeoReference

        public void setGeoReference(Rectangle2D bounds)
        Sets the bound of grid dataset to the geographical coordinates.
        Parameters:
        bounds - The specified grid bounds.
      • setValue

        public double setValue(int x,
                               int y,
                               double value)
        Sets the grid value of the grid dataset with the specific row number and column number.

        Note: The number of columns of parameter values for this method counts from zero.

        Parameters:
        x - The row of the specified grid dataset.
        y - The column of the specified grid dataset.
        value - Specifies the raster value for the raster of the specified raster dataset.
        Returns:
        The grid value of the grid of the grid dataset that corresponds to the modification.
      • gridToXY

        public Point2D gridToXY(java.awt.Point point)
        This method is used to transform the grid with the specified row and column to the point which is x-coordinate and y-coordinate in geographical coordinates system.
        Parameters:
        point - the specified image point with the specified row and column.
        Returns:
        A point which is x-coordinate and y-coordinate in geographical coordinates.
        Example:
        The following example demonstrates how to get the gird value at specified row and column and transfer it to the point which is x-coordinate and y-coordinate in geographical coordinates system.
         public void gridToXYTest() {
                // Imagines that you open a workspace object, and there is a database datasource object in the workspace
                // The datasource includes a raster dataset Raster (datasetGrid), open the dataset.
        
                // Gets the value of raster point at specified clumn and row and then converts this point to the point under the geographic coordinate system
                DatasetGrid datasetGrid = (DatasetGrid) datasource.getDatasets().get(
                        "Raster");
                datasetGrid.open();
        
                java.awt.Point point = new java.awt.Point(100, 50);
                double value = datasetGrid.getValue(100, 50);
                Point2D point2D = datasetGrid.gridToXY(point);
                System.out.println("The raster value of this point is: " + value + " geographic coordinate is:" + point2D);
                datasetGrid.close();
            }
         
      • xyToGrid

        public java.awt.Point xyToGrid(Point2D point)
        This method is used to transform the x-coordinate and y-coordinate in geographical coordinates system to grid point in grid dataset.
        Parameters:
        point - specified point which is x-coordinate and y-coordinate in geographical coordinates system.
        Returns:
        Grid Dataset corresponding grid
      • updatePyramid

        public boolean updatePyramid(Rectangle2D rectangle2D)
        Update the image pyramid in the specific extent.
        Parameters:
        rectangle2D - update the image pyramid in the specific extent.
        Returns:
        Returns true If successful; otherwise false.
        Example:
        The following code demonstrates how to update the image pyramid in specific extent.
         public void updatePyramidTest() {
                // Imagines that you open a workspace object, and there is a database datasource object in the workspace
                // The datasource includes a raster dataset Raster (datasetGrid), open the dataset.
                DatasetGrid datasetGrid = (DatasetGrid) datasource.getDatasets().get("Raster");
                datasetGrid.open();
        
                //Specifies the update range of raster dataset pyramid
                Rectangle2D rectangle2D = datasetGrid.getBounds();
                double width = rectangle2D.getRight() - rectangle2D.getLeft();
                double height = rectangle2D.getTop() - rectangle2D.getBottom();
                rectangle2D.setLeft(rectangle2D.getLeft() + width/4);
                rectangle2D.setRight(rectangle2D.getRight() - width/4);
                rectangle2D.setTop(rectangle2D.getTop() + height/4);
                rectangle2D.setBottom(rectangle2D.getBottom() + height/4);
                
                //Updates the image pyramid
                datasetGrid.updatePyramid(rectangle2D);
                
                //Close dataset
                datasetGrid.close();
            }
         
      • removePyramid

        public boolean removePyramid()
        Removes the pyramid of the grid dataset.
        Returns:
        Returns true if it is removed successfully; false otherwise.
      • getColorTable

        public Colors getColorTable()
        The color table when opening the dataset. All of the settings will lose when closing the dataset.
        Returns:
        The color table..
      • setColorTable

        public void setColorTable(Colors colors)
        Sets the color table.
        Parameters:
        colors - the color table object.
      • update

        public boolean update(DatasetGrid dataset)
        Updates according to the specified grid dataset.

        Note: the encode type the given grid dataset and the grid dataset to update have the same encoding type and pixel format:EncodeTypeandPixelFormat.

        Parameters:
        dataset - The specified grid dataset.
        Returns:
        A boolean represents whether update successfully or not. Returns true if successful; otherwise, false.
      • getGridStatisticsResult

        public StatisticsResult getGridStatisticsResult()
        Returns the statistics result of raster dataset. Including Max, Min, Average, median, thickest value, thinnest value, variance and standard deviation.

        If the raster dataset didn't conduct the raster statistics, namely, didn't call the buildStatistics() method, every statistics in the result is 0.

        If the pixel format of the raster dataset isSINGLE and DOUBLE , the thickest value (got by the { getMajority() method) and thinnest value (got by the getMinority() method) arrays in the statistics result objects are empty arrays, and the median (got by the getMedianValue() method) is 0. The statistics doesn't contain the three results.

        Returns:
        The statistics result object of the raster dataset.
      • buildStatistics

        public StatisticsResult buildStatistics()
        Implement the statistics for the raster dataset. Return the statistics result of the raster dataset, including max, min, average, median, thickest value, thinnest value, variance, standard deviation and so on.
        Returns:
        The statistics result object of the raster dataset.
      • buildValueTable

        public DatasetVector buildValueTable(Datasource targetDatasource,
                                             java.lang.String tableName)
        Create the cell value property sheet, and its type is tabular dataset TABULAR.

        The pixel format of the raster dataset isSINGLE and DOUBLE . Unable to create the attribute table, namely return null after called this method.

        Returns the system field and two raster information fields of Tabular Dataset. GRIDVALUE records the cell value, and GRIDCOUNT records the cell number corresponding to the cell values.

        Parameters:
        targetDatasource - Datasource for storing the table datasets.
        tableName - The name of the table dataset to be created.
        Returns:
        Returns the table object of the cell value.
      • buildPyramid

        public boolean buildPyramid()
        To create an image pyramid, you must first close the dataset before creating the image pyramid.
        Returns:
        Returns whether the image pyramid was created successfully, true if true, false otherwise.