OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
resolution_utils.cpp
Go to the documentation of this file.
1 #include <genutils.h>
2 
3 #include <boost/algorithm/string/trim.hpp>
4 #include <boost/algorithm/string/case_conv.hpp>
5 #include <boost/algorithm/string/predicate.hpp>
6 #include <boost/algorithm/string.hpp>
7 
8 bool is_digits(const std::string &str)
9 {
10  return std::all_of(str.begin(), str.end(), ::isdigit);
11 }
12 
13 double string2resolution(std::string resolutionStr) {
14  double resolution = BAD_FLT;
15  boost::trim(resolutionStr);
16  boost::to_lower(resolutionStr);
17  resolutionStr.erase(remove_if(resolutionStr.begin(), resolutionStr.end(), ::isspace), resolutionStr.end());
18 
19  if (resolutionStr.compare("90km") == 0)
21  else if (resolutionStr.compare("36km") == 0)
23  else if (resolutionStr.compare("18km") == 0)
25  else if (resolutionStr.compare("9km") == 0)
27  else if (resolutionStr.compare("4km") == 0)
29  else if (resolutionStr.compare("2km") == 0)
30  resolution = EARTH_CIRCUMFERENCE / 17280.0;
31  else if (resolutionStr.compare("1km") == 0)
32  resolution = EARTH_CIRCUMFERENCE / 34560.0;
33  else if (resolutionStr.compare("hkm") == 0)
34  resolution = EARTH_CIRCUMFERENCE / 69120.0;
35  else if (resolutionStr.compare("qkm") == 0)
36  resolution = EARTH_CIRCUMFERENCE / 138240.0;
37  else if (resolutionStr.compare("hqkm") == 0)
38  resolution = EARTH_CIRCUMFERENCE / 276480.0;
39  else if (resolutionStr.compare("hhkm") == 0)
40  resolution = EARTH_CIRCUMFERENCE / 552960.0;
41  else if (resolutionStr.compare("smi") == 0)
43  else if (resolutionStr.compare("smi4") == 0)
45  else if (resolutionStr.compare("land") == 0)
47  else if (resolutionStr.compare("thirddeg") == 0)
49  else if (boost::ends_with(resolutionStr, "km")) {
50  std::string val = resolutionStr.substr(0, resolutionStr.length() - 2);
51  resolution = atof(val.c_str()) * 1000.0;
52  } else if (boost::ends_with(resolutionStr, "m")) {
53  std::string val = resolutionStr.substr(0, resolutionStr.length() - 1);
54  resolution = atof(val.c_str());
55  } else if (boost::ends_with(resolutionStr, "deg")) {
56  std::string val = resolutionStr.substr(0, resolutionStr.length() - 3);
57  resolution = atof(val.c_str()) / 360.0 * EARTH_CIRCUMFERENCE;
58  } else if (is_digits(resolutionStr)) {
59  resolution = atof(resolutionStr.c_str());
60  } else {
62  }
63  return resolution;
64 }
65 
67  std::string resolutionStr = "Unknown";
68  if (resolution > 0) {
69  std::string geoUnits = " m";
70  if (resolution > 1000.0) {
71  resolution = resolution / 1000.0;
72  geoUnits = " km";
73  }
74  resolutionStr = std::to_string(resolution) + geoUnits;
75  }
76  return resolutionStr;
77 }
78 
79 extern "C" double str2resolution(char const * resolutionStr) {
80  std::string str(resolutionStr);
81  return string2resolution(str);
82 }
83 
84 extern "C" const char* resolution2str(double resolution) {
85  static std::string stringRes = resolution2string(resolution);
86  return stringRes.c_str();
87 }
88 
89 extern "C" double resolution2degrees(double resolution) {
90  return resolution / EARTH_CIRCUMFERENCE * 360.0;
91 }
92 
93 extern "C" double degrees2resolution(double degrees) {
94  return degrees / 360.0 * EARTH_CIRCUMFERENCE;
95 }
96 
double degrees2resolution(double degrees)
Pixel resolution degrees to meters.
double resolution2degrees(double resolution)
Pixel resolution meters to degrees.
bool is_digits(const std::string &str)
this program makes no use of any feature of the SDP Toolkit that could generate such a then geolocation is calculated at that resolution
Definition: HISTORY.txt:188
@ string
#define isdigit(c)
double string2resolution(std::string resolutionStr)
double str2resolution(char const *resolutionStr)
Pixel resolution string to meters.
const char * resolution2str(double resolution)
Pixel resolution meters to string.
std::string resolution2string(double resolution)
#define EARTH_CIRCUMFERENCE
Definition: genutils.h:10
string & trim(string &s, const string &delimiters)
Definition: EnvsatUtil.cpp:29
#define isspace(c)
const char * str
Definition: l1c_msi.cpp:35
#define BAD_FLT
Definition: jplaeriallib.h:19
#define degrees(radians)
Definition: niwa_iop.c:30
msiBandIdx val
Definition: l1c_msi.cpp:34