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

#include <ossimDemUtil.h>

Static Public Member Functions

static bool isUsgsDem (const ossimFilename &file)
 Does basic sanity checks to see if file is a dem. More...
 
static bool isUsgsDem (std::shared_ptr< ossim::istream > str, const std::string &connectionString)
 
static bool getRecord (ossim::istream &s, std::string &strbuf, long reclength=1024)
 Reads a single record from a DEM. More...
 
static bool getRecord (ossim::istream &s, char *buf, long reclength=1024)
 Same as getRecord above. More...
 
static long getLong (char *const strbuf, long const startpos, long const width)
 
static bool getDouble (std::string const &strbuf, long const startpos, long const width, double &val)
 

Private Member Functions

 ossimDemUtil ()
 

Detailed Description

Definition at line 25 of file ossimDemUtil.h.

Constructor & Destructor Documentation

◆ ossimDemUtil()

ossimDemUtil::ossimDemUtil ( )
private

Member Function Documentation

◆ getDouble()

bool ossimDemUtil::getDouble ( std::string const &  strbuf,
long const  startpos,
long const  width,
double &  val 
)
static

Definition at line 185 of file ossimDemUtil.cpp.

Referenced by ossimDemHeader::open(), and operator>>().

189 {
190  if ((startpos + width - 1) > (long)(strbuf.length()))
191  return false;
192 
193  // Convert FORTRAN 'D' exponent indicator to 'E'.
194  std::string tempbuf(strbuf.substr(startpos,width));
195  for (unsigned int i = 0; i < tempbuf.length(); i++)
196  if (tempbuf[i] == 'D')
197  tempbuf[i] = 'E';
198 
199  val = atof(tempbuf.c_str());
200  return true;
201 }

◆ getLong()

long ossimDemUtil::getLong ( char *const  strbuf,
long const  startpos,
long const  width 
)
static

Definition at line 203 of file ossimDemUtil.cpp.

Referenced by ossimDemHeader::open(), and operator>>().

206 {
207  char temp[1024];
208  std::strncpy(temp,strbuf+startpos,width);
209  temp[width] = '\0';
210  return atol(temp);
211 }

◆ getRecord() [1/2]

bool ossimDemUtil::getRecord ( ossim::istream s,
std::string &  strbuf,
long  reclength = 1024 
)
static

Reads a single record from a DEM.

Returns true if succesful. Returns false if EOF or error.

Definition at line 146 of file ossimDemUtil.cpp.

Referenced by ossimDemHeader::open(), and operator>>().

147 {
148  char* buf = new char[reclength + 1];
149 
150  bool flag = ossimDemUtil::getRecord(s,buf,reclength);
151  if (flag == true)
152  strbuf = buf;
153 
154  delete [] buf;
155 
156  return flag;
157 }
static bool getRecord(ossim::istream &s, std::string &strbuf, long reclength=1024)
Reads a single record from a DEM.

◆ getRecord() [2/2]

bool ossimDemUtil::getRecord ( ossim::istream s,
char *  buf,
long  reclength = 1024 
)
static

Same as getRecord above.

buf should be at least reclength+1 in size.

Definition at line 159 of file ossimDemUtil.cpp.

160 {
161  // buf is assumed to be at least reclength+1 in size.
162 
163  if (!s)
164  return false;
165 
166  long curpos = 0;
167  buf[curpos] = s.get();
168  while ((buf[curpos] != EOF) &&
169  (buf[curpos] != '\n') &&
170  (curpos < reclength-1))
171  {
172  curpos++;
173  buf[curpos] = s.get();
174  }
175  buf[curpos] = '\0';
176 
177  if (s.peek() == '\n')
178  s.get();
179 
180  return true;
181 
182 }

◆ isUsgsDem() [1/2]

bool ossimDemUtil::isUsgsDem ( const ossimFilename file)
static

Does basic sanity checks to see if file is a dem.

1) Check extension for .dem

2) Look for file.omd (ossim meta data) file containing keyword "dem_type" with value of "usgs_dem".

3) Check 512 bytes and make sure there is no binary data.

