BritishNationalGrid.BritishNationalGridModule

BritishNationalGrid

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 functions:

• 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

The following functions are also exported. Note that these do not check that the longitude and latitude, or easting and northing, supplied to these functions are within the valid region of the grid, and so these functions should be used with care.

• bng2lonlat: Return (unchecked) longitude and latitude from BNG coordinates
• lonlat2bng: Return (unchecked) BNG coordinates from a longitude and latitude

BritishNationalGrid.BNGPointType

Type

BNGPoint{T<:Real}

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

Constructors

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)

Note

An error is thrown if the supplied coordinates do not lie within the valid bounds of the National Grid.

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)

BritishNationalGrid.bng2lonlatMethod
bng2lonlat(e::T1, n::T2) where {T1<:Real, T2<:Real} -> longitude, latitude

Transform from easting and northing in m on the British National Grid to WGS84 longitude and latitude (degrees).

Note

This function does not throw an error if e and n are outside the bounds of the National Grid. Therefore this function should be used with caution.

Example

julia> bng2lonlat(175154, 225430)
(-5.268407238735794, 51.88199105278528)

BritishNationalGrid.gridrefFunction
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="_")
"NU_2915_2300"

BritishNationalGrid.in_gridMethod
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.

BritishNationalGrid.lonlatMethod
lonlat(p::BNGPoint) -> lon, lat

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

BritishNationalGrid.lonlat2bngMethod
lonlat2bng(lon, lat) -> easting, northing

Transform from longitude and latitude (degrees) in WGS84 into BNG easting and northing (m).

Note

This function does not throw an error if lon and lat are at a point outside the bounds of the National Grid. Therefore this function should be used with caution.

Example

julia> lon, lat = -3.183503, 55.954983;

julia> lonlat2bng(lon, lat)
(326200.06052230217, 674183.9198954724)

BritishNationalGrid.squareMethod
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))
"HX"

BritishNationalGrid.square_namesMethod
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]
"HX"
`