Ordnance Survey grid system for Great Britain.
The class implements the coordinate system used by the Ordnance Survey for maps of Great Britain and conversions to the grid reference system.
See
- Warning
- the latitudes and longitudes for the Ordnance Survey grid system do not use the WGS84 datum. Do not use the values returned by this class in the UTMUPS, MGRS, or Geoid classes without first converting the datum (and vice versa).
Example of use:
#include <iostream>
#include <iomanip>
#include <exception>
#include <string>
try {
{
double
string gridref;
cout << fixed << setprecision(3)
<< x << " " << y << " " << gridref << "\n";
}
{
string gridref = "TG5113";
int prec;
cout << fixed << setprecision(8)
<< prec << " " << lat << " " << lon << "\n";
}
}
catch (const exception& e) {
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
}
Definition at line 44 of file OSGB.hpp.
void GeographicLib::OSGB::GridReference |
( |
real |
x, |
|
|
real |
y, |
|
|
int |
prec, |
|
|
std::string & |
gridref |
|
) |
| |
|
static |
Convert OSGB coordinates to a grid reference.
- Parameters
-
[in] | x | easting of point (meters). |
[in] | y | northing of point (meters). |
[in] | prec | precision relative to 100 km. |
[out] | gridref | National Grid reference. |
- Exceptions
-
GeographicErr | if prec, x, or y is outside its allowed range. |
std::bad_alloc | if the memory for gridref can't be allocatied. |
prec specifies the precision of the grid reference string as follows:
- prec = 0 (min), 100km
- prec = 1, 10km
- prec = 2, 1km
- prec = 3, 100m
- prec = 4, 10m
- prec = 5, 1m
- prec = 6, 0.1m
- prec = 11 (max), 1μm
The easting must be in the range [−1000 km, 1500 km) and the northing must be in the range [−500 km, 2000 km). These bounds are consistent with rules for the letter designations for the grid system.
If x or y is NaN, the returned grid reference is "INVALID".
Definition at line 34 of file src/OSGB.cpp.
void GeographicLib::OSGB::GridReference |
( |
const std::string & |
gridref, |
|
|
real & |
x, |
|
|
real & |
y, |
|
|
int & |
prec, |
|
|
bool |
centerp = true |
|
) |
| |
|
static |
Convert OSGB coordinates to a grid reference.
- Parameters
-
[in] | gridref | National Grid reference. |
[out] | x | easting of point (meters). |
[out] | y | northing of point (meters). |
[out] | prec | precision relative to 100 km. |
[in] | centerp | if true (default), return center of the grid square, else return SW (lower left) corner. |
- Exceptions
-
The grid reference must be of the form: two letters (not including I) followed by an even number of digits (up to 22).
If the first 2 characters of gridref are "IN", then x and y are set to NaN and prec is set to −2.
Definition at line 87 of file src/OSGB.cpp.