MGRS.hpp
Go to the documentation of this file.
1 
10 #if !defined(GEOGRAPHICLIB_MGRS_HPP)
11 #define GEOGRAPHICLIB_MGRS_HPP 1
12 
14 #include <GeographicLib/UTMUPS.hpp>
15 
16 #if defined(_MSC_VER)
17 // Squelch warnings about dll vs string
18 # pragma warning (push)
19 # pragma warning (disable: 4251)
20 #endif
21 
22 namespace GeographicLib {
23 
75  private:
76  typedef Math::real real;
77  static const char* const hemispheres_;
78  static const char* const utmcols_[3];
79  static const char* const utmrow_;
80  static const char* const upscols_[4];
81  static const char* const upsrows_[2];
82  static const char* const latband_;
83  static const char* const upsband_;
84  static const char* const digits_;
85 
86  static const int mineasting_[4];
87  static const int maxeasting_[4];
88  static const int minnorthing_[4];
89  static const int maxnorthing_[4];
90  enum {
91  base_ = 10,
92  // Top-level tiles are 10^5 m = 100 km on a side
93  tilelevel_ = 5,
94  // Period of UTM row letters
95  utmrowperiod_ = 20,
96  // Row letters are shifted by 5 for even zones
97  utmevenrowshift_ = 5,
98  // Maximum precision is um
99  maxprec_ = 5 + 6,
100  // For generating digits at maxprec
101  mult_ = 1000000,
102  };
103  static void CheckCoords(bool utmp, bool& northp, real& x, real& y);
104  static int UTMRow(int iband, int icol, int irow);
105 
106  friend class UTMUPS; // UTMUPS::StandardZone calls LatitudeBand
107  // Return latitude band number [-10, 10) for the given latitude (degrees).
108  // The bands are reckoned in include their southern edges.
109  static int LatitudeBand(real lat) {
110  using std::floor;
111  int ilat = int(floor(lat));
112  return (std::max)(-10, (std::min)(9, (ilat + 80)/8 - 10));
113  }
114  // Return approximate latitude band number [-10, 10) for the given northing
115  // (meters). With this rule, each 100km tile would have a unique band
116  // letter corresponding to the latitude at the center of the tile. This
117  // function isn't currently used.
118  static int ApproxLatitudeBand(real y) {
119  // northing at tile center in units of tile = 100km
120  using std::floor; using std::abs;
121  real ya = floor( (std::min)(real(88), abs(y/tile_)) ) +
122  real(0.5);
123  // convert to lat (mult by 90/100) and then to band (divide by 8)
124  // the +1 fine tunes the boundary between bands 3 and 4
125  int b = int(floor( ((ya * 9 + 1) / 10) / 8 ));
126  // For the northern hemisphere we have
127  // band rows num
128  // N 0 0:8 9
129  // P 1 9:17 9
130  // Q 2 18:26 9
131  // R 3 27:34 8
132  // S 4 35:43 9
133  // T 5 44:52 9
134  // U 6 53:61 9
135  // V 7 62:70 9
136  // W 8 71:79 9
137  // X 9 80:94 15
138  return y >= 0 ? b : -(b + 1);
139  }
140  // UTMUPS access these enums
141  enum {
142  tile_ = 100000, // Size MGRS blocks
143  minutmcol_ = 1,
144  maxutmcol_ = 9,
145  minutmSrow_ = 10,
146  maxutmSrow_ = 100, // Also used for UTM S false northing
147  minutmNrow_ = 0, // Also used for UTM N false northing
148  maxutmNrow_ = 95,
149  minupsSind_ = 8, // These 4 ind's apply to easting and northing
150  maxupsSind_ = 32,
151  minupsNind_ = 13,
152  maxupsNind_ = 27,
153  upseasting_ = 20, // Also used for UPS false northing
154  utmeasting_ = 5, // UTM false easting
155  // Difference between S hemisphere northing and N hemisphere northing
156  utmNshift_ = (maxutmSrow_ - minutmNrow_) * tile_
157  };
158  MGRS(); // Disable constructor
159 
160  public:
161 
243  static void Forward(int zone, bool northp, real x, real y,
244  int prec, std::string& mgrs);
245 
267  static void Forward(int zone, bool northp, real x, real y, real lat,
268  int prec, std::string& mgrs);
269 
315  static void Reverse(const std::string& mgrs,
316  int& zone, bool& northp, real& x, real& y,
317  int& prec, bool centerp = true);
318 
321 
329 
336  static Math::real Flattening() { return UTMUPS::Flattening(); }
338 
345  static void Check();
346 
347  };
348 
349 } // namespace GeographicLib
350 
351 #if defined(_MSC_VER)
352 # pragma warning (pop)
353 #endif
354 
355 #endif // GEOGRAPHICLIB_MGRS_HPP
#define max(a, b)
Definition: datatypes.h:20
Math::real real
Definition: MGRS.hpp:76
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:91
float real
Definition: datatypes.h:10
Scalar * y
Scalar * b
Definition: benchVecAdd.cpp:17
static const double lat
static Math::real Flattening()
Definition: UTMUPS.hpp:414
static Math::real MajorRadius()
Definition: MGRS.hpp:328
#define min(a, b)
Definition: datatypes.h:19
static const char *const digits_
Definition: MGRS.hpp:84
Header for GeographicLib::UTMUPS class.
static const char *const upsband_
Definition: MGRS.hpp:83
static const char *const hemispheres_
Definition: MGRS.hpp:77
static int LatitudeBand(real lat)
Definition: MGRS.hpp:109
static Math::real MajorRadius()
Definition: UTMUPS.hpp:405
EIGEN_DEVICE_FUNC const FloorReturnType floor() const
Convert between geographic coordinates and UTM/UPS.
Definition: UTMUPS.hpp:75
Namespace for GeographicLib.
Header for GeographicLib::Constants class.
static int ApproxLatitudeBand(real y)
Definition: MGRS.hpp:118
static Math::real Flattening()
Definition: MGRS.hpp:336
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
#define abs(x)
Definition: datatypes.h:17
static const char *const latband_
Definition: MGRS.hpp:82
Convert between UTM/UPS and MGRS.
Definition: MGRS.hpp:74
static const char *const utmrow_
Definition: MGRS.hpp:79


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:55