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

#include <ossimGeoidNgsHeader.h>

Public Member Functions

 ossimGeoidNgsHeader ()
 
 ossimGeoidNgsHeader (const ossimFilename &fileName, ossimByteOrder byteOrder=OSSIM_LITTLE_ENDIAN)
 
bool initialize (const ossimFilename &fileName, ossimByteOrder byteOrder=OSSIM_LITTLE_ENDIAN)
 
double southernMostLat () const
 
double westernMostLon () const
 
double latDelta () const
 
double lonDelta () const
 
int rows () const
 
int cols () const
 
int dataType () const
 
bool pointWithin (double lat, double lon) const
 
const ossimFilenamefilename () const
 
int headerSize () const
 
int dataTypeSize () const
 
double getHeightDelta (double lat, double lon) const
 

Private Attributes

ossimFilename theFilename
 
ossimByteOrder theByteOrder
 
double theSouthernMostLatitude
 
double theWesternMostLongitude
 
double theLatDelta
 
double theLonDelta
 
int theRows
 
int theCols
 
int theDataType
 

Friends

OSSIM_DLL std::ostream & operator<< (std::ostream &out, const ossimGeoidNgsHeader &data)
 

Detailed Description

Definition at line 16 of file ossimGeoidNgsHeader.h.

Constructor & Destructor Documentation

◆ ossimGeoidNgsHeader() [1/2]

ossimGeoidNgsHeader::ossimGeoidNgsHeader ( )

◆ ossimGeoidNgsHeader() [2/2]

ossimGeoidNgsHeader::ossimGeoidNgsHeader ( const ossimFilename fileName,
ossimByteOrder  byteOrder = OSSIM_LITTLE_ENDIAN 
)

Definition at line 38 of file ossimGeoidNgsHeader.cpp.

References ossim::byteOrder(), and initialize().

40 {
41  initialize(fileName, byteOrder);
42 }
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
bool initialize(const ossimFilename &fileName, ossimByteOrder byteOrder=OSSIM_LITTLE_ENDIAN)

Member Function Documentation

◆ cols()

int ossimGeoidNgsHeader::cols ( ) const
inline

Definition at line 33 of file ossimGeoidNgsHeader.h.

Referenced by initialize().

◆ dataType()

int ossimGeoidNgsHeader::dataType ( ) const
inline

Definition at line 34 of file ossimGeoidNgsHeader.h.

◆ dataTypeSize()

int ossimGeoidNgsHeader::dataTypeSize ( ) const
inline

Definition at line 39 of file ossimGeoidNgsHeader.h.

Referenced by getHeightDelta().

39 {return theDataType==1?4:0;}

◆ filename()

const ossimFilename& ossimGeoidNgsHeader::filename ( ) const
inline

Definition at line 36 of file ossimGeoidNgsHeader.h.

Referenced by getHeightDelta().

36 {return theFilename;}

◆ getHeightDelta()

double ossimGeoidNgsHeader::getHeightDelta ( double  lat,
double  lon 
) const
Returns
Height delta or ossim::nan() if not found.

Definition at line 108 of file ossimGeoidNgsHeader.cpp.

References dataTypeSize(), filename(), FLT_EPSILON, ossimEndian::getSystemEndianType(), headerSize(), ossim::nan(), ossimNotify(), ossimNotifyLevel_FATAL, ossimEndian::swap(), theByteOrder, theCols, theFilename, theLatDelta, theLonDelta, theSouthernMostLatitude, and theWesternMostLongitude.

