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

Support data container for FGDC in text format. More...

#include <ossimFgdcTxtDoc.h>

Inheritance diagram for ossimFgdcTxtDoc:
ossimReferenced

Public Member Functions

 ossimFgdcTxtDoc ()
 default constructor More...
 
virtual ~ossimFgdcTxtDoc ()
 virtual destructor More...
 
bool open (const ossimFilename &file)
 open method. More...
 
void close ()
 Close method. More...
 
void getProjection (ossimRefPtr< ossimProjection > &proj)
 Gets projection from Spatial_Reference_Information block. More...
 
void getAltitudeDistanceUnits (std::string &units) const
 Gets units from Altitude_Distance_Units. More...
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 

Private Member Functions

void getProjectionV1 (std::ifstream &str, ossimRefPtr< ossimProjection > &proj)
 Gets projection from Spatial_Reference_Information block for version FGDC-STD-001-1998. More...
 
bool findKey (std::ifstream &str, const std::string &key)
 Finds key and returns true if present. More...
 
bool findKey (std::ifstream &str, bool seekBack, const std::string &key, std::string &value)
 Finds key and returns and intializes value if present. More...
 
void getOssimDatum (const std::string &fgdcDatumString, std::string &ossimDatumCode) const
 Gets ossim datum string from fgdc datum string. More...
 

Private Attributes

ossimRefPtr< ossimKeywordlistm_kwl
 

Additional Inherited Members

- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Detailed Description

Support data container for FGDC in text format.

Has minimum parse support to get Spatial_Reference_Information section to extract projection information.

TODO: Make an ossimFgdcBase and consolidate code from ossimFgdcXmlDoc and this class. (drb - 15 Aug. 2011)

Definition at line 38 of file ossimFgdcTxtDoc.h.

Constructor & Destructor Documentation

◆ ossimFgdcTxtDoc()

ossimFgdcTxtDoc::ossimFgdcTxtDoc ( )

default constructor

Definition at line 35 of file ossimFgdcTxtDoc.cpp.

36  : m_kwl( new ossimKeywordlist() )
37 {
38 }
Represents serializable keyword/value map.
ossimRefPtr< ossimKeywordlist > m_kwl

◆ ~ossimFgdcTxtDoc()

ossimFgdcTxtDoc::~ossimFgdcTxtDoc ( )
virtual

virtual destructor

Definition at line 40 of file ossimFgdcTxtDoc.cpp.

References m_kwl.

41 {
42  m_kwl = 0; // Not a leak, m_kwl is a ossimRefPtr.
43 }
ossimRefPtr< ossimKeywordlist > m_kwl

Member Function Documentation

◆ close()

void ossimFgdcTxtDoc::close ( )

Close method.

This doesn't really do anything. Here only because I think every open() should have a matching close().

Definition at line 77 of file ossimFgdcTxtDoc.cpp.

References ossimKeywordlist::clear(), and m_kwl.

78 {
79  m_kwl->clear();
80 }
ossimRefPtr< ossimKeywordlist > m_kwl

◆ findKey() [1/2]

bool ossimFgdcTxtDoc::findKey ( std::ifstream &  str,
const std::string &  key 
)
private

Finds key and returns true if present.

Leaves stream at position of last getline.

Parameters
strStream to read from.
keyKey to find.
Returns
true if present false if not.

Definition at line 208 of file ossimFgdcTxtDoc.cpp.

References getline(), ossimString::size(), ossimString::string(), and ossimString::trim().

Referenced by getProjectionV1(), and open().

209 {
210  bool result = false;
211  ossimString line;
212  while ( !str.eof() )
213  {
214  // Read line:
215  std::getline( str, line.string() );
216  if ( line.size() )
217  {
218  // Eat white space.
219  line.trim();
220  if ( line.string() == key )
221  {
222  result = true;
223  break;
224  }
225  }
226  }
227  return result;
228 }
std::istream & getline(std::istream &is, ossimString &str, char delim)
Definition: ossimString.h:916
std::string::size_type size() const
Definition: ossimString.h:405
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
const std::string & string() const
Definition: ossimString.h:414

◆ findKey() [2/2]

bool ossimFgdcTxtDoc::findKey ( std::ifstream &  str,
bool  seekBack,
const std::string &  key,
std::string &  value 
)
private

Finds key and returns and intializes value if present.

Stream position at end of call is dependent on seekBack flag.

Parameters
strStream to read from.
seekBackIf true the stream will be repositioned to original position at beginning of the call.
keyKey to find.
valueIntialized with value if key is found.
Returns
true if present false if not.

Definition at line 230 of file ossimFgdcTxtDoc.cpp.

References ossimString::clear(), getline(), ossimString::size(), size, ossimString::split(), ossimString::string(), and ossimString::trim().

