OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNadconGridFile.cpp
Go to the documentation of this file.
3 
4 using namespace std;
5 
7 {
8  close();
9 }
10 
12 {
13  if(theHeader.readHeader(file))
14  {
15  theInputFile.close();
16  theInputFile.clear();
17  theInputFile.open(file.c_str(), ios::in|ios::binary);
18 
19  theBoundingRect = theHeader.getBoundingRect();
20  theLatLonOrigin.lat = theHeader.getMinY();
21  theLatLonOrigin.lon = theHeader.getMinX();
22  theFilename = file;
23  theFileOkFlag = true;
24  return theInputFile.good();
25  }
26  theFileOkFlag = false;
27  theFilename = "";
28 
29  return false;
30 }
31 
33 {
34  theInputFile.close();
35 }
36 
37 double ossimNadconGridFile::getShiftAtLatLon(double lat, double lon)const
38 {
39  double result = ossim::nan();
40  if(pointWithin(lat, lon))
41  {
42  double x = (lon - theLatLonOrigin.lon)/(double)theHeader.getDeltaX();
43  double y = (lat - theLatLonOrigin.lat)/(double)theHeader.getDeltaY();
44 
45  int lat0 = (int)y;
46  int lat1 = lat0 + 1;
47  int lon0 = (int)x;
48  int lon1 = lon0 + 1;
49 
50  int rows = theHeader.getNumberOfRows();
51  int cols = theHeader.getNumberOfCols();
52 
53  if(lat1 >= rows) lat1 = lat0;
54  if(lon1 >= cols) lon1 = lon0;
55 
56  double tLat = y - lat0;
57  double tLon = x - lon0;
58 
59  int offset00 = lat0*theHeader.getBytesPerRow() + lon0*4 + theHeader.getStartOffset();
60  int offset01 = lat0*theHeader.getBytesPerRow() + lon1*4 + theHeader.getStartOffset();
61  int offset11 = lat1*theHeader.getBytesPerRow() + lon1*4 + theHeader.getStartOffset();
62  int offset10 = lat1*theHeader.getBytesPerRow() + lon0*4 + theHeader.getStartOffset();
63 
64 
65  double v00 = 0.0;
66  double v01 = 0.0;
67  double v11 = 0.0;
68  double v10 = 0.0;
69 
70  theInputFile.seekg((std::streampos)offset00);
71  theInputFile.read((char*)&v00, 4);
72  theInputFile.seekg((std::streampos)offset01);
73  theInputFile.read((char*)&v01, 4);
74  theInputFile.seekg((std::streampos)offset11);
75  theInputFile.read((char*)&v11, 4);
76  theInputFile.seekg((std::streampos)offset10);
77  theInputFile.read((char*)&v10, 4);
78  ossimEndian anEndian;
79 
81  {
82  anEndian.swap(v00);
83  anEndian.swap(v01);
84  anEndian.swap(v11);
85  anEndian.swap(v10);
86  }
87 
88  double top = (double)v00 + ((double)v01 - (double)v00)*tLon;
89  double bottom = (double)v10 + ((double)v11 - (double)v10)*tLon;
90 
91  result = top + (bottom-top)*tLat;
92  }
93 
94  return result;
95 }
96 
97 bool ossimNadconGridFile::pointWithin(double lat, double lon)const
98 {
99  return theBoundingRect.pointWithin(ossimDpt(lon, lat));
100 }
ossim_uint32 x
ossim_uint32 y
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
ossimByteOrder getSystemEndianType() const
Definition: ossimEndian.h:78
double getShiftAtLatLon(double lat, double lon) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
Definition: ossimString.h:396
bool open(const ossimFilename &file)
bool pointWithin(double lat, double lon) const
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26