ResampleRaster.cpp
Go to the documentation of this file.
1 #include "RasterExamples.h"
2 
3 // TerraLib
4 #include <terralib/raster.h>
7 
8 // STL
9 #include <cstdio>
10 #include <iostream>
11 #include <string>
12 
14 {
15  try
16  {
17  std::cout << "This test resample one raster based on user defined parameters." << std::endl << std::endl;
18 
19  std::map<std::string, std::string> rinfo;
20 
21 // set input raster name
22  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
23 
24 // open input raster
26 
27 // set output raster names
28  std::map<std::string, std::string> nnname;
29  nnname["URI"] = TERRALIB_DATA_DIR "/geotiff/resampled_nn_scale_plus2.tif";
30 
31  std::map<std::string, std::string> biliname;
32  biliname["URI"] = TERRALIB_DATA_DIR "/geotiff/resampled_bili_scale_minus2.tif";
33 
34  std::map<std::string, std::string> bicname;
35  bicname["URI"] = TERRALIB_DATA_DIR "/geotiff/resampled_bic_scale_minus3.tif";
36 
37 // applies the interpolation
38  te::rst::Raster* nnraster = inraster->resample(te::rst::NearestNeighbor, 2, nnname);
39  delete nnraster;
40  std::cout << " Raster " << nnname["URI"] << " created!" << std::endl;
41 
42  te::rst::Raster* biliraster = inraster->resample(te::rst::Bilinear, -2, biliname);
43  delete biliraster;
44  std::cout << " Raster " << biliname["URI"] << " created!" << std::endl;
45 
46  te::rst::Raster* bicraster = inraster->resample(te::rst::Bicubic, -3, bicname);
47  delete bicraster;
48  std::cout << " Raster " << bicname["URI"] << " created!" << std::endl;
49 
50  delete inraster;
51 
52  std::cout << "Done!" << std::endl << std::endl;
53  }
54  catch(const std::exception& e)
55  {
56  std::cout << std::endl << "An exception has occurred in MakeRasterBlock(): " << e.what() << std::endl;
57  }
58  catch(...)
59  {
60  std::cout << std::endl << "An unexpected exception has occurred in MakeRasterBlock()!" << std::endl;
61  }
62 }
void ResampleRaster()
Resample one Raster based on user defined parameters.
Near neighborhood interpolation method.
virtual Raster * resample(int method, unsigned int drow, unsigned int dcolumn, unsigned int height, unsigned int width, unsigned int newheight, unsigned int newwidth, const std::map< std::string, std::string > &rinfo) const
Resample a subset of the raster, given a box.
This is the abstract factory for Rasters.
An abstract class for raster data strucutures.
Bicubic interpolation method.
These routines show how to use the raster module and the GDAL data source module. ...
Bilinear interpolation method.
It interpolates one pixel based on a selected algorithm.
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.