232 {
233  bool result = false;
234 
235  std::vector<ossimString> fgdcKeyValue;
236  ossimString separator = ":";
237  ossimString line;
238  ossimKeywordlist projectionKwl;
239  std::streampos currentPosition = str.tellg();
240 
241  while ( !str.eof() )
242  {
243  // Read line:
244  std::getline( str, line.string() );
245 
246  if ( line.size() )
247  {
248  // Eat white space.
249  line.trim();
250 
251  // Split between ':'
252  fgdcKeyValue.clear();
253  line.split(fgdcKeyValue, separator, false);
254  if ( fgdcKeyValue.size() == 2 )
255  {
256  fgdcKeyValue[0].trim();
257 
258  if ( fgdcKeyValue[0].size() )
259  {
260  if ( fgdcKeyValue[0] == key )
261  {
262  // Found it. Initialize value and get out.
263  result = true;
264  fgdcKeyValue[1].trim();
265  value = fgdcKeyValue[1].string();
266  break; // from while loop.
267  }
268  }
269  }
270  }
271  }
272 
273  if ( seekBack )
274  {
275  str.seekg(currentPosition);
276  }
277 
278  return result;
279 }
void clear()
Erases the entire container.
Definition: ossimString.h:432
Represents serializable keyword/value map.
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
std::istream & getline(std::istream &is, ossimString &str, char delim)
Definition: ossimString.h:916
yy_size_t size
std::string::size_type size() const
Definition: ossimString.h:405
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
const std::string & string() const
Definition: ossimString.h:414

◆ getAltitudeDistanceUnits()

void ossimFgdcTxtDoc::getAltitudeDistanceUnits ( std::string &  units) const

Gets units from Altitude_Distance_Units.

Returns
Units if found, OSSIM_UNIT_UNKNOWN if not.

Definition at line 120 of file ossimFgdcTxtDoc.cpp.

References ossimKeywordlist::findKey(), and m_kwl.

121 {
122  units = m_kwl->findKey( ALTITUDE_DISTANCE_UNITS_KW );
123 }
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
ossimRefPtr< ossimKeywordlist > m_kwl

◆ getOssimDatum()

void ossimFgdcTxtDoc::getOssimDatum ( const std::string &  fgdcDatumString,
std::string &  ossimDatumCode 
) const
private

Gets ossim datum string from fgdc datum string.

Definition at line 282 of file ossimFgdcTxtDoc.cpp.

References ossimString::downcase(), and ossimString::string().

Referenced by getProjectionV1().

284 {
285  ossimString horizdn = fgdcDatumString;
286  horizdn.downcase();
287  if ( horizdn == "north american datum of 1983" )
288  {
289  ossimDatumCode = "NAR-C";
290  }
291  else if ( horizdn == "north american datum of 1927" )
292  {
293  ossimDatumCode = "NAS-C";
294  }
295  else if ( horizdn == "wgs84")
296  {
297  ossimDatumCode = "WGE";
298  }
299  else
300  {
301  // Exception thrown so that we see that we are not handling a datum.
302  std::string errMsg = "ossimFgdcTxtDoc::getOssimDatum ERROR: Unhandled datum: ";
303  errMsg += horizdn.string();
304  throw ossimException(errMsg);
305  }
306 }
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
const std::string & string() const
Definition: ossimString.h:414

◆ getProjection()

void ossimFgdcTxtDoc::getProjection ( ossimRefPtr< ossimProjection > &  proj)

Gets projection from Spatial_Reference_Information block.

Parameters
projIntialized by this method. Set to null on projection cannot be created.

Definition at line 82 of file ossimFgdcTxtDoc.cpp.

References ossimKeywordlist::findKey(), and m_kwl.

83 {
84  static const char M[] = "ossimFgdcTxtDoc::getProjection";
85 
86  try
87  {
88  // Get the file name:
89  std::string file = m_kwl->findKey( FGDC_FILE_KW );
90  if ( file.size() )
91  {
92  // Get the version:
93  std::string version = m_kwl->findKey( FGDC_VERSION_KW );
94  if ( version.size() )
95  {
96  // Note: Currently only coded against FGDC-STD-001-1998
97  if ( version == FGDC_VERSION_001_1998)
98  {
99  // Open the file:
100  std::ifstream str( file.c_str(), std::ios_base::in );
101  if ( str.good() )
102  {
103  // Find the Spatial_Reference_Information section:
104  std::string key = "Spatial_Reference_Information:";
105  if ( findKey( str, key ) )
106  {
107  getProjectionV1( str, proj );
108  }
109  }
110  }
111  }
112  }
113  }
114  catch (const ossimException& e)
115  {
116  ossimNotify(ossimNotifyLevel_WARN) << M << " caught exception:\n" << e.what() << std::endl;
117  }
118 }
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
void getProjectionV1(std::ifstream &str, ossimRefPtr< ossimProjection > &proj)
Gets projection from Spatial_Reference_Information block for version FGDC-STD-001-1998.
virtual const char * what() const
Returns the error message.
ossimRefPtr< ossimKeywordlist > m_kwl
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
bool findKey(std::ifstream &str, const std::string &key)
Finds key and returns true if present.

◆ getProjectionV1()

void ossimFgdcTxtDoc::getProjectionV1 ( std::ifstream &  str,
ossimRefPtr< ossimProjection > &  proj 
)
private

