OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ossimWkt Class Reference

Utility/support data class to parse WKT text string to an ossimKeywordlist. More...

#include <ossimWkt.h>

Public Member Functions

 ossimWkt ()
 default constructor More...
 
 ~ossimWkt ()
 destructor More...
 
bool parse (const std::string &wkt)
 Parses string to keyword list. More...
 
const ossimKeywordlistgetKwl () const
 

Private Member Functions

bool parseWktGroup (std::istringstream &is, ossimKeywordlist &kwl)
 
bool parseObject (std::istringstream &is, const std::string &prefix, const std::string &object, ossimKeywordlist &kwl)
 
bool parseName (std::istringstream &is, const std::string &prefix, const std::string &object, ossimKeywordlist &kwl)
 
bool parseParam (std::istringstream &is, const std::string &prefix, const std::string &object, ossim_uint32 &objectIndex, ossim_uint32 &paramIndex, ossimKeywordlist &kwl)
 

Private Attributes

ossimKeywordlist m_kwl
 

Detailed Description

Utility/support data class to parse WKT text string to an ossimKeywordlist.

Example keyword list( WKT string dependent ):

PROJCS.AUTHORITY.name: EPSG PROJCS.AUTHORITY.param0: "32641" PROJCS.GEOGCS.AUTHORITY.name: EPSG PROJCS.GEOGCS.AUTHORITY.param0: "4326" PROJCS.GEOGCS.DATUM.AUTHORITY.name: EPSG PROJCS.GEOGCS.DATUM.AUTHORITY.param0: "6326" PROJCS.GEOGCS.DATUM.SPHEROID.AUTHORITY.name: EPSG PROJCS.GEOGCS.DATUM.SPHEROID.AUTHORITY.param0: "7030" PROJCS.GEOGCS.DATUM.SPHEROID.name: WGS 84 PROJCS.GEOGCS.DATUM.SPHEROID.param0: 6378137 PROJCS.GEOGCS.DATUM.SPHEROID.param1: 298.2572235630016 PROJCS.GEOGCS.DATUM.name: WGS_1984 PROJCS.GEOGCS.PRIMEM.name: Greenwich PROJCS.GEOGCS.PRIMEM.param0: 0 PROJCS.GEOGCS.UNIT.name: degree PROJCS.GEOGCS.UNIT.param0: 0.0174532925199433 PROJCS.GEOGCS.name: WGS 84 PROJCS.PARAMETER0.name: latitude_of_origin PROJCS.PARAMETER0.param0: 0 PROJCS.PARAMETER1.name: central_meridian PROJCS.PARAMETER1.param0: 63 PROJCS.PARAMETER2.name: scale_factor PROJCS.PARAMETER2.param0: 0.9996 PROJCS.PARAMETER3.name: false_easting PROJCS.PARAMETER3.param0: 500000 PROJCS.PARAMETER4.name: false_northing PROJCS.PARAMETER4.param0: 0 PROJCS.PROJECTION.name: Transverse_Mercator PROJCS.UNIT.AUTHORITY.name: EPSG PROJCS.UNIT.AUTHORITY.param0: "9001" PROJCS.UNIT.name: metre PROJCS.UNIT.param0: 1 PROJCS.name: WGS 84 / UTM zone 41N

Definition at line 68 of file ossimWkt.h.

Constructor & Destructor Documentation

◆ ossimWkt()

ossimWkt::ossimWkt ( )

default constructor

Definition at line 43 of file ossimWkt.cpp.

44  : m_kwl()
45 {
46 }
ossimKeywordlist m_kwl
Definition: ossimWkt.h:107

◆ ~ossimWkt()

ossimWkt::~ossimWkt ( )

destructor

Definition at line 48 of file ossimWkt.cpp.

49 {
50 }

Member Function Documentation

◆ getKwl()

const ossimKeywordlist & ossimWkt::getKwl ( ) const
Returns
Refeerence to keyword list.

Definition at line 63 of file ossimWkt.cpp.

References m_kwl.

Referenced by ossimWktProjectionFactory::createProjection(), and ossimMrSidReader::getGeoProjection().

64 {
65  return m_kwl;
66 }
ossimKeywordlist m_kwl
Definition: ossimWkt.h:107

◆ parse()

bool ossimWkt::parse ( const std::string &  wkt)

Parses string to keyword list.

Parameters
wktString to parse.

Definition at line 52 of file ossimWkt.cpp.

References m_kwl, and parseWktGroup().

Referenced by ossimWktProjectionFactory::createProjection(), and ossimMrSidReader::getGeoProjection().

53 {
54  bool result = false;
55  if ( wkt.size() )
56  {
57  std::istringstream is( wkt );
58  result = parseWktGroup( is, m_kwl );
59  }
60  return result;
61 }
bool parseWktGroup(std::istringstream &is, ossimKeywordlist &kwl)
Definition: ossimWkt.cpp:68
ossimKeywordlist m_kwl
Definition: ossimWkt.h:107
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32

◆ parseName()

bool ossimWkt::parseName ( std::istringstream &  is,
const std::string &  prefix,
const std::string &  object,
ossimKeywordlist kwl 
)
private

Definition at line 140 of file ossimWkt.cpp.

References ossimKeywordlist::addPair().

Referenced by parseObject().

