All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Datum.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/srs/Datum.cpp
22  */
23 
24 // TerraLib
25 #include "Datum.h"
26 #include "Ellipsoid.h"
27 
28 // STL
29 #include <cassert>
30 #include <sstream>
31 
32 te::srs::Datum::Datum(const std::string& name, te::srs::Ellipsoid* ellps):
33  m_name(name),
34  m_ellipsoid(ellps)
35 {}
36 
38 {
39  delete m_ellipsoid;
40 }
41 
42 const std::string& te::srs::Datum::getName() const
43 {
44  return m_name;
45 }
46 
47 void te::srs::Datum::setName(const std::string& name)
48 {
49  m_name = name;
50 }
51 
53 {
54  return m_ellipsoid;
55 }
56 
58 {
59  assert(ellps);
60 
61  delete m_ellipsoid;
62  m_ellipsoid = ellps;
63 }
64 
65 void te::srs::Datum::setToWGS84Params(const std::vector<double>& params)
66 {
67  m_towgs84.clear();
68 
69  size_t i;
70  for (i=0; i<params.size(); m_towgs84.push_back(params[i]), ++i);
71  while (i<6)
72  {
73  m_towgs84.push_back(0.0);
74  ++i;
75  }
76 }
77 
78 const std::vector<double>& te::srs::Datum::getToWGS84Params() const
79 {
80  return m_towgs84;
81 }
82 
83 std::string te::srs::Datum::getWKT() const
84 {
85  std::ostringstream sstr;
86  sstr.precision(10);
87 
88  std::string wkt = "DATUM[\"";
89  wkt += m_name;
90  wkt += "\",";
91  wkt += m_ellipsoid->getWKT();
92  if (!m_towgs84.empty())
93  {
94  wkt += ",TOWGS84[";
95  sstr << m_towgs84[0];
96  wkt += sstr.str();
97  sstr.str("");
98  size_t i;
99  for (i=1; i<m_towgs84.size(); ++i)
100  {
101  if (i>6)
102  break;
103  sstr << m_towgs84[i];
104  wkt += ",";
105  wkt += sstr.str();
106  sstr.str("");
107  }
108  wkt += "]";
109  }
110  wkt += "]";
111  return wkt;
112 }
This file contains the support to represent a geodetic datum.
void setToWGS84Params(const std::vector< double > &params)
Sets the Datum shifting parameters relative to WGS84.
Definition: Datum.cpp:65
Datum(const std::string &name="", Ellipsoid *ellps=0)
Constructor with parameters.
Definition: Datum.cpp:32
const std::string & getName() const
Returns the Datum name.
Definition: Datum.cpp:42
void setEllipsoid(Ellipsoid *ellps)
Sets the Ellipsoid associated to the Datum.
Definition: Datum.cpp:57
~Datum()
Destructor.
Definition: Datum.cpp:37
const Ellipsoid * getEllipsoid() const
Returns the Ellipsoid associated to the Datum.
Definition: Datum.cpp:52
std::string getWKT() const
Returns a WKT string that represent the Datum.
Definition: Datum.cpp:83
void setName(const std::string &name)
Sets the Datum name.
Definition: Datum.cpp:47
const std::vector< double > & getToWGS84Params() const
Returns the WGS84 shifting parameters.
Definition: Datum.cpp:78
A reference ellipsoid is an approximation of the Earth's surface as a squashed sphere.
Definition: Ellipsoid.h:50
This file contains the structs necessary to model an Ellipsoid.