DrawingRasterObject.cpp
Go to the documentation of this file.
1 #include "CanvasExamples.h"
2 
3 // TerraLib
4 #include "../../Config.h"
5 #include <terralib/raster.h>
6 #include <terralib/dataaccess.h>
7 #include <terralib/datatype.h>
8 #include <terralib/geometry.h>
10 
11 // Qt
12 #include <QApplication>
13 
15 {
16  int argc = 1;
17 
18  //create application
19  QApplication app(argc, 0);
20 
21  // set input raster name
22  std::string data_dir = TERRALIB_DATA_DIR;
23 
24  std::string rinfo("file://");
25  rinfo += data_dir + "/geotiff/cbers2b_rgb342_crop.tif";
26 
27  // open input raster
28  std::unique_ptr<te::da::DataSource> ds = te::da::DataSourceFactory::make("GDAL", rinfo);
29  ds->open();
30 
31  std::unique_ptr<te::da::DataSourceTransactor> tr = ds->getTransactor();
32 
33  std::unique_ptr<te::da::DataSet> dataSet = tr->getDataSet("cbers2b_rgb342_crop.tif");
34  std::size_t rpos = te::da::GetFirstPropertyPos(dataSet.get(), te::dt::RASTER_TYPE);
35  std::unique_ptr<te::rst::Raster> raster = dataSet->getRaster(rpos);
36 
37  const te::gm::Envelope* extent = raster->getExtent();
38 
39  double llx = extent->m_llx;
40  double lly = extent->m_lly;
41  double urx = extent->m_urx;
42  double ury = extent->m_ury;
43 
44  // create the canvas and adjust the world-device transformation parameters
45  te::qt::widgets::Canvas canvas(800, 600);
46  canvas.setWindow(llx,lly,urx,ury);
47  canvas.calcAspectRatio(llx,lly,urx,ury);
48 
49  //draw imamge
50  canvas.drawImage(0,0, canvas.getWidth(), canvas.getHeight(), raster.get(), 0, 0, raster->getNumberOfColumns(), raster->getNumberOfRows());
51 
52  // save a PNG to disk
53  canvas.save("raster.png", te::map::PNG);
54 }
This file contains include headers for the Data Type module of TerraLib.
A canvas built on top of Qt.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
void drawImage(char *src, std::size_t size, te::map::ImageType t)
It draws the src image over the canvas.
void DrawingRasterObject()
It retrieves data from a tiff file and prints it to a png graphics file.
double m_urx
Upper right corner x-coordinate.
static te::dt::Date ds(2010, 01, 01)
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
double m_llx
Lower left corner x-coordinate.
Several examples declarations.
An Envelope defines a 2D rectangular region.
void calcAspectRatio(double &llx, double &lly, double &urx, double &ury, const te::map::AlignType hAlign=te::map::Center, const te::map::AlignType vAlign=te::map::Center)
It calculates the best aspect ratio for world (or window) coordinates area (supposing a cartesian ref...
double m_lly
Lower left corner y-coordinate.
int getWidth() const
It returns the canvas width.
double m_ury
Upper right corner y-coordinate.
int getHeight() const
It returns the canvas height.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
This file contains include headers for the Vector Geometry model of TerraLib.
void save(const char *fileName, te::map::ImageType t, int quality=75, int fg=0) const
It saves the canvas content to a file image in the specified format type.
This file contains include headers for the Data Access module of TerraLib.