uk.me.jstott.jcoord
Class OSRef

java.lang.Object
  extended by uk.me.jstott.jcoord.CoordinateSystem
      extended by uk.me.jstott.jcoord.OSRef

public class OSRef
extends CoordinateSystem

This class is part of the Jcoord package. Visit the Jcoord website for more information.

Class to represent an Ordnance Survey of Great Britain (OSGB) grid reference.

British National Grid

A full reference includes a two-character code identifying a particular 100,000m grid square. The table below shows how the two-character 100,000m grid squares are identified. The bottom left corner is at the false origin of the grid. Squares without values fall outside the boundaries of the British National Grid.

km 0 100 200 300 400 500 600 700
1200 HL HM HN HO HP JL JM
1100 HQ HR HS HT HU JQ JR
1000 HV HW HX HY HZ JV JW
900 NA NB NC ND NE OA OB
800 NF NG NH NJ NK OF OG OH
700 NL NM NN NO NP OL OM ON
600 NQ NR NS NT NU OQ OR OS
500 NW NX NY NZ OV OW OX
400 SB SC SD SE TA TB TC
300 SG SH SJ SK TF TG TH
200 SM SN SO SP TL TM TN
100 SQ SR SS ST SU TQ TR TS
0 SV SW SX SY SZ TV TW

Within each 100,000m square, the grid is further subdivided into 1000m squares. These 1km squares are shown on Ordnance Survey 1:25000 and 1:50000 mapping as the main grid. To reference a 1km square, give the easting and then the northing, e.g. TR2266. In this example, TR represents the 100,000m square, 22 represents the easting (in km) and 66 represents the northing (in km). This is commonly called a four-figure grid reference.

It is possible to extend the four-figure grid reference for more accuracy. For example, a six-figure grid reference would be accurate to 100m and an eight-figure grid reference would be accurate to 10m.

When providing local references, the 2 characters representing the 100,000m square are often omitted.

(c) 2006 Jonathan Stott

Created on 11-02-2006

Since:
1.0
Version:
1.0
Author:
Jonathan Stott

Constructor Summary
OSRef(double easting, double northing)
          Create a new Ordnance Survey grid reference using a given easting and northing.
OSRef(LatLng ll)
          Convert this latitude and longitude into an OSGB (Ordnance Survey of Great Britain) grid reference.
OSRef(java.lang.String ref)
          Take a string formatted as a six-figure OS grid reference (e.g.
 
Method Summary
 double getEasting()
          Get the easting in metres relative the origin of the British National Grid.
 double getNorthing()
          Get the northing in metres relative to the origin of the British National Grid.
 void setEasting(double easting)
          Set the easting for this OSRef.
 void setNorthing(double northing)
          Set the northing for this OSRef
 LatLng toLatLng()
          Convert this OSGB grid reference to a latitude/longitude pair using the OSGB36 datum.
 java.lang.String toSixFigureString()
          Return a String representation of this OSGB grid reference using the six-figure notation in the form XY123456
 java.lang.String toString()
          Return a String representation of this OSGB grid reference showing the easting and northing.
 
Methods inherited from class uk.me.jstott.jcoord.CoordinateSystem
getDatum, setDatum
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OSRef

public OSRef(double easting,
             double northing)
      throws java.lang.IllegalArgumentException
Create a new Ordnance Survey grid reference using a given easting and northing. The easting and northing must be in metres and must be relative to the origin of the British National Grid.

Parameters:
easting - the easting in metres. Must be greater than or equal to 0.0 and less than 800000.0.
northing - the northing in metres. Must be greater than or equal to 0.0 and less than 1400000.0.
Throws:
java.lang.IllegalArgumentException - if either the easting or the northing are invalid.
Since:
1.0

OSRef

public OSRef(java.lang.String ref)
      throws java.lang.IllegalArgumentException
Take a string formatted as a six-figure OS grid reference (e.g. "TG514131") and create a new OSRef object that represents that grid reference. The first character must be H, N, S, O or T. The second character can be any uppercase character from A through Z excluding I.

Parameters:
ref - a String representing a six-figure Ordnance Survey grid reference in the form XY123456
Throws:
java.lang.IllegalArgumentException - if ref is not of the form XY123456
Since:
1.0

OSRef

public OSRef(LatLng ll)
Convert this latitude and longitude into an OSGB (Ordnance Survey of Great Britain) grid reference.

Since:
1.1
Method Detail

toString

public java.lang.String toString()
Return a String representation of this OSGB grid reference showing the easting and northing.

Overrides:
toString in class java.lang.Object
Returns:
a String represenation of this OSGB grid reference
Since:
1.0

toSixFigureString

public java.lang.String toSixFigureString()
Return a String representation of this OSGB grid reference using the six-figure notation in the form XY123456

Returns:
a String representing this OSGB grid reference in six-figure notation
Since:
1.0

toLatLng

public LatLng toLatLng()
Convert this OSGB grid reference to a latitude/longitude pair using the OSGB36 datum. Note that, the LatLng object may need to be converted to the WGS84 datum depending on the application.

Specified by:
toLatLng in class CoordinateSystem
Returns:
a LatLng object representing this OSGB grid reference using the OSGB36 datum
Since:
1.0

getEasting

public double getEasting()
Get the easting in metres relative the origin of the British National Grid.

Returns:
the easting in metres.
Since:
1.0

getNorthing

public double getNorthing()
Get the northing in metres relative to the origin of the British National Grid.

Returns:
the northing in metres.
Since:
1.0

setEasting

public void setEasting(double easting)
                throws java.lang.IllegalArgumentException
Set the easting for this OSRef.

Parameters:
easting - the easting in metres. Must be greater than or equal to 0.0 and less than 800000.0.
Throws:
java.lang.IllegalArgumentException - if the easting is invalid.

setNorthing

public void setNorthing(double northing)
                 throws java.lang.IllegalArgumentException
Set the northing for this OSRef

Parameters:
northing - the northing in metres. Must be greater than or equal to 0.0 and less than 1400000.0.
Throws:
java.lang.IllegalArgumentException - if either the northing is invalid.