110 {
111  float result=0.0;
112 
113  // note the headers go from 0 to 360 degrees starting at the prime meridian.
114  // ours goes from -180 to 180 degrees. We will need to shift
115  //
116  if(lon < 0.0) lon += 360;
117  double latSpaces = (lat - theSouthernMostLatitude)/theLatDelta;
118  double lonSpaces = (lon - theWesternMostLongitude)/theLonDelta;
119 
120  if(latSpaces < -FLT_EPSILON) return ossim::nan();
121  if(lonSpaces < -FLT_EPSILON) return ossim::nan();
122 
123  long latSpace0 = (long)std::floor(latSpaces);
124  long latSpace1 = latSpace0 + 1;
125  long lonSpace0 = (long)std::floor(lonSpaces);
126  long lonSpace1 = lonSpace0 + 1;
127 
128  ifstream input(filename().c_str(), ios::in|ios::binary);
129  if(!input)
130  {
131  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL: " << "ossimGeoidNgsHeader::getGeoidHeight, " << "unable to open file: " << theFilename << "\n";
132  return 0;
133  }
134 
135  long offset00 = (long)(headerSize() + (latSpace0*theCols + lonSpace0)*dataTypeSize());
136  long offset01 = (long)(headerSize() + (latSpace0*theCols + lonSpace1)*dataTypeSize());
137  long offset11 = (long)(headerSize() + (latSpace1*theCols + lonSpace1)*dataTypeSize());
138  long offset10 = (long)(headerSize() + (latSpace1*theCols + lonSpace0)*dataTypeSize());
139 
140  double tLat = latSpaces - floor(latSpaces);
141  double tLon = lonSpaces - floor(lonSpaces);
142 
143 
144  float v00;
145  float v01;
146  float v11;
147  float v10;
148 
149  input.seekg(offset00,ios::beg);
150  input.read((char*)&v00, 4);
151 
152  input.seekg(offset01,ios::beg);
153  input.read((char*)&v01, 4);
154 
155  input.seekg(offset11,ios::beg);
156  input.read((char*)&v11, 4);
157 
158  input.seekg(offset10,ios::beg);
159  input.read((char*)&v10, 4);
160  ossimEndian endian;
161  if(endian.getSystemEndianType() != theByteOrder)
162  {
163  endian.swap(v00);
164  endian.swap(v01);
165  endian.swap(v11);
166  endian.swap(v10);
167  }
168  double bottom = (v00 + (v01 - v00)*tLat);
169  double top = (v10 + (v11 - v10)*tLat);
170  result = bottom + (top - bottom)*tLon;
171 
172  return result;
173 
174 }
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
const ossimFilename & filename() const
#define FLT_EPSILON
ossimByteOrder getSystemEndianType() const
Definition: ossimEndian.h:78
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
ossimByteOrder theByteOrder

◆ headerSize()

int ossimGeoidNgsHeader::headerSize ( ) const
inline

Definition at line 38 of file ossimGeoidNgsHeader.h.

Referenced by getHeightDelta().

38 {return 44;}

◆ initialize()

bool ossimGeoidNgsHeader::initialize ( const ossimFilename fileName,
ossimByteOrder  byteOrder = OSSIM_LITTLE_ENDIAN 
)

Definition at line 44 of file ossimGeoidNgsHeader.cpp.

References ossim::byteOrder(), ossimString::c_str(), cols(), FLT_EPSILON, ossimEndian::getSystemEndianType(), rows(), ossimEndian::swap(), theByteOrder, theCols, theDataType, theFilename, theLatDelta, theLonDelta, theRows, theSouthernMostLatitude, and theWesternMostLongitude.

Referenced by ossimGeoidNgs::addFile(), and ossimGeoidNgsHeader().

46 {
47  ifstream input(fileName.c_str(), ios::in|ios::binary);
48  if(!input)
49  {
50 // cerr << MODULE << " Cannot open geoid file in " << fileName.c_str()
51 // << endl;
52  return false;
53  }
54 
56  double latOrigin = 0.0;
57  double lonOrigin = 0.0;
58  double latSpacing = 0.0;
59  double lonSpacing = 0.0;
60  int rows = 0;
61  int cols = 0;
62  int type = 0;
63 
64  input.read((char*)&latOrigin, 8);
65  input.read((char*)&lonOrigin, 8);
66  input.read((char*)&latSpacing, 8);
67  input.read((char*)&lonSpacing, 8);
68  input.read((char*)&rows, 4);
69  input.read((char*)&cols, 4);
70  input.read((char*)&type, 4);
71 
72  ossimEndian endian;
73 
74  if(endian.getSystemEndianType() != byteOrder)
75  {
76  endian.swap(latOrigin);
77  endian.swap(lonOrigin);
78  endian.swap(latSpacing);
79  endian.swap(lonSpacing);
80  endian.swap(rows);
81  endian.swap(cols);
82  endian.swap(type);
83  }
84 
85  theFilename = fileName;
86  theSouthernMostLatitude = latOrigin;
87  theWesternMostLongitude = lonOrigin;
88  theLatDelta = latSpacing;
89  theLonDelta = lonSpacing;
90  theRows = rows;
91  theCols = cols;
92  theDataType = type;
93 
94  return ((theSouthernMostLatitude >= -FLT_EPSILON)&&
95  (theSouthernMostLatitude <= 90.0)&&
97  (theWesternMostLongitude <= 360.0));
98 }
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
#define FLT_EPSILON
ossimByteOrder getSystemEndianType() const
Definition: ossimEndian.h:78
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
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
ossimByteOrder theByteOrder

