# 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)
# Get grid reference at various precisions
osgb_gridref(london_osgb36, precision = 2) # 1 km
osgb_gridref(london_osgb36, precision = 3) # 100 m
osgb_gridref(london_osgb36, precision = 4) # 10 m
# Parse a grid reference
osgb_gridref_rev("TQ3080")
# Round-trip conversion
fwd <- osgb_fwd(london_osgb36)
osgb_rev(fwd$easting, fwd$northing)
Run the code above in your browser using DataLab