nztm2000 1.0.0 → 1.1.0
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.
- checksums.yaml +4 -4
- data/README.md +21 -3
- data/lib/nztm2000.rb +33 -14
- data/test/test_nztm2000.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f8935ed2a880bfc5e71444a44b18f41d706f24a
|
4
|
+
data.tar.gz: b5a00e1f1913e8ff0b28c5a5700055bd376db1c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a59f8c5c2aafac21a30be88cb1c5874667ba00180909b2cbf885457f59afb321b7efb16069c5ede5d53461e096064887d4a8306bb5d8c10520adedecb8e63404
|
7
|
+
data.tar.gz: 2a01610ddb54e7e3829bcb4b34e6bba05989b6a19cc2fbef54fc2a82bc90e2059e70706811ee837c2b40057cb35529cad5f5a5e4cf21f352d48d20a06afd521d
|
data/README.md
CHANGED
@@ -17,19 +17,37 @@ Converts coordinates between the New Zealand Transverse Merctator 2000 and GRS8
|
|
17
17
|
|
18
18
|
The NZTM200 provides two public methods
|
19
19
|
|
20
|
-
|
20
|
+
geod( easting, northing )
|
21
21
|
Converts easting and northing (meters) to a latitude and longitude (Decimal degrees and radian results available)
|
22
22
|
|
23
|
-
|
23
|
+
nztm( latitude, longitude )
|
24
24
|
Converts latitude and longitude (Decimal degrees) to easting and northing (meters)
|
25
25
|
|
26
|
+
```
|
27
|
+
require 'nztm2000'
|
28
|
+
#Self test from nztm.c.
|
29
|
+
nztm2000 = NZTM2000.new
|
30
|
+
[[1576041.150, 6188574.240],
|
31
|
+
[1576542.010, 5515331.050],
|
32
|
+
[1307103.220, 4826464.860]].each do |easting,northing|
|
33
|
+
r_latitude, r_longitude = nztm2000.geod(easting, northing)
|
34
|
+
r_easting, r_northing = nztm2000.nztm(r_latitude, r_longitude)
|
35
|
+
|
36
|
+
printf "Input NZTM easting, northing: %12.3f %12.3f\n", easting, northing
|
37
|
+
printf "Output Latitude Longitude: %12.6f %12.6f\n", r_latitude, r_longitude
|
38
|
+
printf "Output NZTM easting, northing: %12.3f %12.3f\n", r_easting, r_northing
|
39
|
+
printf "Difference: %12.3f %12.3f\n", easting - r_easting, northing - r_northing
|
40
|
+
puts
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
26
44
|
## REQUIREMENTS:
|
27
45
|
|
28
46
|
*
|
29
47
|
|
30
48
|
## INSTALL:
|
31
49
|
|
32
|
-
* sudo gem install
|
50
|
+
* sudo gem install nztm2000
|
33
51
|
|
34
52
|
## LICENSE:
|
35
53
|
|
data/lib/nztm2000.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class NZTM2000
|
2
|
-
VERSION = '1.
|
2
|
+
VERSION = '1.1.0'
|
3
3
|
|
4
4
|
#Define the parameters for the International Ellipsoid
|
5
5
|
#used for the NZGD2000 datum (and hence for NZTM)
|
@@ -28,8 +28,21 @@ class NZTM2000
|
|
28
28
|
attr_accessor :northing #NZTM 2000 northing (meters)
|
29
29
|
attr_accessor :easting #NZTM 2000 easting (meters)
|
30
30
|
|
31
|
-
|
31
|
+
#Initialize
|
32
|
+
# Without arguments, use geod or nztm methods.
|
33
|
+
# Given easting: and northing:, @latitude and @longitude will be calculated
|
34
|
+
# Given latitude: and longitude:, @easting: and @northing will be calculated
|
35
|
+
# @option easting: [Numeric] nztm2000 easting
|
36
|
+
# @option northing: [Numeric] nztm2000 northing
|
37
|
+
# @option latitude: [Numeric] GRS80 latitude
|
38
|
+
# @option longitude: [Numeric] GRS80 longitude
|
39
|
+
def initialize(easting: nil, northing: nil, latitude: nil, longitude: nil)
|
32
40
|
tm_initialize(NZTM_A, NZTM_RF, NZTM_CM/(180/Math::PI), NZTM_SF, NZTM_OLAT/(180/Math::PI), NZTM_FE, NZTM_FN, 1.0)
|
41
|
+
if easting != nil && northing != nil
|
42
|
+
geod(easting, northing)
|
43
|
+
elsif( latitude != nil && longitude != nil)
|
44
|
+
nztm(latitude, longitude)
|
45
|
+
end
|
33
46
|
end
|
34
47
|
|
35
48
|
#Initialize the TM projection parameters
|
@@ -52,7 +65,7 @@ class NZTM2000
|
|
52
65
|
|
53
66
|
#*************************************************************************
|
54
67
|
# Method based on Redfearn's formulation as expressed in GDA technical
|
55
|
-
# manual at http://www.
|
68
|
+
# manual at http://www.icsm.gov.au/gda/tech.html
|
56
69
|
#
|
57
70
|
# @param latitude [Numeric] radians
|
58
71
|
# @return [Numeric] the length of meridional arc in meters (Helmert formula)
|
@@ -73,7 +86,7 @@ class NZTM2000
|
|
73
86
|
#***********************************************************************
|
74
87
|
# Calculates the foot point latitude from the meridional arc
|
75
88
|
# Method based on Redfearn's formulation as expressed in GDA technical
|
76
|
-
# manual at http://www.
|
89
|
+
# manual at http://www.icsm.gov.au/gda/tech.html
|
77
90
|
#
|
78
91
|
# @param m [Numeric] meridional arc (metres)
|
79
92
|
#
|
@@ -98,7 +111,7 @@ class NZTM2000
|
|
98
111
|
#*************************************************************************
|
99
112
|
# Routine to convert from Tranverse Mercator to latitude and longitude.
|
100
113
|
# Method based on Redfearn's formulation as expressed in GDA technical
|
101
|
-
# manual at http://www.
|
114
|
+
# manual at http://www.icsm.gov.au/gda/tech.html
|
102
115
|
# Sets @latitude, @longitude (degrees) and @latitude_r, @longitude_r (Radians)
|
103
116
|
#
|
104
117
|
# @param ce [Numeric] input northing (metres)
|
@@ -162,7 +175,7 @@ class NZTM2000
|
|
162
175
|
#
|
163
176
|
# Routine to convert from latitude and longitude to Transverse Mercator.
|
164
177
|
# Method based on Redfearn's formulation as expressed in GDA technical
|
165
|
-
# manual at http://www.
|
178
|
+
# manual at http://www.icsm.gov.au/gda/tech.html
|
166
179
|
# Loosely based on FORTRAN source code by J.Hannah and A.Broadhurst.
|
167
180
|
#
|
168
181
|
# Sets @easting (metres)
|
@@ -219,21 +232,27 @@ class NZTM2000
|
|
219
232
|
|
220
233
|
# Functions implementation the TM projection specifically for the
|
221
234
|
# NZTM coordinate system
|
235
|
+
# @param easting: [Numeric] nztm2000 easting, either named, or the first argument
|
236
|
+
# @param northing: [Numeric] nztm2000 northing, either named, or the second argument
|
222
237
|
# @return [Numeric,Numeric] latitude and longitude (decimal degrees)
|
223
|
-
def geod( easting, northing )
|
224
|
-
@easting = easting
|
225
|
-
@northing = northing
|
238
|
+
def geod( f_easting = nil, f_northing = nil, easting: nil, northing: nil )
|
239
|
+
@easting = easting || f_easting
|
240
|
+
@northing = northing || f_northing
|
241
|
+
raise ArgumentError.new("Not Numeric") if ! (@easting.is_a?(Numeric) && @northing.is_a?(Numeric) )
|
226
242
|
return tm_geod
|
227
243
|
end
|
228
244
|
|
229
245
|
# Functions implementation the TM projection specifically for the
|
230
246
|
# NZTM coordinate system
|
247
|
+
# @param latitude: [Numeric] GRS80 latitude, either named, or the first argument
|
248
|
+
# @param longitude: [Numeric] GRS80 longitude, either named, or the second argument
|
231
249
|
# @return [Numeric,Numeric] northing and easting (meters)
|
232
|
-
def nztm( latitude, longitude )
|
233
|
-
@latitude = latitude
|
234
|
-
@
|
235
|
-
@
|
236
|
-
@
|
250
|
+
def nztm( f_latitude = nil, f_longitude = nil, latitude: nil, longitude: nil )
|
251
|
+
@latitude = latitude || f_latitude
|
252
|
+
@longitude = longitude || f_longitude
|
253
|
+
raise ArgumentError.new("Not Numeric") if ! (@latitude.is_a?(Numeric) && @longitude.is_a?(Numeric) )
|
254
|
+
@latitude_r = @latitude/(180/Math::PI)
|
255
|
+
@longitude_r = @longitude/(180/Math::PI)
|
237
256
|
return geod_tm
|
238
257
|
end
|
239
258
|
|
data/test/test_nztm2000.rb
CHANGED
@@ -3,6 +3,7 @@ require "nztm2000"
|
|
3
3
|
|
4
4
|
class TestNztm2000 < Test::Unit::TestCase
|
5
5
|
def test_sanity
|
6
|
+
#Test with nil intializer, and using the NZTM2000::geod() and NZTM2000.nztm() methods.
|
6
7
|
nztm2000 = NZTM2000.new
|
7
8
|
[[1576041.150, 6188574.240, -34.444065991, 172.739193967],
|
8
9
|
[1576542.010, 5515331.050, -40.512408980, 172.723105968],
|
@@ -15,5 +16,32 @@ class TestNztm2000 < Test::Unit::TestCase
|
|
15
16
|
assert_in_delta(easting_r, easting, 0.0005)
|
16
17
|
assert_in_delta(northing_r, northing, 0.0005)
|
17
18
|
end
|
19
|
+
|
20
|
+
#Test with nil intializer, and using the NZTM2000::geod() and NZTM2000.nztm() methods with named arguments.
|
21
|
+
nztm2000 = NZTM2000.new
|
22
|
+
[[1576041.150, 6188574.240, -34.444065991, 172.739193967],
|
23
|
+
[1576542.010, 5515331.050, -40.512408980, 172.723105968],
|
24
|
+
[1307103.220, 4826464.860, -46.651295012, 169.172062008]
|
25
|
+
].each do |easting,northing, latitude, longitude|
|
26
|
+
latitude_r, longitude_r = nztm2000.geod(northing: northing, easting: easting)
|
27
|
+
easting_r, northing_r = nztm2000.nztm(longitude: longitude_r, latitude: latitude_r)
|
28
|
+
assert_in_delta(latitude_r, latitude, 0.00005)
|
29
|
+
assert_in_delta(longitude_r, longitude, 0.00005)
|
30
|
+
assert_in_delta(easting_r, easting, 0.0005)
|
31
|
+
assert_in_delta(northing_r, northing, 0.0005)
|
32
|
+
end
|
33
|
+
|
34
|
+
#Test initializers used
|
35
|
+
[[1576041.150, 6188574.240, -34.444065991, 172.739193967],
|
36
|
+
[1576542.010, 5515331.050, -40.512408980, 172.723105968],
|
37
|
+
[1307103.220, 4826464.860, -46.651295012, 169.172062008]
|
38
|
+
].each do |easting,northing, latitude, longitude|
|
39
|
+
nztm1 = NZTM2000.new(easting: easting, northing: northing)
|
40
|
+
nztm2 = NZTM2000.new(latitude: nztm1.latitude, longitude: nztm1.longitude)
|
41
|
+
assert_in_delta(nztm1.latitude, latitude, 0.00005)
|
42
|
+
assert_in_delta(nztm1.longitude, longitude, 0.00005)
|
43
|
+
assert_in_delta(nztm2.easting, easting, 0.0005)
|
44
|
+
assert_in_delta(nztm2.northing, northing, 0.0005)
|
45
|
+
end
|
18
46
|
end
|
19
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nztm2000
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Burrowes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hoe-yard
|