◆ latDelta()

double ossimGeoidNgsHeader::latDelta ( ) const
inline

Definition at line 30 of file ossimGeoidNgsHeader.h.

30 {return theLatDelta;}

◆ lonDelta()

double ossimGeoidNgsHeader::lonDelta ( ) const
inline

Definition at line 31 of file ossimGeoidNgsHeader.h.

31 {return theLonDelta;}

◆ pointWithin()

bool ossimGeoidNgsHeader::pointWithin ( double  lat,
double  lon 
) const

◆ rows()

int ossimGeoidNgsHeader::rows ( ) const
inline

Definition at line 32 of file ossimGeoidNgsHeader.h.

Referenced by initialize().

◆ southernMostLat()

double ossimGeoidNgsHeader::southernMostLat ( ) const
inline

Definition at line 28 of file ossimGeoidNgsHeader.h.

◆ westernMostLon()

double ossimGeoidNgsHeader::westernMostLon ( ) const
inline

Definition at line 29 of file ossimGeoidNgsHeader.h.

Friends And Related Function Documentation

◆ operator<<

OSSIM_DLL std::ostream& operator<< ( std::ostream &  out,
const ossimGeoidNgsHeader data 
)
friend

Member Data Documentation

◆ theByteOrder

ossimByteOrder ossimGeoidNgsHeader::theByteOrder
private

Definition at line 46 of file ossimGeoidNgsHeader.h.

Referenced by getHeightDelta(), and initialize().

◆ theCols

int ossimGeoidNgsHeader::theCols
private

theCols specifies the number of lon increments

Definition at line 74 of file ossimGeoidNgsHeader.h.

Referenced by getHeightDelta(), initialize(), operator<<(), and pointWithin().

◆ theDataType

int ossimGeoidNgsHeader::theDataType
private

Specifies the datatype. if this is 1 then the data that follows is 4 byte floats.

Definition at line 80 of file ossimGeoidNgsHeader.h.

Referenced by initialize(), and operator<<().

◆ theFilename

ossimFilename ossimGeoidNgsHeader::theFilename
private

Definition at line 45 of file ossimGeoidNgsHeader.h.

Referenced by getHeightDelta(), initialize(), and operator<<().

◆ theLatDelta

double ossimGeoidNgsHeader::theLatDelta
private

Specifies the spacing of the latitude direction.

Definition at line 59 of file ossimGeoidNgsHeader.h.

Referenced by getHeightDelta(), initialize(), operator<<(), and pointWithin().

◆ theLonDelta

double ossimGeoidNgsHeader::theLonDelta
private

longitude spacing.

Definition at line 64 of file ossimGeoidNgsHeader.h.

Referenced by getHeightDelta(), initialize(), operator<<(), and pointWithin().

◆ theRows

int ossimGeoidNgsHeader::theRows
private

theRows specifies the number of lat increments

Definition at line 69 of file ossimGeoidNgsHeader.h.

Referenced by initialize(), operator<<(), and pointWithin().

◆ theSouthernMostLatitude

double ossimGeoidNgsHeader::theSouthernMostLatitude
private

Definition at line 47 of file ossimGeoidNgsHeader.h.

Referenced by getHeightDelta(), initialize(), operator<<(), and pointWithin().

◆ theWesternMostLongitude

double ossimGeoidNgsHeader::theWesternMostLongitude
private

Important: The geoid.bin files expresses this as a possitive value.

example: -90.0 is 270 degrees.

Definition at line 54 of file ossimGeoidNgsHeader.h.

Referenced by getHeightDelta(), initialize(), operator<<(), and pointWithin().


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