MakeRasterCrop.cpp
Go to the documentation of this file.
1 #include "RasterExamples.h"
2 
3 // TerraLib
4 #include <terralib/geometry.h>
5 #include <terralib/raster.h>
7 
8 // STL
9 #include <iostream>
10 #include <string>
11 #include <map>
12 
14 {
15  try
16  {
17  std::cout << "This test creates an image crop with a provided envelope." << std::endl << std::endl;
18 
19  std::map<std::string, std::string> irinfo;
20 
21  irinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
22 
24 
25 // set envelope based on line/column
26  te::gm::Coord2D cur = inraster->getGrid()->gridToGeo(299, 150);
27  te::gm::Coord2D cll = inraster->getGrid()->gridToGeo(100, 299);
28  te::gm::Envelope* blenv = new te::gm::Envelope(cll.x, cll.y, cur.x, cur.y);
29 
30  std::map<std::string, std::string> orinfo;
31 
32  orinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/raster-crop.tif";
33 
34  te::rst::Raster* outraster = inraster->trim(blenv, orinfo);
35 
36  delete inraster;
37  delete outraster;
38 
39  std::cout << "Done!" << std::endl << std::endl;
40  }
41  catch(const std::exception& e)
42  {
43  std::cout << std::endl << "An exception has occurred in MakeRasterCrop(): " << e.what() << std::endl;
44  }
45  catch(...)
46  {
47  std::cout << std::endl << "An unexpected exception has occurred in MakeRasterCrop()!" << std::endl;
48  }
49 
50 }
51 
double y
y-coordinate.
Definition: Coord2D.h:114
double x
x-coordinate.
Definition: Coord2D.h:113
virtual Raster * trim(const te::gm::Envelope *env, const std::map< std::string, std::string > &rinfo) const
Subsetting operation for trimming (cropping) the raster.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
This is the abstract factory for Rasters.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
Grid * getGrid()
It returns the raster grid.
These routines show how to use the raster module and the GDAL data source module. ...
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
void MakeRasterCrop()
Creates an image crop with a providen envelope.
This file contains include headers for the Vector Geometry model of TerraLib.
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.