breasal 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c02849fafca9316143e9d3e6adb58ea6b3c89b5
4
+ data.tar.gz: 5aaffddb410739c76b6ba64a7f2d3b5488c154f7
5
+ SHA512:
6
+ metadata.gz: 46bb4f7a6eb76030568b907e6778e63171a52d0398fb42a6c832eff23d22d5516303100c9f0319560d78ee7044678d407d0784e72e52057fa192662a6cb04d1b
7
+ data.tar.gz: 294f4a46556d3e28077bf603670a3f3aa2a858deb5286084c5ef3cbb2c766f6f3d52a448a111e6772c6a41a45ecba35fc8fee7483c81977a00e026652b15b2e0
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,20 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+ notifications:
6
+ irc:
7
+ channels:
8
+ - "irc.freenode.net#theodi"
9
+ template:
10
+ - "%{repository} %{branch} - %{message} %{build_url}"
11
+ on_success: change
12
+ on_failure: always
13
+ deploy:
14
+ provider: rubygems
15
+ api_key:
16
+ secure: "UZ7kuAfrrDfKSsmWwiPq1kS9jThJPFcxwSEyfH2sRSy4GAqqMp/E3y3Iuqbkh6GX4NFWzPtGImxcZ+9P6yoBf9Sk+N5mfUY2zyRtcjbTYZ00jvBQLgwaAh3dTRu0NXpBchn+87p7bEwV6mo4AFiacy2k/nrLdIMiyTPuqE8a1r4="
17
+ gem: breasal
18
+ on:
19
+ tags: true
20
+ repo: theodi/breasal
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ #ruby=ruby-2.1.0
2
+ #ruby-gemset=breasal
3
+
4
+ source 'https://rubygems.org'
5
+
6
+ # Specify your gem's dependencies in breasal.gemspec
7
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 pezholio
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ [![Build Status](http://img.shields.io/travis/theodi/breasal.svg)](https://travis-ci.org/theodi/breasal)
2
+ [![Dependency Status](http://img.shields.io/gemnasium/theodi/breasal.svg)](https://gemnasium.com/theodi/breasal)
3
+ [![Coverage Status](http://img.shields.io/coveralls/theodi/breasal.svg)](https://coveralls.io/r/theodi/breasal)
4
+ [![Code Climate](http://img.shields.io/codeclimate/github/theodi/breasal.svg)](https://codeclimate.com/github/theodi/breasal)
5
+ [![Gem Version](http://img.shields.io/gem/v/breasal.svg)](https://rubygems.org/gems/breasal)
6
+ [![License](http://img.shields.io/:license-mit-blue.svg)](http://theodi.mit-license.org)
7
+ [![Badges](http://img.shields.io/:badges-7/7-ff6799.svg)](https://github.com/pikesley/badger)
8
+
9
+ # Breasal
10
+
11
+ A Ruby gem that converts both British and Irish Eastings and northing to WGS84 latitude and longitude.
12
+
13
+ Based on the work by [Andrew Sprinz at Lambeth Council](https://github.com/LambethCouncil/OSGB36_Converter), and created in anger as part of work on [UK Postcodes](https://github.com/theodi/uk-postcodes)
14
+
15
+ Breasal is the Welsh and Cornish God of all earth, so I thought him suitably Celtic to cover all the British isles.
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ gem 'breasal'
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install breasal
30
+
31
+ ## Usage
32
+
33
+ Provide an easting, northing and coordinate type (either `:gb` or `:ie` - default is `:gb`):
34
+
35
+ en = Breasal::EastingNorthing.new(easting: 412617, northing: 308885, type: :gb)
36
+
37
+ Get the WGS84 latlng:
38
+
39
+ en.to_wgs84 # => {:latitude=>52.67752501534847, :longitude=>-1.8148108086293673}
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
48
+
@@ -0,0 +1,7 @@
1
+ $:.unshift File.join( File.dirname(__FILE__), "lib")
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'breasal/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "breasal"
8
+ spec.version = Breasal::VERSION
9
+ spec.authors = ["Stuart Harrison"]
10
+ spec.email = ["stuart.harrison@theodi.org"]
11
+ spec.description = %q{A Ruby gem that converts both British and Irish Eastings and northing to WGS84 latitude and longitude}
12
+ spec.summary = %q{A Ruby gem that converts both British and Irish Eastings and northing to WGS84 latitude and longitude}
13
+ spec.homepage = "https://github.com/theodi/breasal"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "coveralls"
25
+ spec.add_development_dependency "travis"
26
+ end
@@ -0,0 +1,4 @@
1
+ require "breasal/version"
2
+ require "breasal/utils"
3
+ require "breasal/latlng"
4
+ require "breasal/easting_northing"
@@ -0,0 +1,127 @@
1
+ module Breasal
2
+
3
+ class EastingNorthing
4
+
5
+ include Breasal::Utils
6
+
7
+ def initialize(options)
8
+ @easting = options[:easting]
9
+ @northing = options[:northing]
10
+ @type = options[:type] || :gb
11
+ end
12
+
13
+ # Takes OSGB36 or TM75 (Irish national grid) Easting/Northing coords
14
+ # and returns WGS84 Latitude and Longitude
15
+ def to_wgs84
16
+ ll = to_latlng(@easting, @northing, @type)
17
+ lat_lng = LatLng.new(latitude: ll[:latitude], longitude: ll[:longitude], type: @type)
18
+ lat_lng.to_WGS84
19
+ end
20
+
21
+ # Takes OSGB36 or TM75 (Irish national grid) Easting/Northing coords
22
+ # and returns Latitude and Longitude in either OSGB36 or TM75 format
23
+ def to_latlng(easting, northing, type = :gb)
24
+
25
+ if type == :ie
26
+ @OSGB_F0 = 1.000035
27
+ @N0 = 250000.0
28
+ @E0 = 200000.0
29
+ @phi0 = deg_to_rad(53.5)
30
+ @lambda0 = deg_to_rad(-8.0)
31
+ @a = 6377340.189
32
+ @b = 6356034.447
33
+ else
34
+ @OSGB_F0 = 0.9996012717
35
+ @N0 = -100000.0
36
+ @E0 = 400000.0
37
+ @phi0 = deg_to_rad(49.0)
38
+ @lambda0 = deg_to_rad(-2.0)
39
+ @a = 6377563.396
40
+ @b = 6356256.909
41
+ end
42
+
43
+ @eSquared = ((@a * @a) - (@b * @b)) / (@a * @a)
44
+ @phi = 0.0
45
+ @lambda = 0.0
46
+ @E = easting
47
+ @N = northing
48
+ @n = (@a - @b) / (@a + @b)
49
+ @M = 0.0
50
+ @phiPrime = ((@N - @N0) / (@a * @OSGB_F0)) + @phi0
51
+
52
+ begin
53
+
54
+ @M =
55
+ (@b * @OSGB_F0)\
56
+ * (((1 + @n + ((5.0 / 4.0) * @n * @n) + ((5.0 / 4.0) * @n * @n * @n))\
57
+ * (@phiPrime - @phi0))\
58
+ - (((3 * @n) + (3 * @n * @n) + ((21.0 / 8.0) * @n * @n * @n))\
59
+ * Math.sin(@phiPrime - @phi0)\
60
+ * Math.cos(@phiPrime + @phi0))\
61
+ + ((((15.0 / 8.0) * @n * @n) + ((15.0 / 8.0) * @n * @n * @n))\
62
+ * Math.sin(2.0 * (@phiPrime - @phi0))\
63
+ * Math.cos(2.0 * (@phiPrime + @phi0)))\
64
+ - (((35.0 / 24.0) * @n * @n * @n)\
65
+ * Math.sin(3.0 * (@phiPrime - @phi0))\
66
+ * Math.cos(3.0 * (@phiPrime + @phi0))))
67
+
68
+ @phiPrime += (@N - @N0 - @M) / (@a * @OSGB_F0)
69
+
70
+ end while ((@N - @N0 - @M) >= 0.001)
71
+
72
+ @v = @a * @OSGB_F0 * ((1.0 - @eSquared * sin_pow_2(@phiPrime)) ** -0.5)
73
+ @rho =
74
+ @a\
75
+ * @OSGB_F0\
76
+ * (1.0 - @eSquared)\
77
+ * ((1.0 - @eSquared * sin_pow_2(@phiPrime)) ** -1.5)
78
+ @etaSquared = (@v / @rho) - 1.0
79
+ @VII = Math.tan(@phiPrime) / (2 * @rho * @v)
80
+ @VIII =
81
+ (Math.tan(@phiPrime) / (24.0 * @rho * (@v ** 3.0)))\
82
+ * (5.0\
83
+ + (3.0 * tan_pow_2(@phiPrime))\
84
+ + @etaSquared\
85
+ - (9.0 * tan_pow_2(@phiPrime) * @etaSquared))
86
+ @IX =
87
+ (Math.tan(@phiPrime) / (720.0 * @rho * (@v ** 5.0)))\
88
+ * (61.0\
89
+ + (90.0 * tan_pow_2(@phiPrime))\
90
+ + (45.0 * tan_pow_2(@phiPrime) * tan_pow_2(@phiPrime)))
91
+ @X = sec(@phiPrime) / @v
92
+ @XI =
93
+ (sec(@phiPrime) / (6.0 * @v * @v * @v))\
94
+ * ((@v / @rho) + (2 * tan_pow_2(@phiPrime)))
95
+ @XII =
96
+ (sec(@phiPrime) / (120.0 * (@v ** 5.0)))\
97
+ * (5.0\
98
+ + (28.0 * tan_pow_2(@phiPrime))\
99
+ + (24.0 * tan_pow_2(@phiPrime) * tan_pow_2(@phiPrime)))
100
+ @XIIA =
101
+ (sec(@phiPrime) / (5040.0 * (@v ** 7.0)))\
102
+ * (61.0\
103
+ + (662.0 * tan_pow_2(@phiPrime))\
104
+ + (1320.0 * tan_pow_2(@phiPrime) * tan_pow_2(@phiPrime))\
105
+ + (720.0\
106
+ * tan_pow_2(@phiPrime)\
107
+ * tan_pow_2(@phiPrime)\
108
+ * tan_pow_2(@phiPrime)))
109
+ @phi =
110
+ @phiPrime\
111
+ - (@VII * ((@E - @E0) ** 2.0))\
112
+ + (@VIII * ((@E - @E0) ** 4.0))\
113
+ - (@IX * ((@E - @E0) ** 6.0))
114
+ @lambda =
115
+ @lambda0\
116
+ + (@X * (@E - @E0))\
117
+ - (@XI * ((@E - @E0) ** 3.0))\
118
+ + (@XII * ((@E - @E0) ** 5.0))\
119
+ - (@XIIA * ((@E - @E0) ** 7.0))
120
+
121
+ { :latitude => rad_to_deg(@phi), :longitude => rad_to_deg(@lambda) }
122
+
123
+ end
124
+
125
+ end
126
+
127
+ end
@@ -0,0 +1,69 @@
1
+ module Breasal
2
+
3
+ class LatLng
4
+
5
+ include Breasal::Utils
6
+
7
+ def initialize(options)
8
+ @latitude = options[:latitude]
9
+ @longitude = options[:longitude]
10
+ @type = options[:type] || :gb
11
+ end
12
+
13
+ # Takes OSGB36 or TM75 Latitude and Longitude coords
14
+ # and returns WGS84 Latitude and Longitude
15
+ def to_WGS84
16
+
17
+ if @type == :ie
18
+ @a = 6377340.189
19
+ @b = 6356034.447
20
+ else
21
+ @a = 6377563.396
22
+ @b = 6356256.909
23
+ end
24
+
25
+ @eSquared = ((@a * @a) - (@b * @b)) / (@a * @a)
26
+
27
+ @phi = deg_to_rad(@latitude)
28
+ @lambda = deg_to_rad(@longitude)
29
+ @v = @a / (Math.sqrt(1 - @eSquared * sin_pow_2(@phi)))
30
+ @H = 0
31
+ @x = (@v + @H) * Math.cos(@phi) * Math.cos(@lambda)
32
+ @y = (@v + @H) * Math.cos(@phi) * Math.sin(@lambda)
33
+ @z = ((1 - @eSquared) * @v + @H) * Math.sin(@phi)
34
+
35
+ @tx = 446.448
36
+ @ty = -124.157
37
+ @tz = 542.060
38
+
39
+ @s = -0.0000204894
40
+ @rx = deg_to_rad( 0.00004172222)
41
+ @ry = deg_to_rad( 0.00006861111)
42
+ @rz = deg_to_rad( 0.00023391666)
43
+
44
+ @xB = @tx + (@x * (1 + @s)) + (-@rx * @y) + (@ry * @z)
45
+ @yB = @ty + (@rz * @x) + (@y * (1 + @s)) + (-@rx * @z)
46
+ @zB = @tz + (-@ry * @x) + (@rx * @y) + (@z * (1 + @s))
47
+
48
+ @a = 6378137.000
49
+ @b = 6356752.3141
50
+ @eSquared = ((@a * @a) - (@b * @b)) / (@a * @a)
51
+
52
+ @lambdaB = rad_to_deg(Math.atan(@yB / @xB))
53
+ @p = Math.sqrt((@xB * @xB) + (@yB * @yB))
54
+ @phiN = Math.atan(@zB / (@p * (1 - @eSquared)))
55
+
56
+ (1..10).each do |i|
57
+ @v = @a / (Math.sqrt(1 - @eSquared * sin_pow_2(@phiN)))
58
+ @phiN1 = Math.atan((@zB + (@eSquared * @v * Math.sin(@phiN))) / @p)
59
+ @phiN = @phiN1
60
+ end
61
+
62
+ @phiB = rad_to_deg(@phiN)
63
+
64
+ { :latitude => @phiB, :longitude => @lambdaB }
65
+
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,31 @@
1
+ module Breasal
2
+
3
+ module Utils
4
+
5
+ def deg_to_rad(degrees)
6
+ degrees / 180.0 * Math::PI
7
+ end
8
+
9
+ def rad_to_deg(r)
10
+ (r/Math::PI)*180
11
+ end
12
+
13
+ def sin_pow_2(x)
14
+ Math.sin(x) * Math.sin(x)
15
+ end
16
+
17
+ def cos_pow_2(x)
18
+ Math.cos(x) * Math.cos(x)
19
+ end
20
+
21
+ def tan_pow_2(x)
22
+ Math.tan(x) * Math.tan(x)
23
+ end
24
+
25
+ def sec(x)
26
+ 1.0 / Math.cos(x)
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,3 @@
1
+ module Breasal
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Breasal::EastingNorthing do
4
+
5
+ context "When provided with a GB Easting and Northing" do
6
+
7
+ it "returns the correct WGS84 latitude and longitude" do
8
+ en = Breasal::EastingNorthing.new(easting: 412617, northing: 308885)
9
+
10
+ ll = en.to_wgs84
11
+
12
+ ll[:latitude].should == 52.67752501534847
13
+ ll[:longitude].should == -1.8148108086293673
14
+ end
15
+
16
+ end
17
+
18
+ context "When provided with an Irish Easting and Northing" do
19
+
20
+ it "returns the correct WGS84 latitude and longitude" do
21
+ en = Breasal::EastingNorthing.new(easting: 333832, northing: 374014, type: :ie)
22
+
23
+ ll = en.to_wgs84
24
+
25
+ ll[:latitude].should == 54.596642596875334
26
+ ll[:longitude].should == -5.930070032491946
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,10 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'breasal'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ config.order = "random"
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: breasal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stuart Harrison
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: travis
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A Ruby gem that converts both British and Irish Eastings and northing
84
+ to WGS84 latitude and longitude
85
+ email:
86
+ - stuart.harrison@theodi.org
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - breasal.gemspec
98
+ - lib/breasal.rb
99
+ - lib/breasal/easting_northing.rb
100
+ - lib/breasal/latlng.rb
101
+ - lib/breasal/utils.rb
102
+ - lib/breasal/version.rb
103
+ - spec/easting_northing_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: https://github.com/theodi/breasal
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A Ruby gem that converts both British and Irish Eastings and northing to
129
+ WGS84 latitude and longitude
130
+ test_files:
131
+ - spec/easting_northing_spec.rb
132
+ - spec/spec_helper.rb