15# pragma warning (disable: 5055)
22 const char*
const OSGB::letters_ =
"ABCDEFGHJKLMNOPQRSTUVWXYZ";
23 const char*
const OSGB::digits_ =
"0123456789";
25 const TransverseMercator& OSGB::OSGBTM() {
33 static const real northoffset =
42 if (!(prec >= 0 && prec <= maxprec_))
46 if (isnan(x) || isnan(y)) {
50 char grid[2 + 2 * maxprec_];
52 xh = int(floor(x / tile_)),
53 yh = int(floor(y / tile_));
60 grid[z++] = letters_[(tilegrid_ - (yh / tilegrid_) - 1)
61 * tilegrid_ + (xh / tilegrid_)];
62 grid[z++] = letters_[(tilegrid_ - (yh % tilegrid_) - 1)
63 * tilegrid_ + (xh % tilegrid_)];
65 real mult = real(pow(real(base_), max(tilelevel_ - prec, 0)));
67 ix = int(floor(xf / mult)),
68 iy = int(floor(yf / mult));
69 for (
int c = min(prec,
int(tilelevel_)); c--;) {
70 grid[z + c] = digits_[ ix % base_ ];
72 grid[z + c + prec] = digits_[ iy % base_ ];
75 if (prec > tilelevel_) {
76 xf -= floor(xf / mult);
77 yf -= floor(yf / mult);
78 mult = real(pow(real(base_), prec - tilelevel_));
79 ix = int(floor(xf * mult));
80 iy = int(floor(yf * mult));
81 for (
int c = prec - tilelevel_; c--;) {
82 grid[z + c + tilelevel_] = digits_[ ix % base_ ];
84 grid[z + c + tilelevel_ + prec] = digits_[ iy % base_ ];
88 int mlen = z + 2 * prec;
90 copy(grid, grid + mlen, gridref.begin());
94 real& x, real& y,
int& prec,
97 len = int(gridref.size()),
100 toupper(gridref[0]) ==
'I' &&
101 toupper(gridref[1]) ==
'N') {
106 char grid[2 + 2 * maxprec_];
107 for (
int i = 0; i < len; ++i) {
108 if (!isspace(gridref[i])) {
109 if (p >= 2 + 2 * maxprec_)
111 grid[p++] = gridref[i];
117 throw GeographicErr(
"OSGB string " + gridref +
" too short");
120 " has odd number of characters");
128 yh = yh * tilegrid_ + tilegrid_ - (i / tilegrid_) - 1;
129 xh = xh * tilegrid_ + (i % tilegrid_);
134 int prec1 = (len - p)/2;
139 for (
int i = 0; i < prec1; ++i) {
144 if (ix < 0 || iy < 0)
145 throw GeographicErr(
"Encountered a non-digit in " + gridref);
158 void OSGB::CheckCoords(
real x,
real y) {
162 if (x < minx_ || x >= maxx_)
164 +
"km not in OSGB range ["
167 if (y < miny_ || y >= maxy_)
169 +
"km not in OSGB range ["
GeographicLib::Math::real real
Header for GeographicLib::OSGB class.
Header for GeographicLib::Utility class.
Exception handling for GeographicLib.
static void GridReference(real x, real y, int prec, std::string &gridref)
static Math::real CentralScale()
static Math::real EquatorialRadius()
static Math::real FalseNorthing()
static Math::real Flattening()
static Math::real OriginLatitude()
void Forward(real lon0, real lat, real lon, real &x, real &y, real &gamma, real &k) const
static int lookup(const std::string &s, char c)
static std::string str(T x, int p=-1)
Namespace for GeographicLib.