Table of Contents

Raster

The Raster module provides the base classes foundation for handling geographical data such as remote sensing imagery data. The raster data structure can be viewed as a matrix of cells or pixels associated with spatial locations forming a regular grid. By design each cell can be viewed, individually, as a multi-dimensional data.

This module defines only the abstract classes and therefore implementations must be provided. We call these implementations: raster drivers. TerraLib provides raster drivers on top of other libraries (GDAL, GRIB API, RasterLite), DBMS (PostGIS Raster, MySQL, SQLite) and an In-Memory implementation. In future releases we will provide raster support over Web Services.

This section explains the design an implementation of this module.

Design

The following class diagram shows the main classes in this module:

Raster classes

The Raster class is an abstract class and it is the main raster data conteiner.

A raster is composed by raster bands. A band is represented by the abstract class Band.

For detailed documentation, find the doxygen documentation of Raster class.

Band

One Raster can contain one or more bands. Depending on the satellite, two data storage mechanisms are possible:

Each band is described by a BandProperty.

Follow this link to reach the detailed information of BandProperty class generated by doxygen.

The summarized information are here:

The BandProperty class also keeps information on how the band is arranged in blocks. Besides the above information it also provides:

Grid

A raster also has a grid that defines its spatial support (a rectified grid).

Follow this link to reach the detailed documentation of grid class generated by doxygen, but basically the Grid class contains:

The list of 6 coefficients contains:

They are used to interchange the raster space (Column, Row) with the projection coordinates (X, Y) space, according to the following equation:

X = [0] + C * [1] + R * [2]
Y = [3] + C * [4] + R * [5]

Data Access

In order to have access to cell values one should access the appropriated Band or use the pixel access methods in the Raster class.

double value;
std::complex<double> cvalue; // cvalue.real() is the real part, and cvalue.imag() is the imaginary part, when available
std::vector<std::complex<double> > values;
 
// for example, to get the value in position (10,50) from band 2 in myraster
 
// method 1, using Raster class
myraster->getValue(10, 50, value, 2);
 
// method 2, using Raster class
myraster->getValue(10, 50, cvalue, 2);
value = cvalue.real();
 
// method 3, using vector of complex data in Raster class
myraster->getValues(10, 50, values);
value = values[2].real();
 
// method 4, using Band class
myraster->getBand(2)->getValue(10, 50, value);
 
// method 5, using Band class
myraster->getBand(2)->getValue(10, 50, cvalue);
value = cvalue.real();

There are two ways to handle rasters in TerraLib:

For using as a regular library you can use the RasterFactory class in order to start working with raster data.

Raster Factory

Follow this link to reach the detailed documentation of RasterFactory class generated by doxygen.

The following code snippet shows how to open a raster file for reading using the default raster library support:

std::map<std::string, std::string> rinfo;
 
rinfo["URI"] = "/dir/myfile.tif";
 
te::rst::Raster* r = te::rst::RasterFactory::make();
 
r->open(rinfo, te::common::RAccess);
 
// your code manipulating the raster goes here!
 
delete r;

If you prefer using another raster library support for reading a raster file:

std::map<std::string, std::string> rinfo;
 
rinfo["URI"] = "/dir/myfile.tif";
 
te::rst::Raster* r = te::rst::RasterFactory::make("MY_OWN_IMPLEMENTATION");
 
r->open(rinfo, te::common::RAccess);
 
// your code manipulating the raster goes here!
 
delete r;

The following code snippet shows how to create a new raster file:

te::rst::Grid* grid = new te::rst::Grid(...);
 
te::rst::BandProperty* b1 = new te::rst::BandProperty(...);
 
te::rst::BandProperty* b2 = new te::rst::BandProperty(...);
 
te::rst::BandProperty* b3 = new te::rst::BandProperty(...);
 
std::vector<te::rst::BandProperty*> bands; bands.push_back(b1); bands.push_back(b2); bands.push_back(b3);
 
std::map<std::string, std::string> rinfo;
 
rinfo["URI"] = "/dir/myfile.tif";
 
te::rst::Raster* r = te::rst::RasterFactory::make(grid, bands, rinfo);
 
// R is ready for working!!
 
delete r;

If you want to use a more specific library for creating a new raster file:

te::rst::Grid* grid = new te::rst::Grid(...);
 
te::rst::BandProperty* b1 = new te::rst::BandProperty(...);
 
te::rst::BandProperty* b2 = new te::rst::BandProperty(...);
 
te::rst::BandProperty* b3 = new te::rst::BandProperty(...);
 
std::vector<te::rst::BandProperty*> bands; bands.push_back(b1); bands.push_back(b2); bands.push_back(b3);
 
std::map<std::string, std::string> rinfo;
 
rinfo["URI"] = "/dir/myfile.tif";
 
te::rst::Raster* r = te::rst::RasterFactory::make("MY_OWN_IMPLEMENTATION", grid, bands, rinfo);
 
// R is ready for working!!
 
delete r;

For using raster in the data source API… <color red>!!forma normal!!</color>

RasterProperty class

Follow this link to reach the updated documentation of RasterProperty class generated by doxygen.