17 const string OSGB::letters_ =
"ABCDEFGHJKLMNOPQRSTUVWXYZ";
18 const string OSGB::digits_ =
"0123456789";
20 const TransverseMercator& OSGB::OSGBTM() {
21 static const TransverseMercator osgbtm(MajorRadius(), Flattening(),
27 bool OSGB::init_ =
false;
32 OSGBTM().Forward(
real(0), OriginLatitude(),
real(0), x, y);
33 northoffset_ = FalseNorthing() - y;
41 if (!(prec >= 0 && prec <= maxprec_))
45 char grid[2 + 2 * maxprec_];
47 xh = int(floor(x)) / tile_,
48 yh = int(floor(y)) / tile_;
55 grid[z++] = letters_[(tilegrid_ - (yh / tilegrid_) - 1)
56 * tilegrid_ + (xh / tilegrid_)];
57 grid[z++] = letters_[(tilegrid_ - (yh % tilegrid_) - 1)
58 * tilegrid_ + (xh % tilegrid_)];
59 real mult = pow(
real(base_), max(tilelevel_ - prec, 0));
61 ix = int(floor(xf / mult)),
62 iy = int(floor(yf / mult));
63 for (
int c = min(prec,
int(tilelevel_)); c--;) {
64 grid[z + c] = digits_[ ix % base_ ];
66 grid[z + c + prec] = digits_[ iy % base_ ];
69 if (prec > tilelevel_) {
70 xf -= floor(xf / mult);
71 yf -= floor(yf / mult);
72 mult = pow(
real(base_), prec - tilelevel_);
73 ix = int(floor(xf * mult));
74 iy = int(floor(yf * mult));
75 for (
int c = prec - tilelevel_; c--;) {
76 grid[z + c + tilelevel_] = digits_[ ix % base_ ];
78 grid[z + c + tilelevel_ + prec] = digits_[ iy % base_ ];
82 int mlen = z + 2 * prec;
84 copy(grid, grid + mlen, gridref.begin());
88 real& x, real& y,
int& prec,
91 len = int(gridref.size()),
93 char grid[2 + 2 * maxprec_];
94 for (
int i = 0; i < len; ++i) {
95 if (!isspace(gridref[i])) {
96 if (p >= 2 + 2 * maxprec_)
98 grid[p++] = gridref[i];
104 throw GeographicErr(
"OSGB string " + gridref +
" too short");
107 " has odd number of characters");
115 yh = yh * tilegrid_ + tilegrid_ - (i / tilegrid_) - 1;
116 xh = xh * tilegrid_ + (i % tilegrid_);
121 int prec1 = (len - p)/2;
126 for (
int i = 0; i < prec1; ++i) {
131 if (ix < 0 || iy < 0)
132 throw GeographicErr(
"Encountered a non-digit in " + gridref);
145 void OSGB::CheckCoords(
real x,
real y) {
149 if (! (x >= minx_ && x < maxx_) )
151 +
"km not in OSGB range ["
154 if (! (y >= miny_ && y < maxy_) )
156 +
"km not in OSGB range ["
GeographicLib::Math::real real
Header for GeographicLib::Utility class.
Header for GeographicLib::OSGB class.
Namespace for GeographicLib.
static std::string str(T x, int p=-1)
static void GridReference(real x, real y, int prec, std::string &gridref)
Exception handling for GeographicLib.
static int lookup(const std::string &s, char c)