Class: Breasal::LatLng
Instance Method Summary collapse
-
#initialize(options) ⇒ LatLng
constructor
A new instance of LatLng.
-
#to_WGS84 ⇒ Object
and returns WGS84 Latitude and Longitude.
Methods included from Utils
#cos_pow_2, #deg_to_rad, #rad_to_deg, #sec, #sin_pow_2, #tan_pow_2
Constructor Details
#initialize(options) ⇒ LatLng
Returns a new instance of LatLng.
7 8 9 10 11 |
# File 'lib/breasal/latlng.rb', line 7 def initialize() @latitude = [:latitude] @longitude = [:longitude] @type = [:type] || :gb end |
Instance Method Details
#to_WGS84 ⇒ Object
and returns WGS84 Latitude and Longitude
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/breasal/latlng.rb', line 15 def to_WGS84 if @type == :ie @a = 6377340.189 @b = 6356034.447 else @a = 6377563.396 @b = 6356256.909 end @eSquared = ((@a * @a) - (@b * @b)) / (@a * @a) @phi = deg_to_rad(@latitude) @lambda = deg_to_rad(@longitude) @v = @a / (Math.sqrt(1 - @eSquared * sin_pow_2(@phi))) @H = 0 @x = (@v + @H) * Math.cos(@phi) * Math.cos(@lambda) @y = (@v + @H) * Math.cos(@phi) * Math.sin(@lambda) @z = ((1 - @eSquared) * @v + @H) * Math.sin(@phi) @tx = 446.448 @ty = -124.157 @tz = 542.060 @s = -0.0000204894 @rx = deg_to_rad( 0.00004172222) @ry = deg_to_rad( 0.00006861111) @rz = deg_to_rad( 0.00023391666) @xB = @tx + (@x * (1 + @s)) + (-@rx * @y) + (@ry * @z) @yB = @ty + (@rz * @x) + (@y * (1 + @s)) + (-@rx * @z) @zB = @tz + (-@ry * @x) + (@rx * @y) + (@z * (1 + @s)) @a = 6378137.000 @b = 6356752.3141 @eSquared = ((@a * @a) - (@b * @b)) / (@a * @a) @lambdaB = rad_to_deg(Math.atan(@yB / @xB)) @p = Math.sqrt((@xB * @xB) + (@yB * @yB)) @phiN = Math.atan(@zB / (@p * (1 - @eSquared))) (1..10).each do |i| @v = @a / (Math.sqrt(1 - @eSquared * sin_pow_2(@phiN))) @phiN1 = Math.atan((@zB + (@eSquared * @v * Math.sin(@phiN))) / @p) @phiN = @phiN1 end @phiB = rad_to_deg(@phiN) { :latitude => @phiB, :longitude => @lambdaB } end |