examples/rp/Register.cpp
Go to the documentation of this file.
1 #include "RPExamples.h"
2 
3 // TerraLib
4 #include <terralib/rp.h>
5 #include <terralib/raster.h>
6 
7 #include <iostream>
8 
9 void Register()
10 {
11  try
12  {
13  std::cout << "Example of how Register a TIF image using Raster Processing module." << std::endl << std::endl;
14 
15  // Openning the the input image
16 
17  std::map<std::string, std::string> auxRasterInfo;
18  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
19  te::rst::Raster* inputRasterPointer = te::rst::RasterFactory::open(
20  auxRasterInfo );
21  if( inputRasterPointer == 0 )
22  {
23  std::cout << "Raster 1 error." << std::endl;
24  return;
25  }
26 
27  // Creating the algorithm parameters
28 
29  te::rp::Register::InputParameters algoInputParams;
30 
31  algoInputParams.m_inputRasterPtr = inputRasterPointer;
32 
33  algoInputParams.m_inputRasterBands.push_back( 0 );
34  algoInputParams.m_inputRasterBands.push_back( 1 );
35  algoInputParams.m_inputRasterBands.push_back( 2 );
36 
38  tiePoint1.first.x = 0.0;
39  tiePoint1.first.y = 0.0;
40  tiePoint1.second.x = 528980.0;
41  tiePoint1.second.y = 7945280.0;
42  algoInputParams.m_tiePoints.push_back( tiePoint1 );
43 
45  tiePoint2.first.x = 874.0;
46  tiePoint2.first.y = 0.0;
47  tiePoint2.second.x = 546460.0;
48  tiePoint2.second.y = 7945280.0;
49  algoInputParams.m_tiePoints.push_back( tiePoint2 );
50 
52  tiePoint3.first.x = 874.0;
53  tiePoint3.first.y = 1008.0;
54  tiePoint3.second.x = 546460.0;
55  tiePoint3.second.y = 7925120.0;
56  algoInputParams.m_tiePoints.push_back( tiePoint3 );
57 
59  tiePoint4.first.x = 0.0;
60  tiePoint4.first.y = 1008.0;
61  tiePoint4.second.x = 528980.0;
62  tiePoint4.second.y = 7925120.0;
63  algoInputParams.m_tiePoints.push_back( tiePoint4 );
64 
65  algoInputParams.m_outputSRID = 29182;
66 
67  algoInputParams.m_outputResolutionX = 20.0;
68  algoInputParams.m_outputResolutionY = 20.0;
69 
70  te::rp::Register::OutputParameters algoOutputParams;
71 
72  algoOutputParams.m_rInfo["URI"] =
73  TERRALIB_DATA_DIR "/GeoReferencedImagesRegisterExample.tif";
74  algoOutputParams.m_rType = "GDAL";
75 
76  // Executing the algorithm
77 
78  te::rp::Register algorithmInstance;
79 
80  if( ! algorithmInstance.initialize( algoInputParams ) )
81  {
82  std::cout << "Algorithm initialization error." << std::endl;
83  return;
84  }
85 
86  if( ! algorithmInstance.execute( algoOutputParams ) )
87  {
88  std::cout << "Algorithm execution error." << std::endl;
89  return;
90  }
91  else
92  {
93  std::cout << "Algorithm execution OK." << std::endl;
94  }
95 
96  // clean up
97 
98  delete inputRasterPointer;
99  }
100  catch(const std::exception& e)
101  {
102  std::cout << std::endl << "An exception has occurred:" << e.what() << std::endl;
103  }
104  catch(...)
105  {
106  std::cout << std::endl << "An unexpected exception has occurred!" << std::endl;
107  }
108 }
109 
Register input parameters.
Definition: Register.h:56
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: Register.h:60
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
These routines show how to use the RP (raster processing) module.
double m_outputResolutionY
The output raster Y axis resolution (default:1).
Definition: Register.h:70
std::pair< Coord2D, Coord2D > TiePoint
Tie point type definition.
Definition: GTParameters.h:59
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
Tie-points between each raster point (te::gm::GTParameters::TiePoint::first are raster lines/columns ...
Definition: Register.h:64
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
An abstract class for raster data strucutures.
std::vector< unsigned int > m_inputRasterBands
Bands to process from the input raster.
Definition: Register.h:62
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
Definition: Register.h:108
This file contains include headers for the TerraLib Raster Processing module.
void Register()
Performs raster data registering into a SRS using a set of tie points.
Definition: Register.h:48
int m_outputSRID
The output raster SRID (default:0).
Definition: Register.h:66
double m_outputResolutionX
The output raster X axis resolution (default:1).
Definition: Register.h:68
Register output parameters.
Definition: Register.h:102
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Register.h:106
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.