Class: DefraRuby::Address::TransverseMercatorProjection

Inherits:
Object
  • Object
show all
Defined in:
lib/defra_ruby/address/transverse_mercator_projection.rb

Overview

Converts between British National Grid easting/northing and OSGB36 latitude/longitude, a Transverse Mercator projection on the Airy 1830 ellipsoid. Variable names follow the terms in the OS guide "A guide to coordinate systems in Great Britain".

The easting/northing to lat/lon direction is ported from the breasal gem (https://github.com/theodi/breasal, MIT licence, copyright 2013 pezholio). Breasal has no reverse conversion, so that direction comes straight from the OS guide's forward projection formulae.

Constant Summary collapse

A =
HelmertTransformation::AIRY_1830[:a]
B =
HelmertTransformation::AIRY_1830[:b]
E_SQUARED =
((A * A) - (B * B)) / (A * A)
N =
(A - B) / (A + B)
F0 =
0.9996012717
PHI0 =
49.0 * Math::PI / 180
LAMBDA0 =
-2.0 * Math::PI / 180
E0 =
400_000.0
N0 =
-100_000.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.easting_northing_to_lat_lon(easting, northing) ⇒ Object



26
27
28
# File 'lib/defra_ruby/address/transverse_mercator_projection.rb', line 26

def self.easting_northing_to_lat_lon(easting, northing)
  new.easting_northing_to_lat_lon(easting, northing)
end

.lat_lon_to_easting_northing(latitude, longitude) ⇒ Object



30
31
32
# File 'lib/defra_ruby/address/transverse_mercator_projection.rb', line 30

def self.lat_lon_to_easting_northing(latitude, longitude)
  new.lat_lon_to_easting_northing(latitude, longitude)
end

Instance Method Details

#easting_northing_to_lat_lon(easting, northing) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/defra_ruby/address/transverse_mercator_projection.rb', line 34

def easting_northing_to_lat_lon(easting, northing)
  phi_prime = converged_phi_prime(northing)
  delta_e = easting - E0

  [latitude_from(phi_prime, delta_e) * 180 / Math::PI,
   longitude_from(phi_prime, delta_e) * 180 / Math::PI]
end

#lat_lon_to_easting_northing(latitude, longitude) ⇒ Object



42
43
44
45
46
47
# File 'lib/defra_ruby/address/transverse_mercator_projection.rb', line 42

def lat_lon_to_easting_northing(latitude, longitude)
  phi = latitude * Math::PI / 180
  delta_lambda = (longitude * Math::PI / 180) - LAMBDA0

  [easting_from(phi, delta_lambda), northing_from(phi, delta_lambda)]
end