OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimDtedUhl.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Ken Melero
8 //
9 // Description: This class gives access to the User Header Label
10 // (UHL) of a DTED Level 1 file.
11 //
12 //********************************************************************
13 // $Id: ossimDtedUhl.cpp 23277 2015-04-24 21:02:24Z rashadkm $
14 
15 #include <cstdlib>
16 #include <iostream>
17 #include <iomanip>
18 #include <fstream>
19 #include <string>
20 
22 #include <ossim/base/ossimNotify.h>
25 
27 {
28 
29 }
30 
31 ossimDtedUhl::ossimDtedUhl(std::shared_ptr<ossim::istream>& str, ossim_int64 offset)
32  :
33  theRecSen(),
34  theField2(),
35  theLonOrigin(),
36  theLatOrigin(),
37  theLonInterval(),
38  theLatInterval(),
39  theAbsoluteLE(),
40  theSecurityCode(),
41  theNumLonLines(),
42  theNumLatPoints(),
43  theMultipleAccuracy(),
44  theStartOffset(0),
45  theStopOffset(0)
46 {
47  if(str)
48  {
49  str->seekg(offset);
50  parse(*str);
51  }
52  else
53  {
55  }
56 }
57 
58 
59 //**************************************************************************
60 // ossimDtedUhl::parse()
61 //**************************************************************************
63 {
65  theStartOffset = in.tellg();
67  // Parse theRecSen
68  in.read(theRecSen, FIELD1_SIZE);
69  theRecSen[FIELD1_SIZE] = '\0';
70 
71  if(!(strncmp(theRecSen, "UHL", 3) == 0))
72  {
73  // Not a user header label.
75  in.seekg(theStartOffset);
76  return;
77  }
78 
79  // Parse Field 2
80  in.read(theField2, FIELD2_SIZE);
81  theField2[FIELD2_SIZE] = '\0';
82 
83  // Parse theLonOrigin
84  in.read(theLonOrigin, FIELD3_SIZE);
85  theLonOrigin[FIELD3_SIZE] = '\0';
86 
87  // Parse theLatOrigin
88  in.read(theLatOrigin, FIELD4_SIZE);
89  theLatOrigin[FIELD4_SIZE] = '\0';
90 
91  // Parse theLonInterval
92  in.read(theLonInterval, FIELD5_SIZE);
94 
95  // Parse theLatInterval
96  in.read(theLatInterval, FIELD6_SIZE);
98 
99  // Parse theAbsoluteLE
100  in.read(theAbsoluteLE, FIELD7_SIZE);
101  theAbsoluteLE[FIELD7_SIZE] = '\0';
102 
103  // Parse theSecurityCode
104  in.read(theSecurityCode, FIELD8_SIZE);
106 
107  // Parse Field 9
108  in.read(theField9, FIELD9_SIZE);
109  theField9[FIELD9_SIZE] = '\0';
110 
111  // Parse theNumLonLines
112  in.read(theNumLonLines, FIELD10_SIZE);
114 
115  // Parse theNumLatPoints
116  in.read(theNumLatPoints, FIELD11_SIZE);
118 
119  // Parse theMultipleAccuracy
122 
123  // Field 13 not parsed as it's unused.
124  in.ignore(FIELD13_SIZE);
125  // Set the stop offset.
127 }
128 
130  const ossimString& /* name */) const
131 {
132  ossimRefPtr<ossimProperty> result = 0;
133  return result;
134 }
135 
137  std::vector<ossimString>& propertyNames) const
138 {
139  propertyNames.push_back(ossimString("dted_uhl_record"));
140 }
141 
143 {
144  return theRecSen;
145 }
146 
148 {
150 }
151 
153 {
155 }
156 
158 {
160 }
161 
163 {
165 }
166 
167 double ossimDtedUhl::degreesFromString(const char* str) const
168 {
169  // Parse the string: DDDMMMSSH
170  if (!str)
171  {
173  << "FATAL ossimDtedUhl::degreesFromString: "
174  << "Null pointer passed to method!" << std::endl;
175  return 0.0;
176  }
177 
178  if (strlen(str) < 8)
179  {
181  << "FATAL ossimDtedUhl::decimalDegreesFromString:"
182  << "String not big enough!" << std::endl;
183  return 0.0;
184  }
185 
186  double d = ((str[0]-'0')*100 + (str[1]-'0')*10 + (str[2]-'0') +
187  (str[3]-'0')/6.0 + (str[4]-'0')/60.0 +
188  (str[5]-'0')/360.0 + (str[6]-'0')/3600.0);
189 
190  if ( (str[7] == 'S') || (str[7] == 's') ||
191  (str[7] == 'W') || (str[7] == 'w') )
192  {
193  d *= -1.0;
194  }
195 
196  return d;
197 }
198 
199 double ossimDtedUhl::spacingFromString(const char* str) const
200 {
201  // Parse the string: SSSS (tenths of a second)
202  if (!str)
203  {
205  << "FATAL ossimDtedUhl::decimalDegreesFromString: "
206  << "Null pointer passed to method!" << std::endl;
207  return 0.0;
208  }
209 
210  return atof(str) / 36000.0; // return 10ths of second as decimal degrees.
211 }
212 
214 {
215  return strtod(theAbsoluteLE, NULL);
216 }
217 
219 {
220  return theSecurityCode;
221 }
222 
224 {
225  return atoi(theNumLonLines);
226 }
227 
229 {
230  return atoi(theNumLatPoints);
231 }
232 
234 {
235  return atoi(theMultipleAccuracy);
236 }
237 
239 {
240  return theStartOffset;
241 }
242 
244 {
245  return theStopOffset;
246 }
247 
248 //**************************************************************************
249 // operator <<
250 //**************************************************************************
252 {
253  std::string prefix;
254  return uhl.print(out, prefix);
255 }
256 
258  const std::string& prefix) const
259 {
260  std::string pfx = prefix;
261  pfx += "uhl.";
262 
263  out << setiosflags(ios::left)
264  << pfx << setw(28) << "recognition_sentinel:" << theRecSen << "\n"
265  << pfx << setw(28) << "lon_origin:" << theLonOrigin << "\n"
266  << pfx << setw(28) << "lat_origin:" << theLatOrigin << "\n"
267  << pfx << setw(28) << "lon_interval:" << theLonInterval << "\n"
268  << pfx << setw(28) << "lat_interval:" << theLatInterval << "\n"
269  << pfx << setw(28) << "absolute_le:" << theAbsoluteLE << "\n"
270  << pfx << setw(28) << "security_code:" << theSecurityCode << "\n"
271  << pfx << setw(28) << "number_of_lat_points:" << theNumLatPoints << "\n"
272  << pfx << setw(28) << "number_of_lon_lines:" << theNumLonLines << "\n"
273  << pfx << setw(28) << "multiple_accuracy:"
274  << theMultipleAccuracy << "\n"
275  << pfx << setw(28) << "start_offset:" << theStartOffset << "\n"
276  << pfx << setw(28) << "stop_offset:" << theStopOffset
277  << std::endl;
278 
279  return out;
280 }
281 
283 {
284 }
285 
287 {
288  return rhs;
289 }
290 
ossim_int32 mulitpleAccuracy() const
double latOrigin() const
double latInterval() const
ossimString recognitionSentinel() const
double degreesFromString(const char *str) const
char theMultipleAccuracy[FIELD12_SIZE+1]
Definition: ossimDtedUhl.h:126
char theAbsoluteLE[FIELD7_SIZE+1]
Definition: ossimDtedUhl.h:121
ossimString securityCode() const
static const ossimErrorCode OSSIM_ERROR
std::ostream & print(std::ostream &out, const std::string &prefix) const
print method that outputs a key/value type format adding prefix to keys.
ossim_int32 numLatPoints() const
char theRecSen[FIELD1_SIZE+1]
Definition: ossimDtedUhl.h:115
void getPropertyNames(std::vector< ossimString > &propertyNames) const
Adds this class&#39;s properties to list.
char theNumLatPoints[FIELD11_SIZE+1]
Definition: ossimDtedUhl.h:125
std::ostream & operator<<(std::ostream &out, const ossimDtedUhl &uhl)
ossim_int32 stopOffset() const
char theField2[FIELD2_SIZE+1]
Definition: ossimDtedUhl.h:116
char theField9[FIELD9_SIZE+1]
Definition: ossimDtedUhl.h:123
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
ossim_int32 theStartOffset
Definition: ossimDtedUhl.h:128
ossim_int32 startOffset() const
char theLonOrigin[FIELD3_SIZE+1]
Definition: ossimDtedUhl.h:117
char theLatOrigin[FIELD4_SIZE+1]
Definition: ossimDtedUhl.h:118
long long ossim_int64
char theLatInterval[FIELD6_SIZE+1]
Definition: ossimDtedUhl.h:120
double spacingFromString(const char *str) const
void parse(std::istream &in)
double lonOrigin() const
ossim_int32 theStopOffset
Definition: ossimDtedUhl.h:129
const ossimDtedUhl & operator=(const ossimDtedUhl &rhs)
char theLonInterval[FIELD5_SIZE+1]
Definition: ossimDtedUhl.h:119
ossim_int32 numLonLines() const
ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
Gets a property for name.
char theNumLonLines[FIELD10_SIZE+1]
Definition: ossimDtedUhl.h:124
double absoluteLE() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
double lonInterval() const
char theSecurityCode[FIELD8_SIZE+1]
Definition: ossimDtedUhl.h:122
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
int ossim_int32