OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimApplanixEOFile.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // MIT
4 //
5 // Author: Garrett Potts
6 //
7 //*******************************************************************
8 // $Id$
9 
11 #include <ossim/base/ossimCommon.h>
14 #include <ossim/base/ossimRegExp.h>
16 #include <ossim/base/ossimTrace.h>
17 
18 #include <iterator>
19 #include <sstream>
20 #include <iostream>
21 #include <iomanip>
22 
23 static ossimTrace traceDebug("ossimApplanixEOFile:debug");
24 
25 static std::istream& applanix_skipws(ossim::istream& in)
26 {
27  int c = in.peek();
28  while(((c == ' ') ||
29  (c == '\r') ||
30  (c == '\t') ||
31  (c == '\n'))&&
32  (in.good()))
33  {
34  in.ignore(1);
35  c = in.peek();
36  }
37 
38  return in;
39 }
40 
42 {
43  if(src.theField.size())
44  {
45  std::copy(src.theField.begin(),
46  src.theField.end(),
47  std::ostream_iterator<ossimString>(out, " "));
48  }
49 
50  return out;
51 }
52 
54 {
55  ossim_uint32 idx = 0;
56  out << src.theHeader << std::endl << std::endl;
57 
58  if(src.theRecordFormat.size())
59  {
60  std::copy(src.theRecordFormat.begin(),
61  src.theRecordFormat.end()-1,
62  std::ostream_iterator<ossimString>(out, ", "));
63  out << *(src.theRecordFormat.end()-1);
64  out << std::endl;
65  }
66 
67  out << "Kappa Cardinal Rotation = " << src.theKappaCardinal << std::endl;
68  out << "Bore Sight tx = " << src.theBoreSightTx << std::endl
69  << "Bore Sight ty = " << src.theBoreSightTy << std::endl
70  << "Bore Sight tz = " << src.theBoreSightTz << std::endl;
71 
72  out << "Lever arm lx = " << src.theLeverArmLx << std::endl
73  << "Lever arm ly = " << src.theLeverArmLy << std::endl
74  << "Lever arm lz = " << src.theLeverArmLz << std::endl;
75 
76  out << "Shift Value X = " << src.theShiftValuesX << std::endl
77  << "Shift Value Y = " << src.theShiftValuesY << std::endl
78  << "Shift Value Z = " << src.theShiftValuesZ << std::endl;
79 
80  out << "Mapping Frame Datum = " << src.theMappingFrameDatum << std::endl
81  << "Mapping Frame Projection = " << src.theMappingFrameProjection << std::endl
82  << "Central Meridian = " << src.theCentralMeridian << std::endl
83  << "Origin of Latitude = " << src.theOriginLatitude << std::endl
84  << "Grid Scale Factor = " << src.theGridScaleFactor << std::endl
85  << "False easting = " << src.theFalseEasting << std::endl
86  << "False northing = " << src.theFalseNorthing << std::endl;
87 
88  out << "theUtmZone = " << src.theUtmZone << std::endl;
89  out << "theUtmHemisphere = " << src.theUtmHemisphere << std::endl;
90 
91  if(src.theApplanixRecordList.size())
92  {
93  out << std::endl;
94  for(idx = 0; idx < src.theApplanixRecordList.size()-1; ++idx)
95  {
96  out << *(src.theApplanixRecordList[idx]) << std::endl;
97  }
98  out << *(src.theApplanixRecordList[idx]);
99 
100  }
101 
102  return out;
103 }
104 
106 {
107  theMinLat = ossim::nan();
108  theMinLon = ossim::nan();
109  theMaxLat = ossim::nan();
110  theMaxLon = ossim::nan();
111 }
112 
114 {
115  bool result = false;
116 
117  std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->
118  createIstream(file, std::ios_base::in);
119 
120  if ( in )
121  {
122  result = parseStream( *in );
123  }
124 
125  return result;
126 }
127 
129 {
130  bool result = false;
131 
132  std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->
133  createIstream( file, std::ios_base::in);
134 
135  if ( in )
136  {
137  result = isEOFile( *in );
138  }
139 
140  return result;
141 }
142 
144 {
145  ossimString header;
146 
147  return parseHeader(in, header);
148 }
149 
151 {
152  theRecordIdMap.clear();
153  ossimString line;
154  int c = '\0';
155  if(!parseHeader(in, theHeader))
156  {
157  return false;
158  }
159 
160  // now parse parameters
161  in>>applanix_skipws;
162  line = "";
163  while(in.good()&&
164  !line.contains("RECORD FORMAT"))
165  {
166  std::getline(in, line.string());
167  line = line.upcase();
168  line = line.substitute("\r","\n", true);
169  if(line.contains("KAPPA CARDINAL"))
170  {
171  theKappaCardinal = line;
172  theKappaCardinal = theKappaCardinal.substitute("KAPPA CARDINAL ROTATION","");
175  }
176  else if(line.contains("LEVER ARM"))
177  {
178  ossimKeywordlist kwl('=');
179  line = line.substitute("LEVER ARM VALUES:",
180  "");
181  line = line.substitute(",",
182  "\n",
183  true);
184  std::istringstream in(line);
185 
186  kwl.parseStream(in);
187 
188  theLeverArmLx = kwl.find("LX");
189  theLeverArmLy = kwl.find("LY");
190  theLeverArmLz = kwl.find("LZ");
191  }
192  else if(line.contains("BORESIGHT VALUES"))
193  {
194  ossimKeywordlist kwl('=');
195  line = line.substitute("BORESIGHT VALUES:",
196  "");
197  line = line.substitute(",",
198  "\n",
199  true);
200 
201  std::istringstream in(line);
202 
203  kwl.parseStream(in);
204 
205 
206  theBoreSightTx = kwl.find("TX");
207  theBoreSightTy = kwl.find("TY");
208  theBoreSightTz = kwl.find("TZ");
209  }
210  else if(line.contains("SHIFT VALUES:"))
211  {
212  ossimKeywordlist kwl('=');
213  line = line.substitute("SHIFT VALUES:","");
214  line = line.substitute(",",
215  "\n",
216  true);
217 
218  std::istringstream in(line);
219  kwl.parseStream(in);
220 
221 
222  theShiftValuesX = kwl.find("X");
223  theShiftValuesY = kwl.find("Y");
224  theShiftValuesZ = kwl.find("Z");
225 
226  }
227  else if(line.contains("GRID:"))
228  {
229  ossimKeywordlist kwl(':');
230  line = line.substitute(";",
231  "\n",
232  true);
233  std::istringstream in(line);
234  kwl.parseStream(in);
235  theUtmZone = kwl.find("ZONE");
236 
237  if(theUtmZone.contains("NORTH"))
238  {
239  theUtmHemisphere = "North";
240  }
241  else
242  {
243  theUtmHemisphere = "South";
244  }
245  theUtmZone = theUtmZone.replaceAllThatMatch("UTM|\\(.*\\)|NORTH|SOUTH","");
247  }
248  else if(line.contains("FRAME DATUM"))
249  {
250  ossimKeywordlist kwl(':');
251  line = line.substitute(";",
252  "\n",
253  true);
254  std::istringstream in(line);
255  kwl.parseStream(in);
256 
257  theMappingFrameDatum = kwl.find("MAPPING FRAME DATUM");
258  theMappingFrameProjection = kwl.find("MAPPING FRAME PROJECTION");
261  }
262  else if(line.contains("POSPROC SBET"))
263  {
264  theSbetField = line.after(":");
266  }
267  else if(line.contains("CENTRAL MERIDIAN"))
268  {
269  theCentralMeridian = line;
270  theCentralMeridian = theCentralMeridian.substitute("CENTRAL MERIDIAN","");
274  }
275  else if(line.contains("LATITUDE OF THE GRID ORIGIN"))
276  {
277  ossimKeywordlist kwl('=');
278  line = line.substitute(";",
279  "\n",
280  true);
281  std::istringstream in(line);
282  kwl.parseStream(in);
283 
284  theOriginLatitude = kwl.find("LATITUDE OF THE GRID ORIGIN");
285  theGridScaleFactor = kwl.find("GRID SCALE FACTOR");
286  }
287  else if(line.contains("FALSE EASTING"))
288  {
289  ossimKeywordlist kwl('=');
290  line = line.substitute(";",
291  "\n",
292  true);
293  std::istringstream in(line);
294  kwl.parseStream(in);
295 
296  theFalseEasting = kwl.find("FALSE EASTING");
297  theFalseNorthing = kwl.find("FALSE NORTHING");
298  }
299  }
300 
301  in>>applanix_skipws;
302 
303  c = in.get();
304 
305  std::vector<ossimString> fieldArray;
306  ossimString field;
307 
308  while(in.good()&&
309  (c!='\n')&&
310  (c!='\r'))
311  {
312  field = "";
313  while((c != ',')&&
314  (c != '\n')&&
315  (c != '\r'))
316  {
317  field += (char)c;
318  c = in.get();
319  }
320  if((c!='\n')&&
321  (c!='\r'))
322  {
323  c = in.get();
324  }
325  field = field.trim();
326  if(field != "")
327  {
328  theRecordFormat.push_back(field);
329  }
330  }
331  in>>applanix_skipws;
332 
333  if(in.peek() == '(')
334  {
335  std::getline(in, line.string());
336  }
337  in>>applanix_skipws;
339  ossim_int32 latIdx = getFieldIdx("LAT");
340  ossim_int32 lonIdx = getFieldIdx("LONG");;
341  bool hasLatLon = (latIdx >=0)&&(lonIdx >= 0);
342 
343 
344  if(hasLatLon)
345  {
346  theMinLat = 90.0;
347  theMaxLat = -90.0;
348  theMinLon = 180.0;
349  theMaxLon = -180.0;
350  }
351  else
352  {
353  theMinLat = ossim::nan();
354  theMaxLat = ossim::nan();
355  theMinLon = ossim::nan();
356  theMaxLon = ossim::nan();
357  }
358 
359  while(in.good()&&theRecordFormat.size())
360  {
361  std::getline(in, line.string());
362  line = line.trim();
363  if(line != "")
364  {
365  std::istringstream inStr(line);
366  ossim_uint32 idx;
367  ossimString value;
368 
369  for(idx = 0; idx < theRecordFormat.size(); ++idx)
370  {
371  inStr >> (*record)[idx];
372  }
373  if(hasLatLon)
374  {
375  double lat = (*record)[latIdx].toDouble();
376  double lon = (*record)[lonIdx].toDouble();
377 
378  if(lat<theMinLat) theMinLat = lat;
379  if(lat>theMaxLat) theMaxLat = lat;
380  if(lon<theMinLon) theMinLon = lon;
381  if(lon>theMaxLon) theMaxLon = lon;
382 
383  }
384  theApplanixRecordList.push_back(new ossimApplanixEORecord(*record));
385  }
386  }
387  indexRecordIds();
388 
389  if(traceDebug())
390  {
391  if(hasLatLon)
392  {
393  ossimNotify(ossimNotifyLevel_DEBUG) << "min lat: " << theMinLat << std::endl
394  << "min lon: " << theMinLon << std::endl
395  << "max lat: " << theMaxLat << std::endl
396  << "max lon: " << theMaxLon << std::endl;
397  }
398  }
399  return true;
400 }
401 
403  ossimString& header)const
404 {
405  bool result = false;
406 
407  std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->
408  createIstream( file, std::ios_base::in);
409 
410  if ( in )
411  {
412  result = parseHeader( *in, header);
413  }
414 
415  return result;
416 }
417 
419  ossimString& header)const
420 {
421  header = "";
422  in >> applanix_skipws;
423 
424  int c = in.peek();
425 
426  if((c!='*')||
427  (!in.good()))
428  {
429  return false;
430  }
431  ossimString line;
432 
433  std::getline(in, line.string());
434  line = line .substitute("\r",
435  "\n");
436  if(!line.contains("************"))
437  {
438  return false;
439  }
440 
441  header = line;
442  header += "\n";
443 
444  in>>applanix_skipws;
445  std::getline(in, line.string());
446  line = line .substitute("\r",
447  "\n");
448 
449  while((in.good())&&
450  (!line.contains("***********")))
451  {
452  header += line;
453  header += "\n";
454  std::getline(in, line.string());
455  line = line .substitute("\r",
456  "\n");
457  }
458  header += line;
459  header += "\n";
460 
461  if(!header.contains("Applanix"))
462  {
463  return false;
464  }
465 
466  return true;
467 }
468 
470 {
471  ossimString id;
472  ossim_uint32 idx;
473  ossim_int32 idIdx = getFieldIdxLike("ID");
475  theRecordIdMap.clear();
476 
477  if(idIdx < 0) return;
478 
479  for(idx = 0; idx < size; ++idx)
480  {
481  id = (*theApplanixRecordList[idx])[idIdx];
482  theRecordIdMap.insert(std::make_pair(id, theApplanixRecordList[idx]));
483  }
484 }
485 
487 {
488  ossimString key = searchKey;
489  ossim_uint32 idx = 0;
490  key = key.upcase();
491 
492  for(idx = 0; idx < theRecordFormat.size(); ++idx)
493  {
495  {
496  return (int)idx;
497  }
498  }
499 
500  return -1;
501 }
502 
504 {
505  ossimString key = searchKey;
506  ossim_uint32 idx = 0;
507 
508  key = key.upcase();
509 
510  for(idx = 0; idx < theRecordFormat.size(); ++idx)
511  {
512  if(ossimString::upcase(theRecordFormat[idx]) == key)
513  {
514  return (int)idx;
515  }
516  }
517 
518  return -1;
519 }
520 
521 
523 {
524 
525  if(theRecordIdMap.size())
526  {
527  std::map<ossimString, ossimRefPtr<ossimApplanixEORecord>,
528  ossimStringLtstr >::const_iterator iter = theRecordIdMap.find(id);
529 
530  if(iter!=theRecordIdMap.end())
531  {
532  return iter->second;
533  }
534  }
535  else
536  {
537  ossim_uint32 idx;
538  ossim_int32 idxId = getFieldIdx("ID");
539 
540  if(idxId >= 0)
541  {
542  for(idx = 0; idx < theApplanixRecordList.size(); ++idx)
543  {
544  if((*theApplanixRecordList[idx])[idxId] == id)
545  {
546  return theApplanixRecordList[idx];
547  }
548  }
549  }
550  }
551 
552  return 0;
553 }
554 
556 {
557  return (ossim_uint32)theApplanixRecordList.size();
558 }
559 
561 {
562  if(idx < theApplanixRecordList.size())
563  {
564  return theApplanixRecordList[idx];
565  }
566 
567  return 0;
568 }
569 
571 {
572  return (getFieldIdx("ORTHOMETRIC HEIGHT") >= 0);
573 }
574 
576 {
577  ossim_int32 xIdx = getFieldIdx("X");
578  ossim_int32 yIdx = getFieldIdx("Y");
579  ossim_int32 zIdx = getFieldIdx("Z");
580  ossim_int32 rollIdx = getFieldIdx("ROLL");
581  ossim_int32 pitchIdx = getFieldIdx("PITCH");
582  ossim_int32 headingIdx = getFieldIdx("HEADING");
583 
584  return ((xIdx >=0)&&
585  (yIdx >=0)&&
586  (zIdx >=0)&&
587  (rollIdx>=0)&&
588  (pitchIdx>=0)&&
589  (headingIdx>=0));
590 }
591 
592 
594 {
595  return ((getFieldIdxLike("EASTING")>=0)&&
596  (getFieldIdxLike("NORTHING") >=0)&&
597  (getFieldIdxLike("HEIGHT") >= 0)&&
598  (getFieldIdxLike("OMEGA") >=0)&&
599  (getFieldIdxLike("PHI") >=0)&&
600  (getFieldIdxLike("KAPPA") >=0));
601 
602  return (getUtmZone() >= 0.0);
603 }
604 
606 {
607  return theUtmZone.toInt32();
608 }
609 
611 {
612  return theUtmHemisphere;
613 }
614 
616 {
617  return theSbetField;
618 }
619 
621 {
622  return theBoreSightTx.toDouble();
623 }
624 
626 {
627  return theBoreSightTy.toDouble();
628 }
629 
631 {
632  return theBoreSightTz.toDouble();
633 }
634 
636 {
637  return theLeverArmLx.toDouble();
638 }
639 
641 {
642  return theLeverArmLy.toDouble();
643 }
644 
646 {
647  return theLeverArmLz.toDouble();
648 }
649 
651 {
652  return theKappaCardinal.toDouble();
653 }
654 
656 {
657  return theShiftValuesX.toDouble();
658 }
659 
661 {
662  return theShiftValuesY.toDouble();
663 }
664 
666 {
667  return theShiftValuesZ.toDouble();
668 }
669 
671 {
672  return theMappingFrameDatum;
673 }
674 
676 {
678 }
679 
681 {
682  return theCentralMeridian.toDouble();
683 }
684 
686 {
687  return theOriginLatitude.toDouble();
688 }
689 
691 {
692  return theGridScaleFactor.toDouble();
693 }
694 
696 {
697  return theFalseEasting.toDouble();
698 }
699 
701 {
702  return theFalseNorthing.toDouble();
703 }
704 
706 {
707  ossimString result = "WGE";
708  ossimString temp = datum;
709  temp = temp.upcase();
710 
711  if(temp == "NAD83")
712  {
713  result = "NAR-C";
714  }
715 
716  return result;
717 }
ossimString substitute(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false) const
Substitutes searchKey string with replacementValue and returns a string.
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
ossimString getMappingFrameProjection() const
ossimString getMappingFrameDatum() const
double getMappingFrameCentralMeridian() const
Represents serializable keyword/value map.
const char * find(const char *key) const
double getShiftValuesX() const
ossim_int32 getUtmZone() const
double getShiftValuesY() const
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
bool contains(char aChar) const
Definition: ossimString.h:58
double getMappingFrameOriginLatitude() const
bool parseHeader(const ossimFilename &file, ossimString &header) const
Parses the header of the exterior orientation file.
double getKardinalKappa() const
static StreamFactoryRegistry * instance()
std::istream & getline(std::istream &is, ossimString &str, char delim)
Definition: ossimString.h:916
double getMappingFrameGridScaleFactor() const
ossim_uint32 getNumberOfRecords() const
ossimString theMappingFrameDatum
ossim_int32 toInt32() const
std::vector< ossimString > theField
ossim_int32 getFieldIdxLike(const ossimString &searchKey) const
Is a case insensitive parse of the column names for the orientation record.
ossimString replaceAllThatMatch(const char *regularExpressionPattern, const char *value="") const
std::ostream & operator<<(std::ostream &out, const ossimApplanixEORecord &src)
yy_size_t size
unsigned int ossim_uint32
For use with std::map as a compare operator: std::map<ossimString, ossimString, ossimStringLtstr> ...
Definition: ossimString.h:971
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
double toDouble() const
ossimString getUtmHemisphere() const
std::map< ossimString, ossimRefPtr< ossimApplanixEORecord >, ossimStringLtstr > theRecordIdMap
const ossimRefPtr< ossimApplanixEORecord > getRecord(ossim_uint32 idx) const
double getMappingFrameFalseNorthing() const
const ossimRefPtr< ossimApplanixEORecord > getRecordGivenId(const ossimString &id) const
Given an ID it will search and find an EO record that matches the ID.
ossimString getSbetField() const
ossimString convertToOssimDatumCode(const ossimString &datum) const
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
double getMappingFrameFalseEasting() const
ossim_int32 getFieldIdx(const ossimString &searchKey) const
Is a case insensitive parse of the column names for the orientation record.
ossimString theMappingFrameProjection
double getShiftValuesZ() const
virtual bool parseStream(ossim::istream &is, bool ignoreBinaryChars)
deprecated method
void indexRecordIds()
Will index all records based on the "ID #" field for fast searching.
std::vector< ossimString > theRecordFormat
bool parseStream(ossim::istream &in)
Will parse the stream and set internal queriable parameters.
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
bool parseFile(const ossimFilename &file)
Will parse the entire Exterior orientation file and then index any record ID&#39;s found.
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
ossimString & upcase()
Upcases this string.
Definition: ossimString.cpp:62
bool isEOFile(const ossimFilename &file) const
Utility method that just checks for an APPlanix exterior orientation header.
std::vector< ossimRefPtr< ossimApplanixEORecord > > theApplanixRecordList
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
int ossim_int32
const std::string & string() const
Definition: ossimString.h:414