ReprojectRaster.cpp
Go to the documentation of this file.
1 #include "RasterExamples.h"
2 
6 
7 #include <iostream>
8 #include <string>
9 
11 {
12  try
13  {
14  std::cout << "Reprojecting raster data using the raster driver internal capacity." << std::endl << std::endl;
15 
16  // 0 - Set input data: a RS image
17  std::map<std::string, std::string> rinfo;
18  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
20 
21  // 1 - The entire image.
22  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_LL.tif";
23  te::rst::Raster* outraster = inraster->transform(4326, rinfo);
24  if (outraster)
25  {
26  std::cout << "End. Check the reprojected raster file: cbers2b_rgb342_crop_LL.tif." << std::endl << std::endl;
27  delete outraster;
28  }
29  else
30  {
31  std::cout << "Reprojection failed!" << std::endl << std::endl;
32  return;
33  }
34 
35  // 2- To a given region.
36  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_LL_P.tif";
37  te::rst::Raster* outraster2 = inraster->transform(4326, 773113, 7365893, 776145, 7368469, rinfo);
38  if (outraster2)
39  {
40  std::cout << "End. Check the reprojected raster file: cbers2b_rgb342_crop_LL_P.tif." << std::endl << std::endl;
41  delete outraster2;
42  }
43  else
44  {
45  std::cout << "Reprojection failed!" << std::endl << std::endl;
46  return;
47  }
48 
49  // 3- To a given region and resolution.
50  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_LL_PR.tif";
51  te::rst::Raster* outraster3 = inraster->transform(4326, 773113, 7365893, 776145, 7368469, 0.0003, 0.0003, rinfo);
52  if (outraster3)
53  {
54  std::cout << "End. Check the reprojected raster file: cbers2b_rgb342_crop_LL_PR.tif." << std::endl << std::endl;
55  delete outraster3;
56  }
57  else
58  {
59  std::cout << "Reprojection to cbers2b_rgb342_crop_LL_PR failed!" << std::endl << std::endl;
60  return;
61  }
62  delete inraster;
63  }
64  catch(const std::exception& e)
65  {
66  std::cout << std::endl << "An exception has occurred in ReprojectRasterUsingDriver(): " << e.what() << std::endl;
67  }
68  catch(...)
69  {
70  std::cout << std::endl << "An unexpected exception has occurred in ReprojectRasterUsingDriver()!" << std::endl;
71  }
72 }
73 
75 {
76  try
77  {
78  std::cout << "Reprojecting raster data using TerraLib's own algorithm." << std::endl << std::endl;
79 
80  // 0 - Set input data: a RS image
81  std::map<std::string, std::string> rinfo;
82  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
84 
85  // 1 - The entire image.
86  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_LL_ALG.tif";
87  te::rst::Raster* outraster = te::rst::Reproject(inraster, 4326, rinfo);
88  if (outraster)
89  {
90  std::cout << "End. Check the reprojected raster file: cbers2b_rgb342_crop_LL_ALG.tif." << std::endl << std::endl;
91  delete outraster;
92  }
93  else
94  {
95  std::cout << "Reprojection to cbers2b_rgb342_crop_LL_ALG failed!" << std::endl << std::endl;
96  return;
97  }
98 
99  // 2- To a given region.
100  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_LL_P_ALG.tif";
101  te::rst::Raster* outraster2 = te::rst::Reproject(inraster, 4326, 773113, 7365893, 776145, 7368469, rinfo);
102  if (outraster2)
103  {
104  std::cout << "End. Check the reprojected raster file: cbers2b_rgb342_crop_LL_P_ALG.tif." << std::endl << std::endl;
105  delete outraster2;
106  }
107  else
108  {
109  std::cout << "Reprojection to cbers2b_rgb342_crop_LL_P_ALG failed !" << std::endl << std::endl;
110  return;
111  }
112 
113  // 3- To a given region and resolution.
114  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_LL_PR_ALG.tif";
115  te::rst::Raster* outraster3 = te::rst::Reproject(inraster, 4326, 773113, 7365893, 776145, 7368469, 0.0006, 0.0006, rinfo);
116  if (outraster3)
117  {
118  std::cout << "End. Check the reprojected raster file: cbers2b_rgb342_crop_LL_PR_ALG.tif." << std::endl << std::endl;
119  delete outraster3;
120  }
121  else
122  {
123  std::cout << "Reprojection to cbers2b_rgb342_crop_LL_PR_ALG failed!" << std::endl << std::endl;
124  return;
125  }
126  delete inraster;
127  }
128  catch(const std::exception& e)
129  {
130  std::cout << std::endl << "An exception has occurred in ReprojectRasterUsingFunction(): " << e.what() << std::endl;
131  }
132  catch(...)
133  {
134  std::cout << std::endl << "An unexpected exception has occurred in ReprojectRasterUsingFunction()!" << std::endl;
135  }
136 }
It contains the algorithm to reproject raster data.
An abstract class for raster data strucutures.
This is the abstract factory for Rasters.
An abstract class for raster data strucutures.
void ReprojectRasterUsingFunction()
Reproject one raster using GDAL implementation.
virtual Raster * transform(int srid, const std::map< std::string, std::string > &rinfo, int m=1) const
Reprojects this raster to a distinct SRS. This method reprojects this raster to a distinct SRS...
TERASTEREXPORT te::rst::Raster * Reproject(te::rst::Raster const *const rin, int srid, const std::map< std::string, std::string > &routinfo, int m=te::rst::NearestNeighbor)
Reprojects a raster to another SRS.
These routines show how to use the raster module and the GDAL data source module. ...
void ReprojectRasterUsingDriver()
Reproject one raster using TerraLib implementation.
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.