144 {
145  bool result = false;
146  char c;
147  std::string name;
148 
149  // Find the first quote:
150  while ( is.good() )
151  {
152  is.get(c);
153  if ( is.good() )
154  {
155  if ( c == '"' )
156  {
157  break;
158  }
159  }
160  }
161 
162  // Get the name:
163  while ( is.good() )
164  {
165  is.get(c);
166  if ( is.good() )
167  {
168  if ( c != '"' )
169  {
170  name.push_back(c);
171  }
172  else
173  {
174  break; // End quote:
175  }
176  }
177  }
178 
179  if ( name.size() )
180  {
181  // Add to keyword list.
182  std::string key;
183  if ( prefix.size() )
184  {
185  key += prefix;
186  }
187  key += object;
188  key += ".name";
189  kwl.addPair( key, name );
190  result = true;
191  }
192 
193  return result;
194 }
void addPair(const std::string &key, const std::string &value, bool overwrite=true)

◆ parseObject()

bool ossimWkt::parseObject ( std::istringstream &  is,
const std::string &  prefix,
const std::string &  object,
ossimKeywordlist kwl 
)
private

Definition at line 105 of file ossimWkt.cpp.

References parseName(), and parseParam().

Referenced by parseParam(), and parseWktGroup().

109 {
110  bool result = false;
111 
112  result = parseName( is, prefix, object, kwl );
113 
114  if ( result && is.good() )
115  {
116  char c;
117  ossim_uint32 myObjectIndex = 0;
118  ossim_uint32 paramIndex = 0;
119  while ( is.good() )
120  {
121  is.get(c);
122  if ( is.good() )
123  {
124  if ( c == ',' )
125  {
126  parseParam( is, prefix, object, myObjectIndex, paramIndex, kwl );
127  }
128  else if ( (c == ']') || (c == ')') )
129  {
130  break; // End of object.
131  }
132  }
133  }
134 
135  }
136 
137  return result;
138 }
unsigned int ossim_uint32
bool parseParam(std::istringstream &is, const std::string &prefix, const std::string &object, ossim_uint32 &objectIndex, ossim_uint32 &paramIndex, ossimKeywordlist &kwl)
Definition: ossimWkt.cpp:196
bool parseName(std::istringstream &is, const std::string &prefix, const std::string &object, ossimKeywordlist &kwl)
Definition: ossimWkt.cpp:140

◆ parseParam()

bool ossimWkt::parseParam ( std::istringstream &  is,
const std::string &  prefix,
const std::string &  object,
ossim_uint32 objectIndex,
ossim_uint32 paramIndex,
ossimKeywordlist kwl 
)
private

Definition at line 196 of file ossimWkt.cpp.

References ossimKeywordlist::addPair(), parseObject(), ossimString::string(), and ossimString::toString().

Referenced by parseObject().

202 {
203  bool result = false;
204  char c;
205  std::string name;
206 
207  // Get the name:
208  while ( is.good() )
209  {
210  int i = is.peek(); // Don't gobble the trailing comma or bracket.
211 
212  if ( (i == ',') || (i == ']') || (i == ')') )
213  {
214  // End of param.
215  if ( name.size() )
216  {
217  // Add to keyword list.
218  std::string key;
219  if ( prefix.size() )
220  {
221  key += prefix;
222  }
223  key += object;
224  key += ".param";
225  key += ossimString::toString(paramIndex).string();
226  kwl.addPair( key, name );
227  name = "";
228  ++paramIndex;
229  result = true;
230  }
231 
232  break; // Next param or at end of object.
233  }
234 
235  is.get(c);
236  if ( is.good() )
237  {
238  // Look nexted object.
239  if ( (c == '[') || (c == '(') )
240  {
241  std::string myPrefix;
242  if ( prefix.size() )
243  {
244  myPrefix += prefix;
245  }
246 
247  myPrefix += object;
248 
249  myPrefix += ".";
250 
251  //---
252  // Special hack for duplicated keyword "PARAMETER"
253  //---
254  if ( name == "PARAMETER" )
255  {
256  name += ossimString::toString(objectIndex).string();
257  ++objectIndex;
258  }
259 
260  result = parseObject( is, myPrefix, name, kwl );
261 
262  name = "";
263  }
264  else
265  {
266  name.push_back(c);
267  }
268  }
269  }
270 
271  return result;
272 }
static ossimString toString(bool aValue)
Numeric to string methods.
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
bool parseObject(std::istringstream &is, const std::string &prefix, const std::string &object, ossimKeywordlist &kwl)
Definition: ossimWkt.cpp:105
const std::string & string() const
Definition: ossimString.h:414

◆ parseWktGroup()

bool ossimWkt::parseWktGroup ( std::istringstream &  is,
ossimKeywordlist kwl 
)
private

Definition at line 68 of file ossimWkt.cpp.

References parseObject().

Referenced by parse().

69 {
70  bool result = false;
71 
72  if ( is.good() )
73  {
74  char c;
75 
76  // Get the wkt group name up to '[', e.g. "PROJCS[".
77  std::string prefix = "";
78  std::string object;
79  // std::string v;
80  while ( is.good() )
81  {
82  is.get(c);
83  if ( is.good() )
84  {
85  // Look for parens or square brackets.
86  if ( (c != '[') && (c != '(') )
87  {
88  object.push_back(c);
89  }
90  else
91  {
92  result = parseObject( is, prefix, object, kwl );
93  }
94  }
95  else
96  {
97  break;
98  }
99  }
100  }
101 
102  return result;
103 }
bool parseObject(std::istringstream &is, const std::string &prefix, const std::string &object, ossimKeywordlist &kwl)
Definition: ossimWkt.cpp:105

Member Data Documentation

◆ m_kwl

ossimKeywordlist ossimWkt::m_kwl
private

Definition at line 107 of file ossimWkt.h.

Referenced by getKwl(), and parse().


The documentation for this class was generated from the following files: