Convert between geographic coordinates and the Ordnance Survey National Grid used in Great Britain.

Important: These functions expect coordinates on the OSGB36 datum, not WGS84. For WGS84 coordinates (e.g., from GPS), you need to perform a datum transformation first using another package such as sf.

osgb_fwd(x)

osgb_rev(easting, northing)

osgb_gridref(x, precision = 2L)

osgb_gridref_rev(gridref)

Arguments

x

For osgb_fwd() and osgb_gridref(): a two-column matrix or data frame of OSGB36 coordinates (longitude, latitude) in decimal degrees.

easting

Numeric vector of OSGB eastings in meters.

northing

Numeric vector of OSGB northings in meters.

precision

Integer specifying the precision of grid references:

  • -1: 500 km squares (first letter only)

  • 0: 100 km squares (two letters)

  • 1: 10 km (2 digits)

  • 2: 1 km (4 digits)

  • 3: 100 m (6 digits)

  • 4: 10 m (8 digits)

  • 5: 1 m (10 digits)

gridref

Character vector of OSGB grid reference strings.

Value

  • osgb_fwd(): Data frame with columns:

    • easting: OSGB easting in meters

    • northing: OSGB northing in meters

    • convergence: Grid convergence in degrees

    • scale: Scale factor

    • lon, lat: Input OSGB36 coordinates (echoed)

  • osgb_rev(): Data frame with columns:

    • lon: OSGB36 longitude in decimal degrees

    • lat: OSGB36 latitude in decimal degrees

    • convergence: Grid convergence in degrees

    • scale: Scale factor

    • easting, northing: Input coordinates (echoed)

  • osgb_gridref(): Character vector of grid reference strings.

  • osgb_gridref_rev(): Data frame with columns:

    • lon: OSGB36 longitude in decimal degrees

    • lat: OSGB36 latitude in decimal degrees

    • easting: OSGB easting in meters

    • northing: OSGB northing in meters

    • precision: Precision level of the grid reference

Details

The Ordnance Survey National Grid is a geographic grid reference system used in Great Britain. It uses the OSGB36 datum and a Transverse Mercator projection.

Grid references are alphanumeric codes like "TQ3080" for central London. The format is two letters (100 km square) followed by an even number of digits.

Datum note: The difference between WGS84 and OSGB36 can be up to ~100m. For precise work, transform WGS84 coordinates to OSGB36 first.

Examples

# OSGB36 coordinates for central London (not WGS84!)
# In practice, you would transform from WGS84 first
london_osgb36 <- c(-0.1270, 51.5072)

# Convert to OSGB grid
osgb_fwd(london_osgb36)
#>    easting northing convergence     scale    lon     lat
#> 1 529971.9 180413.2    1.466175 0.9998087 -0.127 51.5072

# Get grid reference at various precisions
osgb_gridref(london_osgb36, precision = 2)  # 1 km
#> [1] "TQ2980"
osgb_gridref(london_osgb36, precision = 3)  # 100 m
#> [1] "TQ299804"
osgb_gridref(london_osgb36, precision = 4)  # 10 m
#> [1] "TQ29978041"

# Parse a grid reference
osgb_gridref_rev("TQ3080")
#>         lon      lat easting northing precision
#> 1 -0.119362 51.50786  530500   180500         2

# Round-trip conversion
fwd <- osgb_fwd(london_osgb36)
osgb_rev(fwd$easting, fwd$northing)
#>      lon     lat convergence     scale  easting northing
#> 1 -0.127 51.5072    1.466175 0.9998087 529971.9 180413.2