geo_swap 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/geo_swap.gemspec +1 -0
- data/lib/geo_swap/utm_point.rb +18 -0
- data/lib/geo_swap/version.rb +1 -1
- data/lib/geo_swap/zone.rb +29 -1
- data/lib/geo_swap.rb +27 -2
- data/spec/geo_swap_spec.rb +3 -2
- metadata +21 -4
data/geo_swap.gemspec
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module GeoSwap
|
2
|
+
class UtmPoint
|
3
|
+
|
4
|
+
attr_reader :zone, :easting, :northing, :hemisphere
|
5
|
+
|
6
|
+
def initialize(attrs)
|
7
|
+
@easting = attrs.fetch(:easting)
|
8
|
+
@northing = attrs.fetch(:northing)
|
9
|
+
@zone = attrs.fetch(:zone)
|
10
|
+
@hemisphere = attrs.fetch(:hemisphere)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#{zone.number}#{zone.letter} #{easting}mE #{northing}mN"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/geo_swap/version.rb
CHANGED
data/lib/geo_swap/zone.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module GeoSwap
|
2
2
|
class Zone
|
3
|
-
def initialize(longitude)
|
3
|
+
def initialize(latitude, longitude)
|
4
|
+
@latitude = latitude
|
4
5
|
@longitude = longitude.to_f
|
5
6
|
end
|
6
7
|
|
@@ -15,5 +16,32 @@ module GeoSwap
|
|
15
16
|
def origin
|
16
17
|
@origin ||= ((number - 1) * 6) - 177
|
17
18
|
end
|
19
|
+
|
20
|
+
def letter
|
21
|
+
case @latitude
|
22
|
+
when 72..84 then 'X'
|
23
|
+
when 64...72 then 'W'
|
24
|
+
when 56...64 then 'V'
|
25
|
+
when 48...56 then 'U'
|
26
|
+
when 40...48 then 'T'
|
27
|
+
when 32...40 then 'S'
|
28
|
+
when 24...32 then 'R'
|
29
|
+
when 16...24 then 'Q'
|
30
|
+
when 8...16 then 'P'
|
31
|
+
when 0...8 then 'N'
|
32
|
+
when -8...0 then 'M'
|
33
|
+
when -16...-8 then 'L'
|
34
|
+
when -24...-16 then 'K'
|
35
|
+
when -32...-24 then 'J'
|
36
|
+
when -40...-32 then 'H'
|
37
|
+
when -48...-40 then 'G'
|
38
|
+
when -56...-48 then 'F'
|
39
|
+
when -64...-56 then 'E'
|
40
|
+
when -72...-64 then 'D'
|
41
|
+
when -80...-72 then 'C'
|
42
|
+
else
|
43
|
+
'Z'
|
44
|
+
end
|
45
|
+
end
|
18
46
|
end
|
19
47
|
end
|
data/lib/geo_swap.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'pry'
|
1
2
|
require "geo_swap/version"
|
2
3
|
require 'geo_swap/zone'
|
3
4
|
require 'geo_swap/utilities'
|
5
|
+
require 'geo_swap/utm_point'
|
4
6
|
|
5
7
|
module GeoSwap
|
6
8
|
extend Utilities
|
@@ -10,10 +12,10 @@ module GeoSwap
|
|
10
12
|
lat_radians = degrees_to_radians(lat)
|
11
13
|
long_radians = degrees_to_radians(long)
|
12
14
|
|
13
|
-
zone = Zone.new(long)
|
15
|
+
zone = Zone.new(lat, long)
|
14
16
|
origin_radians = degrees_to_radians(zone.origin)
|
15
17
|
|
16
|
-
equator_factor = (EQUATORIAL_RADIUS / Math.sqrt(1 - (ECC_SQUARED * (Math.sin(lat_radians) ** 2)))
|
18
|
+
equator_factor = (EQUATORIAL_RADIUS / Math.sqrt(1 - (ECC_SQUARED * (Math.sin(lat_radians) ** 2))))
|
17
19
|
squared_lat_tangent = Math.tan(lat_radians) ** 2
|
18
20
|
ecc_prime_factor = ECC_PRIME_SQUARED * (Math.cos(lat_radians) ** 2)
|
19
21
|
origin_factor = Math.cos(lat_radians) * (long_radians - origin_radians)
|
@@ -36,6 +38,25 @@ module GeoSwap
|
|
36
38
|
ecc_4 * latRad_4
|
37
39
|
)
|
38
40
|
|
41
|
+
utm_easting = (MERIDIAN_SCALE * equator_factor *
|
42
|
+
(origin_factor + (1 - squared_lat_tangent + ecc_prime_factor) *
|
43
|
+
(origin_factor ** 3) / 6 +
|
44
|
+
(5 - 18 * squared_lat_tangent + (squared_lat_tangent ** 2) + 72 * ecc_prime_factor - 58 * ECC_PRIME_SQUARED) *
|
45
|
+
(origin_factor ** 5) / 120) + EASTING_OFFSET)
|
46
|
+
|
47
|
+
utm_northing = (
|
48
|
+
MERIDIAN_SCALE * ( northing_factor + equator_factor * Math.tan(lat_radians) * (origin_factor ** 2) / 2 + (5 - squared_lat_tangent + 9 * ecc_prime_factor + 4 * (ecc_prime_factor ** 2)) * (origin_factor ** 4) / 2 +
|
49
|
+
(61 - 58 * squared_lat_tangent + (squared_lat_tangent ** 2) + 600 * ecc_prime_factor - 330 * ECC_PRIME_SQUARED) *
|
50
|
+
(origin_factor ** 6) / 720))
|
51
|
+
|
52
|
+
utm_northing += 10000000 if utm_northing < 0
|
53
|
+
|
54
|
+
UtmPoint.new(
|
55
|
+
easting: utm_easting.round,
|
56
|
+
northing: utm_northing.round,
|
57
|
+
zone: zone,
|
58
|
+
hemisphere: (lat < 0 ? 'S' : 'N')
|
59
|
+
)
|
39
60
|
end
|
40
61
|
|
41
62
|
module_function :lat_long_to_utm
|
@@ -53,6 +74,10 @@ module GeoSwap
|
|
53
74
|
EQUATORIAL_RADIUS = 6378137.0
|
54
75
|
ECC_SQUARED = 0.006694380023
|
55
76
|
ECC_PRIME_SQUARED = ECC_SQUARED / (1 - ECC_SQUARED)
|
77
|
+
MERIDIAN_SCALE = 0.9996
|
78
|
+
|
79
|
+
EASTING_OFFSET = 500000.0
|
80
|
+
NORTHING_OFFSET = 10000000.0
|
56
81
|
|
57
82
|
def self.validate_range(lat, long)
|
58
83
|
unless lat.between?(MIN_LATITUDE, MAX_LATITUDE) && long.between?(MIN_LONGITUDE, MAX_LONGITUDE)
|
data/spec/geo_swap_spec.rb
CHANGED
@@ -12,7 +12,7 @@ module GeoSwap
|
|
12
12
|
{
|
13
13
|
lat: 41.8901694,
|
14
14
|
long: 12.4922694,
|
15
|
-
utm: "33T 291952mE
|
15
|
+
utm: "33T 291952mE 4640622mN",
|
16
16
|
}
|
17
17
|
]
|
18
18
|
|
@@ -40,7 +40,8 @@ module GeoSwap
|
|
40
40
|
|
41
41
|
it 'correctly converts several reference points' do
|
42
42
|
DATA.each do |data|
|
43
|
-
GeoSwap.lat_long_to_utm(data[:lat], data[:long]).
|
43
|
+
GeoSwap.lat_long_to_utm(data[:lat], data[:long]).to_s.
|
44
|
+
should == data[:utm]
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geo_swap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 2.12.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pry
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.11.4
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.11.4
|
46
62
|
description: Simple utility functions for converting between coordinate systems (Lat/Long,
|
47
63
|
UTM, USNG)
|
48
64
|
email:
|
@@ -60,6 +76,7 @@ files:
|
|
60
76
|
- geo_swap.gemspec
|
61
77
|
- lib/geo_swap.rb
|
62
78
|
- lib/geo_swap/utilities.rb
|
79
|
+
- lib/geo_swap/utm_point.rb
|
63
80
|
- lib/geo_swap/version.rb
|
64
81
|
- lib/geo_swap/zone.rb
|
65
82
|
- spec/geo_swap/utilities_spec.rb
|
@@ -79,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
96
|
version: '0'
|
80
97
|
segments:
|
81
98
|
- 0
|
82
|
-
hash:
|
99
|
+
hash: 3526420961644426813
|
83
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
101
|
none: false
|
85
102
|
requirements:
|
@@ -88,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
105
|
version: '0'
|
89
106
|
segments:
|
90
107
|
- 0
|
91
|
-
hash:
|
108
|
+
hash: 3526420961644426813
|
92
109
|
requirements: []
|
93
110
|
rubyforge_project:
|
94
111
|
rubygems_version: 1.8.23
|