UOM.cpp
Go to the documentation of this file.
1 #include "CommonExamples.h"
2 
3 // TerraLib
4 #include <terralib/srs.h>
5 
6 // STL
7 #include <iostream>
8 
9 void UOMManage()
10 {
11  try
12  {
13  // list all units in the manager
16  std::cout << "Units in the manager:"<< std::endl;
17  while (it!=itend)
18  {
19  te::common::UnitOfMeasurePtr uptr = it->second;
20  std::cout << "\t Id:" << uptr->getId() << " name: " << uptr->getName() << " symbol: " << uptr->getSymbol() << std::endl;
21  ++it;
22  }
23 
24  // searching by name and displaying information about unit
26  if (munit.get())
27  std::cout << "Unit \"metre\" found."<< std::endl;
28  else
29  return;
30 
31  unsigned int id = munit->getId();
32  std::string symb = munit->getSymbol();
33 
35  if (munit.get())
36  std::cout << "Unit " << id << " found."<< std::endl;
37  else
38  return;
39 
41  if (munit.get())
42  std::cout << "Unit " << symb << " found."<< std::endl;
43  else
44  return;
45 
46  // converting from units
47  std::cout << "1 km = " << te::common::UnitsOfMeasureManager::getInstance().getConversion("kilometre","metre") << " m." << std::endl;
48  std::cout << "1 m = " << te::common::UnitsOfMeasureManager::getInstance().getConversion("metre","kilometre") << " km." << std::endl;
49 
50  std::cout << "1 deg = " << te::common::UnitsOfMeasureManager::getInstance().getConversion("degree","radian") << " rad." << std::endl;
51  std::cout << "1 rad = " << te::common::UnitsOfMeasureManager::getInstance().getConversion("radian","degree") << " deg." << std::endl;
52 
53  std::cout << "1 km = " << te::common::UnitsOfMeasureManager::getInstance().getConversion("kilometre","radian") << "rad." << std::endl;
54 
55  }
56  catch (te::common::Exception& ex)
57  {
58  std::cout << ex.what() << std::endl;
59  }
60 }
61 
62 void UnitSRS()
63 {
64  try
65  {
66  std::cout << "Geographic:" << std::endl;
68  if(uptr)
69  std::cout << "\t Id:" << uptr->getId() << " name: " << uptr->getName() << " symbol: " << uptr->getSymbol() << std::endl;
70 
71  std::cout << "Projected:" << std::endl;
73  if(uptr)
74  std::cout << "\t Id:" << uptr->getId() << " name: " << uptr->getName() << " symbol: " << uptr->getSymbol() << std::endl;
75  }
76  catch (te::common::Exception& ex)
77  {
78  std::cout << ex.what() << std::endl;
79  }
80 }
81 
const_iterator begin() const
It returns an iterator to the beginning of the conteiner.
This file contains include headers for TerraLib Spatial Reference System module.
virtual const char * what() const
It outputs the exception message.
UnitOfMeasurePtr findBySymbol(const std::string &symbol) const
Returns a unit of measure identified by its symbol.
const_iterator end() const
It returns an iterator to the end of the conteiner.
#define TE_SRS_SAD69
void UOMManage()
This example shows TerraLib handles Units of Measure.
Definition: UOM.cpp:9
static UnitsOfMeasureManager & getInstance()
It returns a reference to the singleton instance.
std::map< unsigned int, UnitOfMeasurePtr >::const_iterator const_iterator
void UnitSRS()
This example test how to retrieve a SRS unit of measure.
Definition: UOM.cpp:62
double getConversion(const std::string &unitFromName, const std::string &unitToName) const
Calculates a multiplicative factor to convert from a given unit to its base unit and vice-versa...
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
#define TE_SRS_SAD69_UTM_ZONE_23S
boost::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
A set of module common examples.
UnitOfMeasurePtr find(unsigned int id) const
Returns a unit of measure identified by its identificaton.