All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WKTActions.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 WKTActions.cpp
22 
23  \brief A class that implements the semanthic actions to grammar rules for well known text (WKT) format for Spatial Reference Systems.
24  Basically, the class is responsible to generate a SRS element.
25 */
26 
27 // TerraLib
28 #include "Datum.h"
29 #include "Ellipsoid.h"
32 #include "WKTActions.h"
33 
34 // STL
35 #include <cstdlib>
36 
38  : m_srs(0),
39  m_projCS(0),
40  m_geoCS(0),
41  m_datum(0),
42  m_ellps(0),
43  m_authorityName(""),
44  m_authorityCode("")
45 {
46  m_sevenParams.resize(7);
47 }
48 
50 {
51 }
52 
54 {
55  m_srs = 0;
56 
57  delete m_projCS;
58  m_projCS = 0;
59 
60  delete m_geoCS;
61  m_geoCS = 0;
62 
63  delete m_datum;
64  m_datum = 0;
65 
66  delete m_ellps;
67  m_ellps = 0;
68 }
69 
71 {
72  m_projCS = new te::srs::ProjectedCoordinateSystem();
73  m_srs = m_projCS;
74 }
75 
77 {
79  m_srs = m_geoCS;
80 }
81 
83 {
84  m_datum = new te::srs::Datum();
85 }
86 
88 {
89  m_ellps = new te::srs::Ellipsoid();
90 }
91 
92 void te::srs::WKTActions::setName(const std::string& name)
93 {
94  m_srs->setName(name);
95 }
96 
97 void te::srs::WKTActions::setPrimeMeridian(const double& primem)
98 {
99  m_geoCS->setPrimem(primem);
100 }
101 
102 void te::srs::WKTActions::setUnitName(const std::string& name)
103 {
104  m_srs->setUnitName(name);
105 }
106 
108 {}
109 
110 void te::srs::WKTActions::setDatumName(const std::string& name)
111 {
112  m_datum->setName(name);
113 }
114 
115 void te::srs::WKTActions::setDx(const double& dx)
116 {
117  m_sevenParams[0] = dx;
118 }
119 
120 void te::srs::WKTActions::setDy(const double& dy)
121 {
122  m_sevenParams[1] = dy;
123 }
124 
125 void te::srs::WKTActions::setDz(const double& dz)
126 {
127  m_sevenParams[2] = dz;
128 }
129 
130 void te::srs::WKTActions::setEx(const double& ex)
131 {
132  m_sevenParams[3] = ex;
133 }
134 
135 void te::srs::WKTActions::setEy(const double& ey)
136 {
137  m_sevenParams[4] = ey;
138 }
139 
140 void te::srs::WKTActions::setEz(const double& ez)
141 {
142  m_sevenParams[5] = ez;
143 }
144 
145 void te::srs::WKTActions::setPPM(const double& ppm)
146 {
147  m_sevenParams[6] = ppm;
148 }
149 
151 {
152  m_datum->setToWGS84Params(m_sevenParams);
153 }
154 
155 void te::srs::WKTActions::setAuthorityName(const std::string& name)
156 {
157  m_authorityName = name;
158 }
159 
160 void te::srs::WKTActions::setAuthorityCode(const std::string& code)
161 {
162  m_authorityCode = code;
163 }
164 
165 void te::srs::WKTActions::setSpheroidName(const std::string& name)
166 {
167  m_ellps->setName(name);
168 }
169 
171 {
172  m_ellps->setRadium(rad);
173 }
174 
175 void te::srs::WKTActions::setInverseFlattening(const double& invflat)
176 {
177  m_ellps->setInverseFlattening(invflat);
178 }
179 
180 void te::srs::WKTActions::setProjectionName(const std::string& name)
181 {
182  m_projCS->setProjection(name);
183 }
184 
185 void te::srs::WKTActions::setParameter(const std::string& name)
186 {
187  m_parameter.first = name;
188 }
189 
190 void te::srs::WKTActions::setParameterValue(const double& value)
191 {
192  m_parameter.second = value;
193  m_params.insert(m_parameter);
194 }
195 
196 void te::srs::WKTActions::setAxisName(const std::string& name)
197 {
198  m_axis.first = name;
199 }
200 
201 void te::srs::WKTActions::setAxisValue(const std::string& value)
202 {
203  m_axis.second = value;
204  m_axes.insert(m_axis);
205 }
206 
208 {
209  m_datum->setEllipsoid(m_ellps);
210  m_ellps = 0;
211 }
212 
214 {
215  m_geoCS->setDatum(m_datum);
216  m_datum = 0;
217 }
218 
220 {
221  if(!m_authorityName.empty() && !m_authorityCode.empty()) // The parser read AUTHORITY[name, code]?
222  {
223  m_geoCS->setSRID(atoi(m_authorityCode.c_str()), m_authorityName);
224 
225 // clears authority to the next element use it
226  m_authorityName.clear();
227  m_authorityCode.clear();
228  }
229 
230  if(m_projCS == 0)
231  {
232  m_geoCS = 0; // The reference is now only in m_srs
233  return;
234  }
235 
236  m_projCS->setGeographicCoordinateSystem(m_geoCS);
237  m_srs = m_projCS;
238 }
239 
241 {
242  if(!m_authorityName.empty() && !m_authorityCode.empty()) // The parser read AUTHORITY[name, code]?
243  {
244  m_projCS->setSRID(atoi(m_authorityCode.c_str()), m_authorityName);
245  // Clears authority to the next element use it
246  m_authorityName.clear();
247  m_authorityCode.clear();
248  }
249 
250  m_projCS->setParameters(m_params);
251  m_projCS = 0; // The reference is now only in m_srs
252 }
253 
255 {
256  return m_srs;
257 }
258 
void endProjectedCoordinateSystem()
Definition: WKTActions.cpp:240
void reset()
This method resets the Action class to original state.
Definition: WKTActions.cpp:53
A geodetic datum defines a reference to measure Earth's surface.
Definition: Datum.h:35
void setSpheroidName(const std::string &name)
Definition: WKTActions.cpp:165
This file contains the support to represent a geodetic datum.
A Geographic Coordinate System (GEOGCS).
void setPrimeMeridian(const double &primem)
Definition: WKTActions.cpp:97
void setAuthorityName(const std::string &name)
Definition: WKTActions.cpp:155
~WKTActions()
Destructor.
Definition: WKTActions.cpp:49
void setAxisValue(const std::string &value)
Definition: WKTActions.cpp:201
void setConversionFactor(const double &f)
Definition: WKTActions.cpp:107
void setEx(const double &ex)
Definition: WKTActions.cpp:130
void createGeographicCoordinateSystem()
Definition: WKTActions.cpp:76
A Spatial Reference System, also known as a Coordinate System.
std::vector< double > m_sevenParams
Definition: WKTActions.h:152
void setUnitName(const std::string &name)
Definition: WKTActions.cpp:102
This file contains the structs necessary to represent a ProjectedCoordinateSystem.
void setPPM(const double &ppm)
Definition: WKTActions.cpp:145
void setEz(const double &ez)
Definition: WKTActions.cpp:140
void setDx(const double &dx)
Definition: WKTActions.cpp:115
void setProjectionName(const std::string &name)
Definition: WKTActions.cpp:180
void setDy(const double &dy)
Definition: WKTActions.cpp:120
void setDatumName(const std::string &name)
Definition: WKTActions.cpp:110
WKTActions()
Default constructor.
Definition: WKTActions.cpp:37
void setAxisName(const std::string &name)
Definition: WKTActions.cpp:196
void setSemiMajorAxis(const double &rad)
Definition: WKTActions.cpp:170
This file contains the structs necessary to represent a GeographicCoordinateSystem.
A Projected Coordinate System (PROJCS).
A reference ellipsoid is an approximation of the Earth's surface as a squashed sphere.
Definition: Ellipsoid.h:50
SpatialReferenceSystem * getSRS()
It returns the SRS generated by the parser process.
Definition: WKTActions.cpp:254
void setParameter(const std::string &name)
Definition: WKTActions.cpp:185
void endGeographicCoordinateSystem()
Definition: WKTActions.cpp:219
void setName(const std::string &name)
Definition: WKTActions.cpp:92
void setParameterValue(const double &value)
Definition: WKTActions.cpp:190
void setEy(const double &ey)
Definition: WKTActions.cpp:135
This file contains the structs necessary to model an Ellipsoid.
void setDz(const double &dz)
Definition: WKTActions.cpp:125
void createProjectedCoordinateSystem()
Definition: WKTActions.cpp:70
void setAuthorityCode(const std::string &code)
Definition: WKTActions.cpp:160
void setInverseFlattening(const double &invflat)
Definition: WKTActions.cpp:175