coordinate-converter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/lib/coordinate-converter.rb +88 -0
- data/spec/conversion_spec.rb +19 -0
- metadata +71 -0
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
Converting UTM to Latitude and Longitude
|
2
|
+
========================================
|
3
|
+
|
4
|
+
Parameters are specified in the following order:
|
5
|
+
|
6
|
+
* reference_ellipsoid
|
7
|
+
* northing
|
8
|
+
* easting
|
9
|
+
* zone
|
10
|
+
|
11
|
+
Example
|
12
|
+
-------
|
13
|
+
|
14
|
+
Coordinates.utm_to_lat_long("WGS-84", 6688940, 219165, "33N")
|
15
|
+
# => {:lat => 60.2399303597183, :long => 9.92496237547609}
|
16
|
+
|
17
|
+
Supported ellipsoids
|
18
|
+
--------------------
|
19
|
+
|
20
|
+
* Airy
|
21
|
+
* Australian National
|
22
|
+
* Bessel 1841
|
23
|
+
* Bessel 1841 (Nambia)
|
24
|
+
* Clarke 1866
|
25
|
+
* Clarke 1880
|
26
|
+
* Everest
|
27
|
+
* Fischer 1960 (Mercury)
|
28
|
+
* Fischer 1968
|
29
|
+
* GRS 1967
|
30
|
+
* GRS 1980
|
31
|
+
* Helmert 1906
|
32
|
+
* Hough
|
33
|
+
* International
|
34
|
+
* Krassovsky
|
35
|
+
* Modified Airy
|
36
|
+
* Modified Everest
|
37
|
+
* Modified Fischer 1960
|
38
|
+
* South American 1969
|
39
|
+
* WGS 60
|
40
|
+
* WGS 66
|
41
|
+
* WGS-72
|
42
|
+
* WGS-84
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "coordinate-converter"
|
5
|
+
gemspec.summary = "Converting UTM to Latitude and Longitude"
|
6
|
+
gemspec.description = "Converting UTM to Latitude and Longitude"
|
7
|
+
gemspec.email = "mail@kimjoar.net"
|
8
|
+
gemspec.homepage = "http://github.com/kjbekkelund/coordinate-converter"
|
9
|
+
gemspec.authors = "Kim Joar Bekkelund"
|
10
|
+
end
|
11
|
+
Jeweler::GemcutterTasks.new
|
12
|
+
rescue LoadError
|
13
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
14
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Coordinates
|
2
|
+
def self.utm_to_lat_long(reference_ellipsoid, northing, easting, zone)
|
3
|
+
a = equitorial_radius(reference_ellipsoid)
|
4
|
+
ecc_squared = eccentricity_squared(reference_ellipsoid)
|
5
|
+
|
6
|
+
e1 = (1 - Math.sqrt(1 - ecc_squared)) / (1 + Math.sqrt(1 - ecc_squared))
|
7
|
+
|
8
|
+
x = easting - 500000.0
|
9
|
+
y = northing
|
10
|
+
|
11
|
+
zone_letter = zone[-1].chr
|
12
|
+
zone_number = zone[0..-2].to_i
|
13
|
+
if zone_letter >= 'S'
|
14
|
+
y -= 10000000.0
|
15
|
+
end
|
16
|
+
|
17
|
+
long_origin = (zone_number - 1) * 6 - 180 + 3
|
18
|
+
ecc_prime_squared = (ecc_squared) / (1 - ecc_squared)
|
19
|
+
|
20
|
+
k0 = 0.9996
|
21
|
+
m = y / k0
|
22
|
+
mu = m / (a * (1 - ecc_squared / 4 - 3 * ecc_squared * ecc_squared / 64 - 5 \
|
23
|
+
* ecc_squared * ecc_squared * ecc_squared / 256))
|
24
|
+
|
25
|
+
phi1_rad = (mu + (3 * e1 / 2 - 27 * e1 * e1 * e1 / 32) * Math.sin(2 * mu) \
|
26
|
+
+ (21 * e1 * e1 / 16 - 55 * e1 * e1 * e1 * e1 / 32) \
|
27
|
+
* Math.sin(4 * mu) + (151 * e1 * e1 * e1 / 96) \
|
28
|
+
* Math.sin(6 * mu))
|
29
|
+
|
30
|
+
n1 = a / Math.sqrt(1 - ecc_squared * Math.sin(phi1_rad) * Math.sin(phi1_rad))
|
31
|
+
t1 = Math.tan(phi1_rad) * Math.tan(phi1_rad)
|
32
|
+
c1 = ecc_prime_squared * Math.cos(phi1_rad) * Math.cos(phi1_rad)
|
33
|
+
r1 = a * (1 - ecc_squared) / (1 - ecc_squared * Math.sin(phi1_rad) * Math.sin(phi1_rad))**1.5
|
34
|
+
d = x / (n1 * k0)
|
35
|
+
|
36
|
+
lat = phi1_rad - (n1 * Math.tan(phi1_rad) / r1) * (d * d / 2 - (5 + 3 * t1 \
|
37
|
+
+ 10 * c1 - 4 * c1**2 - 9 * ecc_prime_squared) * d**4 / 24 + (61 + 90 \
|
38
|
+
* t1 + 298 * c1 + 45 * t1**2 - 252 * ecc_prime_squared - 3 * c1**2) \
|
39
|
+
* d**6 / 720)
|
40
|
+
lat = lat * RAD_TO_DEG
|
41
|
+
|
42
|
+
long = (d - (1 + 2 * t1 + c1) * d * d * d / 6 + (5 - 2 * c1 + 28 \
|
43
|
+
* t1 - 3 * c1 * c1 + 8 * ecc_prime_squared + 24 * t1 * t1) \
|
44
|
+
* d * d * d * d * d / 120) / Math.cos(phi1_rad)
|
45
|
+
|
46
|
+
long = long_origin + long * RAD_TO_DEG
|
47
|
+
|
48
|
+
{ :lat => lat, :long => long }
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def self.equitorial_radius(ellipsoid)
|
54
|
+
ELLIPSOID[ellipsoid].first
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.eccentricity_squared(ellipsoid)
|
58
|
+
ELLIPSOID[ellipsoid].last
|
59
|
+
end
|
60
|
+
|
61
|
+
ELLIPSOID = {
|
62
|
+
"Airy" => [6377563, 0.00667054],
|
63
|
+
"Australian National" => [6378160, 0.006694542],
|
64
|
+
"Bessel 1841" => [6377397, 0.006674372],
|
65
|
+
"Bessel 1841 (Nambia)" => [6377484, 0.006674372],
|
66
|
+
"Clarke 1866" => [6378206, 0.006768658],
|
67
|
+
"Clarke 1880" => [6378249, 0.006803511],
|
68
|
+
"Everest" => [6377276, 0.006637847],
|
69
|
+
"Fischer 1960 (Mercury)" => [6378166, 0.006693422],
|
70
|
+
"Fischer 1968" => [6378150, 0.006693422],
|
71
|
+
"GRS 1967" => [6378160, 0.006694605],
|
72
|
+
"GRS 1980" => [6378137, 0.00669438],
|
73
|
+
"Helmert 1906" => [6378200, 0.006693422],
|
74
|
+
"Hough" => [6378270, 0.00672267],
|
75
|
+
"International" => [6378388, 0.00672267],
|
76
|
+
"Krassovsky" => [6378245, 0.006693422],
|
77
|
+
"Modified Airy" => [6377340, 0.00667054],
|
78
|
+
"Modified Everest" => [6377304, 0.006637847],
|
79
|
+
"Modified Fischer 1960" => [6378155, 0.006693422],
|
80
|
+
"South American 1969" => [6378160, 0.006694542],
|
81
|
+
"WGS 60" => [6378165, 0.006693422],
|
82
|
+
"WGS 66" => [6378145, 0.006694542],
|
83
|
+
"WGS-72" => [6378135, 0.006694318],
|
84
|
+
"WGS-84" => [6378137, 0.00669438]
|
85
|
+
}
|
86
|
+
|
87
|
+
RAD_TO_DEG = 180.0 / Math::PI
|
88
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'coordinates')
|
2
|
+
|
3
|
+
describe Coordinates do
|
4
|
+
describe "#utm_to_lat_long" do
|
5
|
+
it "should return a hash with keys lat and long" do
|
6
|
+
ll = Coordinates.utm_to_lat_long("WGS-84", 6688940, 219165, "33N")
|
7
|
+
ll.should be_an Hash
|
8
|
+
ll.has_key?(:lat).should be_true
|
9
|
+
ll.has_key?(:long).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return a correct lat long for the reference ellipsoid WGS-84 in the zone 33N" do
|
13
|
+
coords = Coordinates.utm_to_lat_long("WGS-84", 6688940, 219165, "33N")
|
14
|
+
|
15
|
+
coords[:lat].should be_close(60.2399303597183, 0.00000005)
|
16
|
+
coords[:long].should be_close(9.92496237547609, 0.00000005)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coordinate-converter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kim Joar Bekkelund
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-10 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Converting UTM to Latitude and Longitude
|
23
|
+
email: mail@kimjoar.net
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.md
|
30
|
+
files:
|
31
|
+
- README.md
|
32
|
+
- Rakefile
|
33
|
+
- VERSION
|
34
|
+
- lib/coordinate-converter.rb
|
35
|
+
- spec/conversion_spec.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/kjbekkelund/coordinate-converter
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options:
|
42
|
+
- --charset=UTF-8
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.7
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Converting UTM to Latitude and Longitude
|
70
|
+
test_files:
|
71
|
+
- spec/conversion_spec.rb
|