17 const char*
const OSGB::letters_ =
"ABCDEFGHJKLMNOPQRSTUVWXYZ";
18 const char*
const OSGB::digits_ =
"0123456789";
20 const TransverseMercator& OSGB::OSGBTM() {
21 static const TransverseMercator osgbtm(EquatorialRadius(), Flattening(),
28 static const real northoffset =
29 ( OSGBTM().Forward(
real(0), OriginLatitude(),
real(0), x, y),
30 FalseNorthing() - y );
37 if (!(prec >= 0 && prec <= maxprec_))
41 if (isnan(x) || isnan(y)) {
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_)];
60 real mult =
real(pow(
real(base_), max(tilelevel_ - prec, 0)));
62 ix = int(floor(xf / mult)),
63 iy = int(floor(yf / mult));
64 for (
int c = min(prec,
int(tilelevel_)); c--;) {
65 grid[z + c] = digits_[ ix % base_ ];
67 grid[z + c + prec] = digits_[ iy % base_ ];
70 if (prec > tilelevel_) {
71 xf -= floor(xf / mult);
72 yf -= floor(yf / mult);
73 mult =
real(pow(
real(base_), prec - tilelevel_));
74 ix = int(floor(xf * mult));
75 iy = int(floor(yf * mult));
76 for (
int c = prec - tilelevel_; c--;) {
77 grid[z + c + tilelevel_] = digits_[ ix % base_ ];
79 grid[z + c + tilelevel_ + prec] = digits_[ iy % base_ ];
83 int mlen = z + 2 * prec;
85 copy(grid, grid + mlen, gridref.begin());
89 real& x, real& y,
int& prec,
92 len = int(gridref.size()),
95 toupper(gridref[0]) ==
'I' &&
96 toupper(gridref[1]) ==
'N') {
101 char grid[2 + 2 * maxprec_];
102 for (
int i = 0; i < len; ++i) {
103 if (!isspace(gridref[i])) {
104 if (p >= 2 + 2 * maxprec_)
106 grid[p++] = gridref[i];
112 throw GeographicErr(
"OSGB string " + gridref +
" too short");
115 " has odd number of characters");
123 yh = yh * tilegrid_ + tilegrid_ - (i / tilegrid_) - 1;
124 xh = xh * tilegrid_ + (i % tilegrid_);
129 int prec1 = (len - p)/2;
134 for (
int i = 0; i < prec1; ++i) {
139 if (ix < 0 || iy < 0)
140 throw GeographicErr(
"Encountered a non-digit in " + gridref);
153 void OSGB::CheckCoords(
real x,
real y) {
157 if (x < minx_ || x >= maxx_)
159 +
"km not in OSGB range [" 162 if (y < miny_ || y >= maxy_)
164 +
"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)