Mosaic.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 // STL
8 #include <vector>
9 #include <map>
10 #include <string>
11 
12 void Mosaic()
13 {
14  try
15  {
16  std::cout << "Mosaic of georeferenced images example using Raster Processing module." << std::endl << std::endl;
17 
18  std::map<std::string, std::string> auxRasterInfo;
19 
20  // Openning the the input images
21 
22  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
23  te::rst::Raster* inputRaster1Pointer = te::rst::RasterFactory::open(
24  auxRasterInfo );
25  if( inputRaster1Pointer == 0 )
26  {
27  std::cout << "Raster 1 error." << std::endl;
28  return;
29  }
30 
31  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop2.tif";
32  te::rst::Raster* inputRaster2Pointer = te::rst::RasterFactory::open(
33  auxRasterInfo );
34  if( inputRaster2Pointer == 0 )
35  {
36  std::cout << "Raster 2 error." << std::endl;
37  return;
38  }
39 
40  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop3_EPSG_22522.tif";
41  te::rst::Raster* inputRaster3Pointer ( te::rst::RasterFactory::open(
42  auxRasterInfo ) );
43  if( inputRaster3Pointer == 0 )
44  {
45  std::cout << "Raster 3 error." << std::endl;
46  return;
47  }
48 
49  // Creating the algorithm parameters
50 
51  te::rp::GeoMosaic::InputParameters algoInputParams;
52 
53  std::vector< const te::rst::Raster* > rasters;
54  rasters.push_back( inputRaster1Pointer );
55  rasters.push_back( inputRaster2Pointer );
56  rasters.push_back( inputRaster3Pointer );
57  te::rp::FeederConstRasterVector feeder( rasters );
58  algoInputParams.m_feederRasterPtr = &feeder;
59 
60  // Input raster 1 bands to mosaic
61  std::vector< unsigned int > bands;
62  bands.push_back( 0 );
63  bands.push_back( 1 );
64  bands.push_back( 2 );
65  algoInputParams.m_inputRastersBands.push_back( bands );
66 
67  // Input raster 2 bands to mosaic
68  bands[ 0 ] = 1;
69  bands[ 1 ] = 2;
70  bands[ 2 ] = 0;
71  algoInputParams.m_inputRastersBands.push_back( bands );
72 
73  // Input raster 3 bands to mosaic
74  bands[ 2 ] = 2;
75  bands[ 0 ] = 1;
76  bands[ 1 ] = 0;
77  algoInputParams.m_inputRastersBands.push_back( bands );
78 
79  te::rp::GeoMosaic::OutputParameters algoOutputParams;
80 
81  // The output raster info
82  algoOutputParams.m_rInfo["URI"] =
83  TERRALIB_DATA_DIR "/geotiff/GeoReferencedImagesMosaicExample.tif";
84  algoOutputParams.m_rType = "GDAL";
85 
86  // Executing the algorithm
87 
88  te::rp::GeoMosaic algorithmInstance;
89 
90  if( ! algorithmInstance.initialize( algoInputParams ) )
91  {
92  std::cout << "Algorithm initialization error." << std::endl;
93  return;
94  }
95 
96  if( ! algorithmInstance.execute( algoOutputParams ) )
97  {
98  std::cout << "Algorithm execution error." << std::endl;
99  return;
100  }
101  else
102  {
103  std::cout << "Algorithm execution OK." << std::endl << std::endl;
104  }
105 
106  // clean up
107 
108  delete inputRaster1Pointer;
109  delete inputRaster2Pointer;
110  delete inputRaster3Pointer;
111  }
112  catch(const std::exception& e)
113  {
114  std::cout << std::endl << "An exception has occurred:" << e.what() << std::endl;
115  }
116  catch(...)
117  {
118  std::cout << std::endl << "An unexpected exception has occurred!" << std::endl;
119  }
120 }
121 
A feeder from a input rasters vector;.
Definition: FeedersRaster.h:69
These routines show how to use the RP (raster processing) module.
GeoMosaic input parameters.
Definition: GeoMosaic.h:56
Create a mosaic from a set of geo-referenced rasters.
Definition: GeoMosaic.h:48
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: GeoMosaic.h:104
bool execute(AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
Executes the algorithm using the supplied parameters.
Definition: GeoMosaic.cpp:163
An abstract class for raster data strucutures.
void Mosaic()
Definition: Mosaic.cpp:12
list bands
Definition: compose.py:2
This file contains include headers for the TerraLib Raster Processing module.
bool initialize(const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
Initialize the algorithm instance making it ready for execution.
Definition: GeoMosaic.cpp:760
GeoMosaic output parameters.
Definition: GeoMosaic.h:100
std::vector< std::vector< unsigned int > > m_inputRastersBands
Bands to process for each input raster.
Definition: GeoMosaic.h:62
list rasters
Definition: compose.py:3
FeederConstRaster * m_feederRasterPtr
Input rasters feeder.
Definition: GeoMosaic.h:60
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::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
Definition: GeoMosaic.h:106