GeoTools

OSGeo

Table Of Contents

Previous topic

GeoTIFF Plugin

Next topic

GTOPO30 Plugin

This Page

GrassRaster Plugin

The module supplies support for reading and writing GRASS rasters. The metadata contain both the colortable and the categories (if available) of the raster map. The original colortable of the GRASS raster is read into the geotools coverage Categories and can as such be visualized if using a default styler.

Maven:

<dependency>
  <groupId>org.geotools</groupId>
  <artifactId>gt-grassraster</artifactId>
  <version>${geotools.version}</version>
</dependency>

Data structure of a rastermap

Raster data in GRASS are strictly bound to their workspace. Since a workspace is something more on userlevel, I will from now on use grass database for the folder structure and workspace for what the user will interact with at application level.

A GRASS raster map consists of several files in several subdirectories in a mapset, organized as follows:

  • cellhd/: map header including projection code, coordinates representing the spatial extent of the raster map, number of rows and columns, resolution, and information about map compression;
  • cell/, fcell/ or grid3/: generic matrix of values in a compressed, portable format which depends on the raster data type (integer, floating point or 3D grid);
  • hist/: history file which contains metadata such as the data source, the command that was used to generate the raster map, or other information provided by the user;
  • cats/: optional category file which contains text or numeric labels assigned to the raster map categories;
  • colr/: optional color table;
  • cell_misc/: optional timestamp, range of values, quantization rules (for floating point maps) and null (no-data) files;
  • WIND: contains the active processing region and the resolution
  • PROJ_INFO: contains the information about the projection
  • PROJ_UNITS: contains the information about projection units used
  • vector/: contain the vector data since GRASS 6

Usage

        
        /*
         * read a grassraster given the bounds and the number of rows and cols. 
         */
        // prepare the parameters
        GeneralParameterValue[] readParams = new GeneralParameterValue[1];
        Parameter<GridGeometry2D> readGG = new Parameter<GridGeometry2D>(AbstractGridFormat.READ_GRIDGEOMETRY2D);
        GridEnvelope2D gridEnvelope = new GridEnvelope2D(0, 0, cols, rows);
        ReferencedEnvelope env = new ReferencedEnvelope(w, e, s, n, crs);
        readGG.setValue(new GridGeometry2D(gridEnvelope, env));
        readParams[0] = readGG;
        // do the reading
        AbstractGridFormat format = (AbstractGridFormat) new GrassCoverageFormatFactory().createFormat();
        GridCoverageReader reader = format.getReader(file);
        GridCoverage2D gc = ((GridCoverage2D) reader.read(readParams));