OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGeoidNgs.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 //
7 //*******************************************************************
8 // $Id: ossimGeoidNgs.cpp 22900 2014-09-30 09:56:11Z dburken $
10 
11 #include <ossim/base/ossimCommon.h>
13 #include <ossim/base/ossimString.h>
15 #include <ossim/base/ossimGpt.h>
17 #include <ossim/base/ossimTrace.h>
19 
20 
21 #include <stdlib.h> /* standard C general utility library */
22 #include <iostream>
23 #include <fstream>
24 using namespace std;
25 
26 RTTI_DEF1(ossimGeoidNgs, "ossimGeoidNgs", ossimGeoid)
27 
28 static ossimTrace traceDebug ("ossimGeoidNgs:debug");
29 
31  :theShortName("")
32 {
33 }
34 
36  ossimByteOrder /* byteOrder */)
37 {
38  open(dir);
39 }
40 
41 
44 {
45  if (!dir.isDir())
46  {
47  return false;
48  }
49 
50  if(dir.isDir())
51  {
53 
54  if(dir.dirCat("g2003u01.bin").exists())
55  {
56  theShortName = "geoid2003";
57  addFile(dir.dirCat("g2003u01.bin"), byteOrder);
58  }
59  if(dir.dirCat("g2003u02.bin").exists())
60  {
61  theShortName = "geoid2003";
62  addFile(dir.dirCat("g2003u02.bin"), byteOrder);
63  }
64  if(dir.dirCat("g2003u03.bin").exists())
65  {
66  theShortName = "geoid2003";
67  addFile(dir.dirCat("g2003u03.bin"), byteOrder);
68  }
69  if(dir.dirCat("g2003u04.bin").exists())
70  {
71  theShortName = "geoid2003";
72  addFile(dir.dirCat("g2003u04.bin"), byteOrder);
73  }
74  if(dir.dirCat("g2003u05.bin").exists())
75  {
76  theShortName = "geoid2003";
77  addFile(dir.dirCat("g2003u05.bin"), byteOrder);
78  }
79  if(dir.dirCat("g2003u06.bin").exists())
80  {
81  theShortName = "geoid2003";
82  addFile(dir.dirCat("g2003u06.bin"), byteOrder);
83  }
84 
85  if(dir.dirCat("g1999u01.bin").exists())
86  {
87  theShortName = "geoid1999";
88  addFile(dir.dirCat("g1999u01.bin"), byteOrder);
89  }
90  if(dir.dirCat("g1999u02.bin").exists())
91  {
92  theShortName = "geoid1999";
93  addFile(dir.dirCat("g1999u02.bin"), byteOrder);
94  }
95  if(dir.dirCat("g1999u03.bin").exists())
96  {
97  theShortName = "geoid1999";
98  addFile(dir.dirCat("g1999u03.bin"), byteOrder);
99  }
100  if(dir.dirCat("g1999u04.bin").exists())
101  {
102  theShortName = "geoid1999";
103  addFile(dir.dirCat("g1999u04.bin"), byteOrder);
104  }
105  if(dir.dirCat("g1999u05.bin").exists())
106  {
107  theShortName = "geoid1999";
108  addFile(dir.dirCat("g1999u05.bin"), byteOrder);
109  }
110  if(dir.dirCat("g1999u06.bin").exists())
111  {
112  theShortName = "geoid1999";
113  addFile(dir.dirCat("g1999u06.bin"), byteOrder);
114  }
115  if(dir.dirCat("g1999u07.bin").exists())
116  {
117  theShortName = "geoid1999";
118  addFile(dir.dirCat("g1999u07.bin"), byteOrder);
119  }
120  if(dir.dirCat("g1999u08.bin").exists())
121  {
122  theShortName = "geoid1999";
123  addFile(dir.dirCat("g1999u08.bin"), byteOrder);
124  }
125  if(dir.dirCat("g1999a01.bin").exists())
126  {
127  theShortName = "geoid1999";
128  addFile(dir.dirCat("g1999a01.bin"), byteOrder);
129  }
130  if(dir.dirCat("g1999a02.bin").exists())
131  {
132  theShortName = "geoid1999";
133  addFile(dir.dirCat("g1999a02.bin"), byteOrder);
134  }
135  if(dir.dirCat("g1999a03.bin").exists())
136  {
137  theShortName = "geoid1999";
138  addFile(dir.dirCat("g1999a03.bin"), byteOrder);
139  }
140  if(dir.dirCat("g1999a04.bin").exists())
141  {
142  theShortName = "geoid1999";
143  addFile(dir.dirCat("g1999a04.bin"), byteOrder);
144  }
145  if(dir.dirCat("g1999h01.bin"))
146  {
147  theShortName = "geoid1999";
148  addFile(dir.dirCat("g1999h01.bin"), byteOrder);
149  }
150  if(dir.dirCat("g1999p01.bin").exists())
151  {
152  theShortName = "geoid1999";
153  addFile(dir.dirCat("g1999p01.bin"), byteOrder);
154  }
155  }
156  else
157  {
158  addFile(dir, byteOrder);
159  }
160  if (traceDebug())
161  {
163  << "Opened geoid grids from: " << dir.c_str() << endl;
164  }
165 
166  return true;
167 }
168 
170 {
171 }
172 
173 
175 {
176  bool result = false;
177  if(file.exists())
178  {
179  ossim_uint32 idx = 0;
180  for(idx = 0; idx < theGridVector.size();++idx)
181  {
182  if(file == theGridVector[idx].filename())
183  {
184  result = true;
185  return result;
186  }
187  }
189  result = h.initialize(file, byteOrder);
190  if(result)
191  {
192  theGridVector.push_back(h);
193  }
194  }
195 
196  if(traceDebug())
197  {
198  ossimNotify(ossimNotifyLevel_DEBUG) << "ossimGeoidNgs::addFile: Adding file = " << file << std::endl;
199  }
200  return result;
201 }
202 
204 {
205  ossimGpt savedGpt = gpt;
206  if(ossimDatumFactory::instance()->wgs84())
207  {
208  savedGpt.changeDatum(ossimDatumFactory::instance()->wgs84());
209  }
210  double lat = savedGpt.latd();
211  double lon = savedGpt.lond();
212  fixLatLon(lat, lon);
213 
214  return deltaHeight(lat, lon);
215 }
216 
218  double lon,
219  double geoidHeight) const
220 {
221 
222  fixLatLon(lat, lon);
223  double delta = deltaHeight(lat, lon);
224  if (!ossim::isnan(delta))
225  {
226  return (geoidHeight + delta);
227  }
228  return delta; // nan
229 }
230 
232  double lon,
233  double ellipsoidHeight) const
234 {
235 
236  fixLatLon(lat, lon);
237  double delta = deltaHeight(lat, lon);
238  if (!ossim::isnan(delta))
239  {
240  return (ellipsoidHeight - delta);
241  }
242  return delta; // nan
243 }
244 
245 void ossimGeoidNgs::fixLatLon(double &lat, double &lon) const
246 {
247  if(lat < 0)
248  {
249  lat += 180;
250  }
251  if(lon < 0)
252  {
253  lon += 360;
254  }
255 }
256 
257 double ossimGeoidNgs::deltaHeight(double lat, double lon)const
258 {
259  ossim_uint32 idx = 0;
260  for(idx = 0; idx < theGridVector.size();++idx)
261  {
262  if( theGridVector[idx].pointWithin(lat, lon) )
263  {
264  return theGridVector[idx].getHeightDelta(lat,
265  lon);
266  }
267  }
268  return ossim::nan();
269 }
270 
272 {
273  return theShortName;
274 }
double lond() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:97
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
bool isDir() const
double latd() const
Will convert the radian measure to degrees.
Definition: ossimGpt.h:87
void changeDatum(const ossimDatum *datum)
This will actually perform a shift.
Definition: ossimGpt.cpp:316
virtual ~ossimGeoidNgs()
std::vector< ossimGeoidNgsHeader > theGridVector
Definition: ossimGeoidNgs.h:58
bool exists() const
unsigned int ossim_uint32
double ellipsoidToGeoidHeight(double lat, double lon, double ellipsoidHeight) const
static ossimDatumFactory * instance()
ossimByteOrder
ossimString theShortName
Definition: ossimGeoidNgs.h:59
virtual double offsetFromEllipsoid(const ossimGpt &)
virtual ossimString getShortName() const
double geoidToEllipsoidHeight(double lat, double lon, double geoidHeight) const
void fixLatLon(double &lat, double &lon) const
virtual bool addFile(const ossimFilename &file, ossimByteOrder byteOrder=OSSIM_LITTLE_ENDIAN)
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
virtual bool open(const ossimFilename &dir, ossimByteOrder byteOrder=OSSIM_LITTLE_ENDIAN)
double deltaHeight(double lat, double lon) const
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
bool initialize(const ossimFilename &fileName, ossimByteOrder byteOrder=OSSIM_LITTLE_ENDIAN)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91