Gets projection from Spatial_Reference_Information block for version FGDC-STD-001-1998.

Parameters
strStream to read from.
projIntialized by this method. Set to null on projection cannot be created.

Definition at line 125 of file ossimFgdcTxtDoc.cpp.

References ossimKeywordlist::addPair(), ossimMapProjectionFactory::createProjection(), findKey(), getOssimDatum(), ossimKeywordlist::getSize(), ossimMapProjectionFactory::instance(), and ossimString::toFloat64().

126 {
127  static const char M[] = "ossimFgdcTxtDoc::getProjectionV1";
128 
129  std::string fgdcKey;
130  std::string fgdcValue;
131  std::string key;
132  std::string value;
133  ossimKeywordlist projectionKwl;
134 
135  fgdcKey = "Grid_Coordinate_System_Name";
136  if ( findKey( str, true, fgdcKey, fgdcValue ) )
137  {
138  if ( fgdcValue == "Universal Transverse Mercator" )
139  {
140  key = "type";
141  value = "ossimUtmProjection";
142  projectionKwl.addPair(key, value);
143 
144  // Get the zone:
145  fgdcKey = "UTM_Zone_Number";
146  if ( findKey( str, true, fgdcKey, fgdcValue ) )
147  {
148  key = "zone";
149  value = fgdcValue;
150  projectionKwl.addPair(key, value);
151  }
152  else
153  {
154  std::string errMsg = M;
155  errMsg += " ERROR: Could not determine utm zone!";
156  throw ossimException(errMsg);
157  }
158 
159  // Check for Southern hemisphere.
160  fgdcKey = "False_Northing";
161  if ( findKey( str, true, fgdcKey, fgdcValue ) )
162  {
163  key = "hemisphere";
164 
165  // Hemisphere( North false easting = 0.0, South = 10000000):
166  ossim_float64 f = ossimString::toFloat64( fgdcKey.c_str() );
167  if ( f == 0.0 )
168  {
169  value = "N";
170  }
171  else
172  {
173  value = "S";
174  }
175  projectionKwl.addPair(key, value);
176  }
177 
178  } // UTM section:
179  else
180  {
181  // Exception thrown so that we see that we are not handling a projection.
182  std::string errMsg = M;
183  errMsg += "ERROR: Unhandled projection: ";
184  errMsg += fgdcValue;
185  throw ossimException(errMsg);
186  }
187 
188  fgdcKey = "Horizontal_Datum_Name";
189  if ( findKey( str, true, fgdcKey, fgdcValue ) )
190  {
191  getOssimDatum( fgdcValue, value );
192  key = "datum";
193  projectionKwl.addPair(key, value);
194  }
195 
196  } // Matches: findKey( Grid_Coordinate_System_Name )
197 
198  if ( projectionKwl.getSize() )
199  {
200  proj = ossimMapProjectionFactory::instance()->createProjection(projectionKwl);
201  }
202  else
203  {
204  proj = 0;
205  }
206 }
virtual ossimProjection * createProjection(const ossimFilename &filename, ossim_uint32 entryIdx) const
takes a filename.
Represents serializable keyword/value map.
static ossimMapProjectionFactory * instance()
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
double ossim_float64
void getOssimDatum(const std::string &fgdcDatumString, std::string &ossimDatumCode) const
Gets ossim datum string from fgdc datum string.
ossim_float64 toFloat64() const
ossim_uint32 getSize() const
bool findKey(std::ifstream &str, const std::string &key)
Finds key and returns true if present.

◆ open()

bool ossimFgdcTxtDoc::open ( const ossimFilename file)

open method.

Parameters
fileFile name to open.
Returns
true on success false on error.

Definition at line 45 of file ossimFgdcTxtDoc.cpp.

References ossimString::c_str(), and findKey().

46 {
47  bool result = false;
48 
49  // Open the file:
50  std::ifstream str( file.c_str(), std::ios_base::in );
51 
52  if ( str.good() )
53  {
54  std::string key = "Metadata_Standard_Version";
55  std::string value;
56  if ( findKey( str, true, key, value ) )
57  {
58  if ( value == FGDC_VERSION_001_1998 )
59  {
60  result = true;
61  m_kwl->addPair( FGDC_VERSION_KW, value );
62  m_kwl->addPair( FGDC_FILE_KW, file.string() );
63 
64  // Store for getAltitudeDistanceUnits() method if key found.
65  key = "Altitude_Distance_Units";
66  if ( findKey( str, false, key, value ) )
67  {
68  m_kwl->addPair( ALTITUDE_DISTANCE_UNITS_KW, value );
69  }
70  }
71  }
72  }
73 
74  return result;
75 }
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
ossimRefPtr< ossimKeywordlist > m_kwl
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool findKey(std::ifstream &str, const std::string &key)
Finds key and returns true if present.
const std::string & string() const
Definition: ossimString.h:414

Member Data Documentation

◆ m_kwl

ossimRefPtr<ossimKeywordlist> ossimFgdcTxtDoc::m_kwl
private

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