OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimSrtmFactory.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: David Burken
6 //
7 // Description:
8 //
9 // Shuttle Radar Topography Mission (SRTM) factory to return an
10 // ossimSrtmElevSource given a ground point.
11 //
12 //----------------------------------------------------------------------------
13 // $Id: ossimSrtmFactory.cpp 16123 2009-12-17 22:07:31Z dburken $
14 
15 #include <cstdlib> /* abs() */
16 #include <iostream>
17 #include <iomanip>
18 #include <sstream>
21 #include <ossim/base/ossimTrace.h>
22 #include <ossim/base/ossimGpt.h>
29 
30 static ossimTrace traceDebug ("ossimSrtmFactory:debug");
31 
33 
36 {}
37 
40 {
41  theDirectory = dir;
42 }
43 
45 {}
46 
48 {
49 
50  if (traceDebug())
51  {
53  << "DEBUG ossimSrtmFactory::getNewElevSource: Entered..."
54  << std::endl;
55  }
56 
58 
60  {
62  << "ossimSrtmFactory::getNewElevSource: "
63  << "SRTM directory has not been set!"
64  << "\nReturning null elevation source..."
65  << std::endl;
66 
67  return srtmPtr.release();
68  }
69 
70  //---
71  // Build up a srtm file name.
72  //
73  // Standard for name is upper case 'N' and 'W' lower case "hgt" like:
74  // N27W081.hgt
75  //---
76  ossimFilename srtmFileBasename;
77 
78  int ilat = static_cast<int>(floor(gpt.latd()));
79  if (ilat < 0)
80  {
81  srtmFileBasename = "S";
82  }
83  else
84  {
85  srtmFileBasename = "N";
86  }
87 
88  ilat = abs(ilat);
90 
91  os1 << std::setfill('0') << std::setw(2) <<ilat;
92 
93  srtmFileBasename += os1.str().c_str();
94 
95  int ilon = static_cast<int>(floor(gpt.lond()));
96 
97  if (ilon < 0)
98  {
99  srtmFileBasename += "W";
100  }
101  else
102  {
103  srtmFileBasename += "E";
104  }
105 
106  ilon = abs(ilon);
108  os2 << std::setfill('0') << std::setw(3) << ilon;
109 
110  srtmFileBasename += os2.str().c_str();
111  srtmFileBasename.setExtension(".hgt");
112 
113  ossimFilename srtmFile = theDirectory.dirCat(srtmFileBasename);
114 
115  if (traceDebug())
116  {
118  << "DEBUG ossimSrtmFactory::getNewElevSource:"
119  << "\nSearching for file: " << srtmFile
120  << std::endl;
121  }
122  // ossimRefPtr<ossimIFStream> is = ossimStreamFactoryRegistry::instance()->
123  std::shared_ptr<ossim::istream> is = ossim::StreamFactoryRegistry::instance()->
124  createIstream(srtmFile);
125 
126  // Look for the file mix case, then all lower case, then all upper case.
127  if ( is )
128  {
129  if(is->fail())
130  {
131  // Try down casing the whole thing.
132  srtmFileBasename = srtmFileBasename.downcase();
133  srtmFile = theDirectory.dirCat(srtmFileBasename);
134 
136  createIstream(srtmFile);
137  if ( is )
138  {
139  if(is->fail())
140  {
141  // OK, try upcasing the whole thing.
142  srtmFileBasename = srtmFileBasename.upcase();
143  srtmFile = theDirectory.dirCat(srtmFileBasename);
145  createIstream(srtmFile);
146  }
147  }
148  }
149  }
150 
151  if ( is && (!is->fail()) )
152  {
153  is.reset();
154  srtmPtr = new ossimSrtmHandler();
155  if(srtmPtr->open(srtmFile)&&srtmPtr->pointHasCoverage(gpt) )
156  {
157  return srtmPtr.release();
158  }
159  else
160  {
161  srtmPtr = 0;
162  }
163  }
164  return srtmPtr.release();
165 }
std::ostringstream os2
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
static const ossimFilename NIL
This was taken from Wx widgets for performing touch and access date stamps.
Definition: ossimFilename.h:40
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
the elevation manager, this class returns an ossimSrtmElevSource given a ground point and some direct...
virtual ~ossimSrtmFactory()
destructor
static StreamFactoryRegistry * instance()
#define abs(a)
Definition: auxiliary.h:74
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
ossimSrtmFactory()
default constructor
virtual bool pointHasCoverage(const ossimGpt &) const
METHOD: pointIsInsideRect() Method to check if the ground point elevation is defined: ...
virtual bool open(const ossimFilename &, bool=false)
T * release()
Definition: ossimRefPtr.h:93
virtual ossimElevSource * getNewElevSource(const ossimGpt &gpt) const
Open the appropriate ossimSrtmElevSource that covers given a ground point.
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
for an srtm file.
ossimFilename dirCat(const ossimFilename &file) 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
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)