Note
There is a keyword list template stored in the templates directory: "ossim/etc/templates/usgs_dem_template.kwl"
Parameters
fileThe file to check.
Returns
true on success, false on error.

Definition at line 28 of file ossimDemUtil.cpp.

References ossimString::downcase(), ossimFilename::exists(), ossimFilename::ext(), ossimKeywordlist::find(), ossimErrorStatusInterface::getErrorStatus(), ossimErrorCodes::OSSIM_OK, and ossimFilename::setExtension().

Referenced by ossimDemInfo::open(), and ossimDemHeader::open().

29 {
30  bool result = false;
31 
32  ossimString ext = file.ext();
33  ext.downcase();
34  if (ext == "dem")
35  {
36  result = true;
37  }
38  else
39  {
40  // Look for file.omd
41  ossimFilename kwlFile = file;
42  kwlFile.setExtension("omd");
43  if (! kwlFile.exists() )
44  {
45  kwlFile.setExtension("OMD");
46  }
47 
48  if ( kwlFile.exists() )
49  {
50  ossimKeywordlist kwl(kwlFile);
51  if (kwl.getErrorStatus() == ossimErrorCodes::OSSIM_OK)
52  {
53  const char* lookup = kwl.find(DEM_TYPE_KW);
54  if (lookup)
55  {
56  ossimString s = lookup;
57  s.downcase();
58  if (s == USGS_DEM_KW)
59  {
60  result = true;
61  }
62  }
63  }
64  }
65  }
66 
67  if ( result )
68  {
69 
70  // Open up the file for reading.
71  // std::shared_ptr<ossim::istream> is = ossim::StreamFactoryRegistry::instance()->
72  // createIstream(file, std::ios_base::in | std::ios_base::binary);
73  }
74 
75  return result;
76 }
Represents serializable keyword/value map.
static const ossimErrorCode OSSIM_OK
bool exists() const
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
ossimString ext() const
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.

◆ isUsgsDem() [2/2]

bool ossimDemUtil::isUsgsDem ( std::shared_ptr< ossim::istream str,
const std::string &  connectionString 
)
static

Definition at line 78 of file ossimDemUtil.cpp.

References ossimString::downcase(), ossimFilename::exists(), ossimFilename::ext(), ossimKeywordlist::find(), ossimErrorStatusInterface::getErrorStatus(), ossimErrorCodes::OSSIM_OK, and ossimFilename::setExtension().

80 {
81  bool result = false;
82  ossimFilename tempFile = connectionString;
83  ossimString ext = tempFile.ext();
84  ext.downcase();
85  if (ext == "dem")
86  {
87  result = true;
88  }
89  else
90  {
91  // Look for file.omd
92  ossimFilename kwlFile = tempFile;
93  kwlFile.setExtension("omd");
94  if (! kwlFile.exists() )
95  {
96  kwlFile.setExtension("OMD");
97  }
98 
99  if ( kwlFile.exists() )
100  {
101  ossimKeywordlist kwl(kwlFile);
102  if (kwl.getErrorStatus() == ossimErrorCodes::OSSIM_OK)
103  {
104  const char* lookup = kwl.find(DEM_TYPE_KW);
105  if (lookup)
106  {
107  ossimString s = lookup;
108  s.downcase();
109  if (s == USGS_DEM_KW)
110  {
111  result = true;
112  }
113  }
114  }
115  }
116  }
117  if(result&&str&&str->good())
118  {
119  //---
120  // SPECIAL HACK (drb):
121  // Check some bytes and make sure there is no binary data.
122  // There are files out there with .dem extension that are binary
123  // rasters.
124  //---
125  ossim_uint8* ubuf = new ossim_uint8[512];
126  str->read((char*)ubuf, 512);
127  for (int i = 0; i < 512; ++i)
128  {
129  if (ubuf[i] > 0x7f)
130  {
131  result = false;
132  break;
133  }
134  }
135  delete [] ubuf;
136  ubuf = 0;
137  }
138  else
139  {
140  result = false;
141  }
142 
143  return result;
144 }
Represents serializable keyword/value map.
static const ossimErrorCode OSSIM_OK
bool exists() const
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
ossimString ext() const
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
unsigned char ossim_uint8

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