OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimSrtmElevationDatabase.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 //----------------------------------------------------------------------------
8 // $Id$
9 
14 #include <ossim/base/ossimTrace.h>
15 #include <sstream>
16 #include <iomanip>
17 #include <cstdlib> /* for abs(int) */
18 
19 static ossimTrace traceDebug("ossimSrtmElevationDatabase:debug");
20 
22 
25 {
26 }
27 
30 {
31 }
32 
34 {
35 }
36 
38 {
40  // duped->open(m_connectionString);
41  return duped;
42 }
43 
45 {
46  if(isSourceEnabled())
47  {
49  if(handler.valid())
50  {
51  return handler->getHeightAboveMSL(gpt); // still need to shift
52  }
53  }
54  return ossim::nan();
55 }
56 
58 {
59  double h = getHeightAboveMSL(gpt);
60  if(h != ossim::nan())
61  {
62  h += getOffsetFromEllipsoid(gpt);
63  }
64 
65  return h;
66 }
67 
68 bool ossimSrtmElevationDatabase::open(const ossimString& connectionString)
69 {
70  bool result = false;
71  ossimFilename file = ossimFilename(connectionString);
72  m_connectionString = connectionString;
73  result = openSrtmDirectory(file);
74  return result;
75 }
76 
78 {
79  bool result = false;
80  info.makeNan();
81 
82  if(pointHasCoverage(gpt))
83  {
84  result = true;
85  if(m_meanSpacing > 100.0)
86  {
87  // 30 arc second
88  info.m_absoluteCE = 20.0;
89  info.m_absoluteLE = 16.0;
90  info.m_surfaceName = "SRTM30";
91 
92  }
93  else if (m_meanSpacing > 40.0)
94  {
95  // SRTM 3 arc
96  info.m_absoluteCE = 20.0;
97  info.m_absoluteLE = 16.0;
98  info.m_surfaceName = "SRTM3";
99  }
100  else
101  {
102  // SRTM 1 arc
103  info.m_absoluteCE = 20.0;
104  info.m_absoluteLE = 10.0;
105  info.m_surfaceName = "SRTM1";
106  }
107  }
108 
109  return result;
110 }
111 
113 {
114  if(traceDebug())
115  {
116  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimSrtmElevationDatabase::open: Entered....\n";
117  }
118  if(!m_geoid.valid())
119  {
121  }
122 
123  //---
124  // Sample format:
125  // dir
126  // | |
127  // N35W121.hgt N35W121.hgt
128  //---
129  ossim_uint32 count = 0;
130  ossim_uint32 maxCount = 25;
131  if (!dir.isDir())
132  {
133  if(traceDebug())
134  {
135  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimSrtmElevationDatabase::open: Not a directory, leaving ... " << dir << "\n";
136  }
137  return false;
138  }
139 
140  ossimDirectory od(dir);
141  if (od.isOpened() == false)
142  {
143  if(traceDebug())
144  {
145  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimSrtmElevationDatabase::open: Unable to open directory " << dir << ", Leaving ... \n";
146  }
147  return false;
148  }
149 
150  ossimFilename f;
151  //ossimSrtmSupportData sd;
154  {
155  do
156  {
157  ++count;
158  if(handler->open(f))
159  {
160  m_meanSpacing = handler->getMeanSpacingMeters();
161 
162  if(traceDebug())
163  {
165  << "ossimSrtmElevationDatabase::open: Found file " << f << "\n";
166  if(!m_geoid.valid())
167  {
169  << "ossimSrtmElevationDatabase::open: Unable to load goeid grid 1996 for SRTM database\n";
170  }
171  }
172  return true;
173  }
174  }while((od.getNext(f)) &&(count < maxCount));
175  }
176 
177  if(traceDebug())
178  {
179  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimSrtmElevationDatabase::open: Leaving ... \n";
180  }
181  return false;
182 }
183 
185 {
186  int ilat = static_cast<int>(floor(gpt.latd()));
187  if (ilat < 0)
188  {
189  file = "S";
190  }
191  else
192  {
193  file = "N";
194  }
195 
196  ilat = abs(ilat);
197  std::ostringstream os1;
198 
199  os1 << std::setfill('0') << std::setw(2) <<ilat;
200 
201  file += os1.str().c_str();
202 
203  int ilon = static_cast<int>(floor(gpt.lond()));
204 
205  if (ilon < 0)
206  {
207  file += "W";
208  }
209  else
210  {
211  file += "E";
212  }
213 
214  ilon = abs(ilon);
216  os2 << std::setfill('0') << std::setw(3) << ilon;
217 
218  file += os2.str().c_str();
219  file.setExtension("hgt");
220 }
221 
222 bool ossimSrtmElevationDatabase::loadState(const ossimKeywordlist& kwl, const char* prefix )
223 {
224  return ossimElevationCellDatabase::loadState(kwl, prefix);
225 
226 #if 0 /* Avoid open which in turn opens files unnecessarily. (drb - 20170419) */
227  bool result = ossimElevationCellDatabase::loadState(kwl, prefix);
228  if(result)
229  {
231  {
232  result = open(m_connectionString);
233  }
234  else
235  {
236  // can't open the connection because it does not exists or empty
237  result = false;
238  }
239  }
240  return result;
241 #endif
242 }
243 
244 bool ossimSrtmElevationDatabase::saveState(ossimKeywordlist& kwl, const char* prefix)const
245 {
246  return ossimElevationCellDatabase::saveState(kwl, prefix);
247 }
248 
251 {
253  ossimFilename f;
254  createFullPath(f, gpt);
255  if(f.exists())
256  {
258  if (h->open(f, m_memoryMapCellsFlag))
259  {
260  result = h.get();
261  }
262  }
263  return result;
264 }
virtual ossimObject * dup() const
std::ostringstream os2
virtual bool isSourceEnabled() const
Definition: ossimSource.cpp:79
virtual double getHeightAboveMSL(const ossimGpt &)=0
Height access methods:
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual double getMeanSpacingMeters() const
METHOD: meanSpacingMeters() Implements pure virtual for.
void createRelativePath(ossimFilename &file, const ossimGpt &gpt) const
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual double getHeightAboveEllipsoid(const ossimGpt &gpt)
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
bool getFirst(ossimFilename &filename, int flags=OSSIM_DIR_DEFAULT)
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
void createFullPath(ossimFilename &file, const ossimGpt &gpt) const
#define abs(a)
Definition: auxiliary.h:74
bool isDir() const
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
bool getNext(ossimFilename &filename) const
virtual bool open(const ossimFilename &file, bool memoryMapFlag=false)
Opens a stream to the srtm cell.
bool getAccuracyInfo(ossimElevationAccuracyInfo &info, const ossimGpt &) const
virtual double getHeightAboveMSL(const ossimGpt &)
Height access methods:
virtual ossimRefPtr< ossimElevCellHandler > getOrCreateCellHandler(const ossimGpt &gpt)
bool exists() const
ossimRefPtr< ossimGeoid > m_geoid
ossimGeoid * findGeoidByShortName(const ossimString &shortName, bool caseSensitive=true)
unsigned int ossim_uint32
static ossimGeoidManager * instance()
Implements singelton pattern:
RTTI_DEF1(ossimSrtmElevationDatabase, "ossimSrtmElevationDatabase", ossimElevationCellDatabase)
for an srtm file.
virtual double getOffsetFromEllipsoid(const ossimGpt &gpt)
bool isOpened() const
virtual bool pointHasCoverage(const ossimGpt &gpt) const
METHOD: pointHasCoverage(gpt) Returns TRUE if coverage exists over gpt:
virtual bool open(const ossimString &connectionString)
Open a connection to a database.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
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 empty() const
Definition: ossimString.h:411
bool openSrtmDirectory(const ossimFilename &dir)
ossimRefPtr< ossimElevCellHandler > createCell(const ossimGpt &gpt)
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)