Class: Silva::System::Gridref
- Includes:
- OsEn
- Defined in:
- lib/silva/system/gridref.rb
Overview
Location system representing Ordnance Survey Standard Grid References.
Can be created given the options :easting => e, :northing => n or :gridref => g
Constant Summary collapse
- DEFAULT_PARAMS =
:digits can be 6, 8 or 10
{ :digits => 8 }
- OSGB_PREFIXES =
UK two-letter prefixes
["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"]
- OSGB_GRID_WIDTH =
Width of the UK grid
7
- OSGB_GRID_SCALE =
Height of the UK grid
100000
Constants included from OsEn
OsEn::EASTING_RANGE, OsEn::NORTHING_RANGE, OsEn::REQUIRED_PARAMS
Constants inherited from Base
Instance Attribute Summary
Attributes included from OsEn
Instance Method Summary collapse
-
#gridref ⇒ String
Lazily create the gridref from given eastings and northings, or just return it if already set.
- #to_s ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from Silva::System::Base
Instance Method Details
#gridref ⇒ String
Lazily create the gridref from given eastings and northings, or just return it if already set.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/silva/system/gridref.rb', line 40 def gridref unless @gridref e100k = (easting / 100000).floor n100k = (northing / 100000).floor index = n100k * OSGB_GRID_WIDTH + e100k prefix = OSGB_PREFIXES[index] e = ((easting % OSGB_GRID_SCALE) / (10**(5 - @digits / 2))).round n = ((northing % OSGB_GRID_SCALE) / (10**(5 - @digits / 2))).round @gridref = prefix + e.to_s.rjust(@digits / 2, '0') + n.to_s.rjust(@digits / 2, '0') end @gridref end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/silva/system/gridref.rb', line 56 def to_s gridref end |