blue_geo 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +5 -0
- data/Rakefile +8 -0
- data/blue_geo.gemspec +24 -0
- data/lib/blue_geo.rb +8 -0
- data/lib/blue_geo/easting_northing_to_latitude_longitude_converter.rb +70 -0
- data/lib/blue_geo/version.rb +3 -0
- data/test/blue_geo_convertion_test.rb +25 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
data/blue_geo.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "blue_geo/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "blue_geo"
|
7
|
+
s.version = BlueGeo::VERSION
|
8
|
+
s.authors = ["Arti Sinani"]
|
9
|
+
s.email = ["artisinani@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Converts easting and northing into latitude and longitude}
|
12
|
+
s.description = %q{Converts easting and northing into latitude and longitude}
|
13
|
+
|
14
|
+
s.rubyforge_project = "blue_geo"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
data/lib/blue_geo.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require_relative "blue_geo/version"
|
2
|
+
require_relative "blue_geo/easting_northing_to_latitude_longitude_converter"
|
3
|
+
|
4
|
+
module BlueGeo
|
5
|
+
def self.easting_northing_to_lat_lon(easting, northing)
|
6
|
+
EastingNorthingToLatitudeLongitudeConverter.new.convert(easting, northing)
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module BlueGeo
|
2
|
+
class EastingNorthingToLatitudeLongitudeConverter
|
3
|
+
DEG2RAD = Math::PI / 180.0
|
4
|
+
RAD2DEG = 180.0 / Math::PI
|
5
|
+
WGS_AXIS = 6378137
|
6
|
+
LAT_ORIG = 49 * DEG2RAD
|
7
|
+
LON_ORIG = -2 * DEG2RAD
|
8
|
+
SCALE = 0.9996012717
|
9
|
+
FALSE_EASTING = 400000
|
10
|
+
FALSE_NORTHING = -100000
|
11
|
+
AXIS = 6377563.396
|
12
|
+
WGS_ECCENT = 0.00669438
|
13
|
+
ECCENT = 0.00667054
|
14
|
+
|
15
|
+
|
16
|
+
def convert(easting, northing)
|
17
|
+
p = ECCENT / 8
|
18
|
+
a = AXIS * (1 - (2 * p) - (3 * p ** 2) - (10 * p ** 3))
|
19
|
+
b = AXIS * ((6 * p) + (12 * p ** 2) + (45 * p ** 3 )) / 2
|
20
|
+
c = AXIS * ((15 * p ** 2) + (90 * p ** 3)) / 4
|
21
|
+
mo = a * LAT_ORIG - b * Math.sin(2 * LAT_ORIG) + c * Math.sin(4 * LAT_ORIG)
|
22
|
+
mp = mo + ((northing - FALSE_NORTHING) / SCALE)
|
23
|
+
phidash = mp / a
|
24
|
+
phif = phidash + ((b * Math.sin(2 * phidash)) - (c * Math.sin(4 * phidash))) / (a - (2 * b * Math.cos(2 * phidash)))
|
25
|
+
|
26
|
+
uf = AXIS / Math.sqrt(1 - (ECCENT * (Math.sin(phif) * Math.sin(phif))))
|
27
|
+
h = (easting - FALSE_EASTING) / (SCALE * uf)
|
28
|
+
|
29
|
+
nsqd = ECCENT * (Math.cos(phif) * Math.cos(phif)) / (1 - ECCENT)
|
30
|
+
tsqd = Math.sin(phif) / Math.cos(phif) ** 2
|
31
|
+
|
32
|
+
lambdap = LON_ORIG + (1 / Math.cos(phif)) * ((h - ((h * h * h) / 6) * (1 + (2 * tsqd) + nsqd)))
|
33
|
+
phip = phif - ((1 + nsqd) * (Math.sin(phif) / Math.cos(phif)) * (((h * h) / 2) - ((h * h * h * h) / 24) * (5 + 3 * tsqd)))
|
34
|
+
|
35
|
+
x, y, z = lat_lon_to_cartesian(phip, lambdap, AXIS, ECCENT, 0)
|
36
|
+
|
37
|
+
lat, lon = cartesian_to_lat_lon(x, y, z, ECCENT, WGS_AXIS)
|
38
|
+
|
39
|
+
[lat * RAD2DEG, lon * RAD2DEG]
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def lat_lon_to_cartesian(lat, lon, a, eccentsq, h)
|
44
|
+
v = a / (Math.sqrt(1 - eccentsq * (Math.sin(lat) ** 2)))
|
45
|
+
x = (v + h) * Math.cos(lat) * Math.cos(lon)
|
46
|
+
y = (v + h) * Math.cos(lat) * Math.sin(lon)
|
47
|
+
z = ((1 - eccentsq) * v + h) * Math.sin(lat)
|
48
|
+
[x, y, z]
|
49
|
+
end
|
50
|
+
|
51
|
+
def cartesian_to_lat_lon(x, y, z, eccentsq, a)
|
52
|
+
lon = Math.atan(y / x)
|
53
|
+
p = Math.sqrt((x * x) + (y * y))
|
54
|
+
lat = Math.atan(z / (p * (1 - eccentsq)))
|
55
|
+
v = a / (Math.sqrt(1 - eccentsq * (Math.sin(lat) * Math.sin(lat))))
|
56
|
+
errvalue = 1.0
|
57
|
+
lat = 0
|
58
|
+
lat0 = 0
|
59
|
+
|
60
|
+
while errvalue > 0.001
|
61
|
+
lat0 = Math.atan((z + eccentsq * v * Math.sin(lat)) / p)
|
62
|
+
errvalue = (lat0 - lat).abs;
|
63
|
+
lat = lat0;
|
64
|
+
end
|
65
|
+
|
66
|
+
[lat, lon]
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require File.expand_path("../../lib/blue_geo", __FILE__)
|
3
|
+
|
4
|
+
module BlueGeo
|
5
|
+
class ConvertionTest < MiniTest::Unit::TestCase
|
6
|
+
# 536861, 176584 -> 51.471150 -0.029269 (easting_north -> lat, lon)
|
7
|
+
# 51.47168 -0.03088506 536861 176584
|
8
|
+
# 53.75771 -2.704654 353639 429270
|
9
|
+
# 51.66625 -3.92504 266963 198141
|
10
|
+
# 52.39906 0.2658032 554253 280309
|
11
|
+
# 51.48031 0.1799298 551473 177959
|
12
|
+
# 53.3513 -3.003981 333267 384294
|
13
|
+
# 53.52229 -2.488291 367724 402958
|
14
|
+
# 55.1022 -4.76847 223472 582144
|
15
|
+
# 52.60267 1.733953 652939 307091
|
16
|
+
# 51.88307 -0.5158798 502248 221541
|
17
|
+
# 51.43271 -0.1848878 526273 171974
|
18
|
+
|
19
|
+
def test_converts_correctly
|
20
|
+
latitude, longitude = BlueGeo.easting_northing_to_lat_lon(536861, 176584)
|
21
|
+
assert_equal 51.471176444600296, latitude, 'latitude'
|
22
|
+
assert_equal -0.02940177028571391, longitude, 'longitude'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blue_geo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Arti Sinani
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-17 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Converts easting and northing into latitude and longitude
|
15
|
+
email:
|
16
|
+
- artisinani@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- blue_geo.gemspec
|
26
|
+
- lib/blue_geo.rb
|
27
|
+
- lib/blue_geo/easting_northing_to_latitude_longitude_converter.rb
|
28
|
+
- lib/blue_geo/version.rb
|
29
|
+
- test/blue_geo_convertion_test.rb
|
30
|
+
homepage: ''
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project: blue_geo
|
50
|
+
rubygems_version: 1.8.17
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Converts easting and northing into latitude and longitude
|
54
|
+
test_files:
|
55
|
+
- test/blue_geo_convertion_test.rb
|