17 const string OSGB::letters_ =
"ABCDEFGHJKLMNOPQRSTUVWXYZ";
18 const string OSGB::digits_ =
"0123456789";
20 const TransverseMercator& OSGB::OSGBTM() {
21 static const TransverseMercator osgbtm(MajorRadius(), Flattening(),
28 static const real northoffset =
29 ( OSGBTM().Forward(
real(0), OriginLatitude(),
real(0), x, y),
30 FalseNorthing() - y );
36 if (!(prec >= 0 && prec <= maxprec_))
44 char grid[2 + 2 * maxprec_];
46 xh = int(floor(x / tile_)),
47 yh = int(floor(y / tile_));
54 grid[z++] = letters_[(tilegrid_ - (yh / tilegrid_) - 1)
55 * tilegrid_ + (xh / tilegrid_)];
56 grid[z++] = letters_[(tilegrid_ - (yh % tilegrid_) - 1)
57 * tilegrid_ + (xh % tilegrid_)];
58 real mult = pow(
real(base_), max(tilelevel_ - prec, 0));
60 ix = int(floor(xf / mult)),
61 iy = int(floor(yf / mult));
62 for (
int c = min(prec,
int(tilelevel_)); c--;) {
63 grid[z + c] = digits_[ ix % base_ ];
65 grid[z + c + prec] = digits_[ iy % base_ ];
68 if (prec > tilelevel_) {
69 xf -= floor(xf / mult);
70 yf -= floor(yf / mult);
71 mult = pow(
real(base_), prec - tilelevel_);
72 ix = int(floor(xf * mult));
73 iy = int(floor(yf * mult));
74 for (
int c = prec - tilelevel_; c--;) {
75 grid[z + c + tilelevel_] = digits_[ ix % base_ ];
77 grid[z + c + tilelevel_ + prec] = digits_[ iy % base_ ];
81 int mlen = z + 2 * prec;
83 copy(grid, grid + mlen, gridref.begin());
87 real& x, real& y,
int& prec,
90 len = int(gridref.size()),
93 toupper(gridref[0]) ==
'I' &&
94 toupper(gridref[1]) ==
'N') {
99 char grid[2 + 2 * maxprec_];
100 for (
int i = 0; i < len; ++i) {
101 if (!isspace(gridref[i])) {
102 if (p >= 2 + 2 * maxprec_)
104 grid[p++] = gridref[i];
110 throw GeographicErr(
"OSGB string " + gridref +
" too short");
113 " has odd number of characters");
121 yh = yh * tilegrid_ + tilegrid_ - (i / tilegrid_) - 1;
122 xh = xh * tilegrid_ + (i % tilegrid_);
127 int prec1 = (len - p)/2;
132 for (
int i = 0; i < prec1; ++i) {
137 if (ix < 0 || iy < 0)
138 throw GeographicErr(
"Encountered a non-digit in " + gridref);
151 void OSGB::CheckCoords(real x, real y) {
155 if (x < minx_ || x >= maxx_)
157 +
"km not in OSGB range [" 160 if (y < miny_ || y >= maxy_)
162 +
"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)