VectorizeRaster.cpp
Go to the documentation of this file.
1 #include "RasterExamples.h"
2 
3 // TerraLib
4 #include <terralib/dataaccess.h>
5 #include <terralib/geometry.h>
6 #include <terralib/raster.h>
7 
8 // STL
9 #include <iostream>
10 #include <string>
11 
13 {
14  try
15  {
16  std::cout << "This example shows how to use the vectorization method." << std::endl << std::endl;
17 
18 // define raster info and load
19  std::map<std::string, std::string> rinfo;
20  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/pattern1.tif";
22 
23  std::vector<te::gm::Geometry*> polygons;
24  inraster->vectorize(polygons, 0);
25 
26  std::cout << "vectorizer created " << polygons.size() << " polygons" << std::endl;
27  for (unsigned int i = 0; i < polygons.size(); i++)
28  {
29  te::gm::Polygon* polygon = (te::gm::Polygon*) polygons[i];
30  std::cout << i << ": " << polygon->toString() << std::endl;
31  }
32 
33 // clean up
34  delete inraster;
35  polygons.clear();
36 
37  std::cout << "Done!" << std::endl << std::endl;
38  }
39  catch(const std::exception& e)
40  {
41  std::cout << std::endl << "An exception has occurred in VectorizeRaster(): " << e.what() << std::endl;
42  }
43  catch(...)
44  {
45  std::cout << std::endl << "An unexpected exception has occurred in VectorizeRaster()!" << std::endl;
46  }
47 }
virtual void vectorize(std::vector< te::gm::Geometry * > &g, std::size_t b, unsigned int mp=0, std::vector< double > *const polygonsValues=0)
Vectorizes a given raster band, using GDALPolygonize function.
void VectorizeRaster()
This example shows how to use the vectorization method.
An abstract class for raster data strucutures.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
These routines show how to use the raster module and the GDAL data source module. ...
std::string toString() const
It returns the data value in a WKT representation.
This file contains include headers for the Vector Geometry model of TerraLib.
This file contains include headers for the Data Access module 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.