Wkt.cpp
Go to the documentation of this file.
1 // Examples
2 #include "GeometryExamples.h"
3 
4 // TerraLib
6 
7 // SLT
8 #include <iostream>
9 #include <fstream>
10 #include <string>
11 
12 void readWkts(const std::string& filePath)
13 {
14  std::cout << "Reading Wkt file..." << std::endl;
15 
16  // Open a txt file that contains a set of Wkt geometries
17  std::ifstream wktFile(filePath.c_str(), std::ifstream::in);
18  std::string wkt;
19  while(wktFile.good()) // for each Wkt
20  {
21  std::getline(wktFile, wkt);
22 
23  std::cout << std::endl;
24  std::cout << "File Wkt: " << wkt << std::endl;
25 
26  te::gm::Geometry* g = 0;
27  try
28  {
29  // Reads the Wkt and gets the geometry
30  g = te::gm::WKTReader::read(wkt.c_str());
31  }
32  catch(te::common::Exception& e)
33  {
34  std::cout << e.what() << std::endl;
35  }
36 
37  if(g == 0)
38  continue;
39 
40  std::cout << "Generated Geometry Wkt: " << g->asText() << std::endl;
41 
42  delete g;
43  }
44 
45  wktFile.close();
46 }
virtual const char * what() const
It outputs the exception message.
std::string asText() const _NOEXCEPT_OP(true)
It returns an string with the Well-Known Text Representation for the geometry.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A set of geometry examples.
void readWkts(const std::string &filePath)
Definition: Wkt.cpp:12
static Geometry * read(const char *wkt)
It returns a valid Geometry from a given WKT.