Convert between longitude and latitude and coordinates of the British National Grid.

The BNGPoint type and constructor is used to create points with easting and northings These are given relative to the grid's false origin southwest of the Isles of Scilly.

Exported methods:

  • BNGPoint: Construct a new point on the grid
  • gridref: Return a string with an n-figure grid reference
  • lonlat: Convert a grid point to WGS84 longitude and latitude
  • square: Determine which National Grid 100 km square a point is in

See the documentation for each method to learn more.




A struct holding the easting and northing of a point within the British National Grid.


BNGPoint(e, n)

Provide eastings e and northings n in m from the grid origin.

BNGPoint(e, n, square)

Provide a point within a 100 km square and its name as a two-character string, creating a point with a full reference

julia> BNGPoint(101, 12345, "OV")
BritishNationalGrid.BNGPoint{Int64}(500101, 512345)
BNGPoint(; lon=0, lat=0)

Convert a WGS84 longitude lon and latitude lat in degrees, into a grid point.

julia> BNGPoint(lon=-1.54, lat=55.5)
BNGPoint{Float64}(429158.6966862687, 623009.0927592682)

Acessing fields

A BNGPoint contains the following fields:

  • e: Easting in m
  • n: Northing in m

These fields are part of the API, and therefore it is safe and expected for users to extract the eastings and northings from a BNGPoint like so:

```jldoctest julia> p = BNGPoint(lon=-1.54, lat=55.5) BNGPoint{Float64}(429158.6966862687, 623009.0927592682)

julia> p.e, p.n (429158.6966862687, 623009.0927592682)

gridref(p::BNGPoint, n; square=false, sep=' ')

Return a string giving an n-figure grid reference. By default, a full reference is given. If square is true, then supply the 100 km square name first, then the reference within that square. The square, eastings and northings are separated by sep.

julia> gridref(BNGPoint(429157, 623009), 8, square=true, sep="_")
in_grid(e, n) -> ::Bool

Return true if the easting e and northing n (in m) are within the British National Grid, and false otherwise.

lonlat(p::BNGPoint) -> lon, lat

Return the WGS84 longitude lon and latitude lat in decimal degrees for the point p.

lonlat2bng(lon, lat) -> easting, northing
lonlat2bng(lon::AbstractArray, lat::AbstractArray) -> A::Array

Transform from longitude and latitude in WGS84 into BNG easting and northing (m). The first form does so for scalars and returns a tuple; the second form does so for length-n arrays and returns a n-by-2 array where the first column is the easting, and the second is the northing.

square(p::BNGPoint) -> XX::String

Return a two-character string XX containing the name of the 100 km-by 100 km square in which is located the point p.

julia> using BritishNationalGrid

julia> BritishNationalGrid.square(BNGPoint(200_000, 1_000_000))
square_names() -> names::Array{String,2}

Build the two-letter codes of each 100 km-b-100 km square of the grid. Access the names by:

julia> using BritishNationalGrid

julia> easting, northing = 200_000, 1_000_000
(200000, 1000000)

julia> squares = BritishNationalGrid.square_names()
13×7 Array{String,2}:
 "SV"  "SW"  "SX"  "SY"  "SZ"  "TV"  "TW"
 "SQ"  "SR"  "SS"  "ST"  "SU"  "TQ"  "TR"
 "SL"  "SM"  "SN"  "SO"  "SP"  "TL"  "TM"
 "SF"  "SG"  "SH"  "SJ"  "SK"  "TF"  "TG"
 "SA"  "SB"  "SC"  "SD"  "SE"  "TA"  "TB"
 "NV"  "NW"  "NX"  "NY"  "NZ"  "OV"  "OW"
 "NQ"  "NR"  "NS"  "NT"  "NU"  "OQ"  "OR"
 "NL"  "NM"  "NN"  "NO"  "NP"  "OL"  "OM"
 "NF"  "NG"  "NH"  "NJ"  "NK"  "OF"  "OG"
 "NA"  "NB"  "NC"  "ND"  "NE"  "OA"  "OB"
 "HV"  "HW"  "HX"  "HY"  "HZ"  "JV"  "JW"
 "HQ"  "HR"  "HS"  "HT"  "HU"  "JQ"  "JR"
 "HL"  "HM"  "HN"  "HO"  "HP"  "JL"  "JM"

julia> squares[floor(Int, northing/100_000)+1, floor(Int, easting/100_000)+1]