examples/rp/ArithmeticOperations.cpp
Go to the documentation of this file.
1 #include "RPExamples.h"
2 
3 // TerraLib
4 
5 #include <terralib/rp.h>
6 #include <terralib/raster.h>
7 
8 // STL
9 #include <string>
10 
12 {
13  try
14  {
15  std::cout << "Example of arithmetic operations using bands of a Raster." << std::endl << std::endl;
16 
17 // open input raster
18  std::map<std::string, std::string> rinfo;
19  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
20  std::unique_ptr<te::rst::Raster> rin(te::rst::RasterFactory::open(rinfo));
21 
22 // defining input parameters, the arithmetic operation will be
23 // band / same band, to check if in the final result, the mean
24 // will be 1.0
26  inputParams.m_arithmeticString = "R0:0 / R0:0";
27  inputParams.m_normalize = false;
28  inputParams.m_inputRasters.push_back(rin.get());
29 
30 // create output raster info
31  std::map<std::string, std::string> orinfo;
32  orinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/arithmetic_operations_result.tif";
33 
34 // defining output parameters
36  outputParams.m_rInfo = orinfo;
37  outputParams.m_rType = "GDAL";
38 
39  te::rp::ArithmeticOperations algorithmInstance;
40 
41  if(!algorithmInstance.initialize(inputParams))
42  throw;
43  if(!algorithmInstance.execute(outputParams))
44  throw;
45  outputParams.reset();
46 
47 // open output raster
48  std::unique_ptr<te::rst::Raster> rout(te::rst::RasterFactory::open(orinfo));
49  std::cout << rout->toString();
50  }
51  catch(const std::exception& e)
52  {
53  std::cout << std::endl << "An exception has occurred in ArithmeticOperations(): " << e.what() << std::endl;
54  }
55  catch(...)
56  {
57  std::cout << std::endl << "An unexpected exception has occurred in ArithmeticOperations()!" << std::endl;
58  }
59 }
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
These routines show how to use the RP (raster processing) module.
bool execute(AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
Executes the algorithm using the supplied parameters.
bool m_normalize
Output values normalization will be performed to fit the original input raster values range (default:...
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
bool initialize(const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
Initialize the algorithm instance making it ready for execution.
ArithmeticOperations output parameters.
This file contains include headers for the TerraLib Raster Processing module.
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated resources and reset the parameters instance to its initial state...
std::vector< te::rst::Raster * > m_inputRasters
Input rasters vector.
Performs arithmetic operation over raster data.
ArithmeticOperations input parameters.
static Raster * open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
It opens a raster with the given parameters and default raster driver.
std::string m_arithmeticString
Arithmetic string.