nztm2000 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd08ac118e24a4d0236bfb2a3eb23467e59e8bab
4
+ data.tar.gz: eb448964c7a654daf2f381f3de60d4bbd7160b82
5
+ SHA512:
6
+ metadata.gz: b66cad2c660774b0cee56132ccb2f982a2c9c34c5daed8659fdf8a6340fcdccd3e8827307c8a09fe6afb60a22ce5a885124aff6d6a655e0be6fb2dbb19e10f09
7
+ data.tar.gz: 0b455392afe57938843ae6404c3e81be1623747416ca918b1b54495b272bc28ec7babefeec460229a9aaf3f9ff4e9fa80ced67e97fa3c583d89481f660b25527
data/History.txt ADDED
@@ -0,0 +1,2 @@
1
+ robertburrowes Sat Aug 6 18:05:02 2016 +1200
2
+ Ruby version of LINZ nztm.c
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/nztm2000.rb
6
+ test/test_nztm2000.rb
7
+
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # nztm2000
2
+
3
+ * http://rbur004.github.com/nztm2000/
4
+ * Source https://github.com/rbur004/nztm2000
5
+ * Gem https://rubygems.org/gems/nztm2000
6
+
7
+ ## DESCRIPTION:
8
+
9
+ ###New Zealand Transverse Mercator (NZTM) projection routines
10
+
11
+ Converts coordinates between the New Zealand Transverse Merctator 2000 and GRS80 latitude and longitude on the New Zealand Geodetic Datum 2000.
12
+
13
+ ## FEATURES/PROBLEMS:
14
+
15
+
16
+ ## SYNOPSIS:
17
+
18
+ The NZTM200 provides two public methods
19
+
20
+ NZTM2000.geod( easting, northing )
21
+ Converts easting and northing (meters) to a latitude and longitude (Decimal degrees and radian results available)
22
+
23
+ NZTM2000.nztm( latitude, longitude )
24
+ Converts latitude and longitude (Decimal degrees) to easting and northing (meters)
25
+
26
+ ## REQUIREMENTS:
27
+
28
+ *
29
+
30
+ ## INSTALL:
31
+
32
+ * sudo gem install NZTM2000
33
+
34
+ ## LICENSE:
35
+
36
+ Derived from
37
+ http://www.linz.govt.nz/geodetic/software-downloads#nztm2000
38
+
39
+ LINZ listed no specific license, but the site states:
40
+
41
+ Download and use of these software applications is taken to be acceptance of the following conditions:
42
+ ```
43
+ Land Information New Zealand (LINZ) does not offer any support for this software.
44
+ The software is provided "as is" and without warranty of any kind. In no event shall LINZ be liable for loss of any kind whatsoever with respect to the download, installation and use of the software.
45
+ The software is designed to work with MS Windows. However, LINZ makes no warranty regarding the performance or non-performance of the software on any particular system or system configuration.
46
+
47
+ Last Updated: 24 November 2014
48
+ ```
49
+
50
+ The LINZ site also carries a CC-by license
51
+ http://www.linz.govt.nz/linz-copyright
52
+
53
+
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ Hoe.plugin :yard
6
+
7
+ Hoe.spec 'nztm2000' do
8
+ self.readme_file = "README.md"
9
+ self.developer( "Rob Burrowes","r.burrowes@auckland.ac.nz")
10
+ remote_rdoc_dir = '' # Release to root
11
+
12
+ self.yard_title = 'nztm2000'
13
+ self.yard_options = ['--markup', 'markdown', '--protected']
14
+ end
15
+
16
+
17
+ #Validate manfest.txt
18
+ #rake check_manifest
19
+
20
+ #Local checking. Creates pkg/
21
+ #rake gem
22
+
23
+ #create doc/
24
+ #rake docs
25
+
26
+ #Copy up to rubygem.org
27
+ #rake release VERSION=1.0.1
data/lib/nztm2000.rb ADDED
@@ -0,0 +1,257 @@
1
+ class NZTM2000
2
+ VERSION = '1.0.0'
3
+
4
+ #Define the parameters for the International Ellipsoid
5
+ #used for the NZGD2000 datum (and hence for NZTM)
6
+ NZTM_A = 6378137.0
7
+ NZTM_RF_GRS80 = 298.257222101 #GRS80 Inverse flattening between equatorial and polar.
8
+ NZTM_RF_WGS84 = 298.257223563 #Inverse flattening.
9
+ NZTM_RF = NZTM_RF_GRS80
10
+ NZTM_CM = 173
11
+ NZTM_OLAT = 0.0
12
+ NZTM_SF = 0.9996
13
+ NZTM_FE = 1600000.0
14
+ NZTM_FN = 10000000.0
15
+
16
+ attr_accessor :meridian #Central meridian
17
+ attr_accessor :scalef #Scale factor
18
+ attr_accessor :orglat #Origin latitude
19
+ attr_accessor :falsee #False easting
20
+ attr_accessor :falsen #False northing
21
+ attr_accessor :utomk #Unit to metre conversion
22
+ attr_accessor :a, :rf, :f, :e2, :ep2 #Ellipsoid parameters
23
+
24
+ attr_accessor :latitude #Latitude (decimal degrees)
25
+ attr_accessor :latitude_r #Latitude (radians)
26
+ attr_accessor :longitude #Longitude (Decimal degrees)
27
+ attr_accessor :longitude_r #Longitude (radians)
28
+ attr_accessor :northing #NZTM 2000 northing (meters)
29
+ attr_accessor :easting #NZTM 2000 easting (meters)
30
+
31
+ def initialize
32
+ tm_initialize(NZTM_A, NZTM_RF, NZTM_CM/(180/Math::PI), NZTM_SF, NZTM_OLAT/(180/Math::PI), NZTM_FE, NZTM_FN, 1.0)
33
+ end
34
+
35
+ #Initialize the TM projection parameters
36
+ def tm_initialize( a, rf, cm, sf, lto, fe, fn, utom )
37
+ @meridian = cm
38
+ @scalef = sf
39
+ @orglat = lto
40
+ @falsee = fe
41
+ @falsen = fn
42
+ @utom = utom
43
+ f = rf != 0.0 ? 1.0/rf : 0.0
44
+ @a = a
45
+ @rf = rf
46
+ @f = f
47
+ @e2 = 2.0*f - f*f
48
+ @ep2 = @e2/( 1.0 - @e2 )
49
+
50
+ @om = meridian_arc( lto )
51
+ end
52
+
53
+ #*************************************************************************
54
+ # Method based on Redfearn's formulation as expressed in GDA technical
55
+ # manual at http://www.anzlic.org.au/icsm/gdatm/index.html
56
+ #
57
+ # @param latitude [Numeric] radians
58
+ # @return [Numeric] the length of meridional arc in meters (Helmert formula)
59
+ #
60
+ #*************************************************************************
61
+ private def meridian_arc( lt )
62
+ e4 = @e2*@e2
63
+ e6 = e4*@e2
64
+
65
+ a0 = 1 - (@e2/4.0) - (3.0*e4/64.0) - (5.0*e6/256.0)
66
+ a2 = (3.0/8.0) * (@e2+e4/4.0+15.0*e6/128.0)
67
+ a4 = (15.0/256.0) * (e4 + 3.0*e6/4.0)
68
+ a6 = 35.0*e6/3072.0
69
+
70
+ return @a*(a0*lt-a2*Math.sin(2*lt)+a4*Math.sin(4*lt)-a6*Math.sin(6*lt))
71
+ end
72
+
73
+ #***********************************************************************
74
+ # Calculates the foot point latitude from the meridional arc
75
+ # Method based on Redfearn's formulation as expressed in GDA technical
76
+ # manual at http://www.anzlic.org.au/icsm/gdatm/index.html
77
+ #
78
+ # @param m [Numeric] meridional arc (metres)
79
+ #
80
+ # @returns [Numeric] the foot point latitude (radians) #
81
+ #***********************************************************************
82
+
83
+ private def foot_point_lat( m )
84
+ n = @f/(2.0-@f)
85
+ n2 = n*n
86
+ n3 = n2*n
87
+ n4 = n2*n2
88
+
89
+ g = @a*(1.0-n)*(1.0-n2)*(1+9.0*n2/4.0+225.0*n4/64.0)
90
+ sig = m/g
91
+
92
+ return sig + (3.0*n/2.0 - 27.0*n3/32.0)*Math.sin(2.0*sig) +
93
+ (21.0*n2/16.0 - 55.0*n4/32.0)*Math.sin(4.0*sig) +
94
+ (151.0*n3/96.0) * Math.sin(6.0*sig) +
95
+ (1097.0*n4/512.0) * Math.sin(8.0*sig)
96
+ end
97
+
98
+ #*************************************************************************
99
+ # Routine to convert from Tranverse Mercator to latitude and longitude.
100
+ # Method based on Redfearn's formulation as expressed in GDA technical
101
+ # manual at http://www.anzlic.org.au/icsm/gdatm/index.html
102
+ # Sets @latitude, @longitude (degrees) and @latitude_r, @longitude_r (Radians)
103
+ #
104
+ # @param ce [Numeric] input northing (metres)
105
+ # @return [Numeric, Numeric] @latitude, @longitude (decimal degrees)
106
+ #
107
+ #*************************************************************************
108
+
109
+ private def tm_geod
110
+ cn1 = (@northing - @falsen)*@utom/@scalef + @om
111
+ fphi = foot_point_lat(cn1)
112
+ slt = Math.sin(fphi)
113
+ clt = Math.cos(fphi)
114
+
115
+ eslt = (1.0-@e2*slt*slt)
116
+ eta = @a/Math.sqrt(eslt)
117
+ rho = eta * (1.0 - @e2) / eslt
118
+ psi = eta/rho
119
+
120
+ e = (@easting-@falsee)*@utom
121
+ x = e/(eta*@scalef)
122
+ x2 = x*x
123
+
124
+ t = slt/clt
125
+ t2 = t*t
126
+ t4 = t2*t2
127
+
128
+ trm1 = 1.0/2.0
129
+
130
+ trm2 = ((-4.0*psi + 9.0*(1-t2))*psi + 12.0*t2)/24.0
131
+
132
+ trm3 = ((((8.0*(11.0-24.0*t2)*psi -
133
+ 12.0*(21.0-71.0*t2))*psi +
134
+ 15.0*((15.0*t2-98.0)*t2+15))*psi +
135
+ 180.0*((-3.0*t2+5.0)*t2))*psi + 360.0*t4)/720.0
136
+
137
+ trm4 = (((1575.0*t2+4095.0)*t2+3633.0)*t2+1385.0)/40320.0
138
+
139
+ @latitude_r = fphi+(t*x*e/(@scalef*rho))*(((trm4*x2-trm3)*x2+trm2)*x2-trm1)
140
+ @latitude = @latitude_r * 180.0 / Math::PI
141
+
142
+ trm1 = 1.0
143
+
144
+ trm2 = (psi+2.0*t2)/6.0
145
+
146
+ trm3 = (((-4.0*(1.0-6.0*t2)*psi +
147
+ (9.0-68.0*t2))*psi +
148
+ 72.0*t2)*psi +
149
+ 24.0*t4)/120.0
150
+
151
+ trm4 = (((720.0*t2+1320.0)*t2+662.0)*t2+61.0)/5040.0
152
+
153
+ @longitude_r = @meridian - (x/clt)*(((trm4*x2-trm3)*x2+trm2)*x2-trm1)
154
+ @longitude = @longitude_r * 180.0 / Math::PI
155
+
156
+ return @latitude, @longitude
157
+ end
158
+
159
+ #*************************************************************************
160
+ #
161
+ # geodtm
162
+ #
163
+ # Routine to convert from latitude and longitude to Transverse Mercator.
164
+ # Method based on Redfearn's formulation as expressed in GDA technical
165
+ # manual at http://www.anzlic.org.au/icsm/gdatm/index.html
166
+ # Loosely based on FORTRAN source code by J.Hannah and A.Broadhurst.
167
+ #
168
+ # Sets @easting (metres)
169
+ # Sets @northing (metres)
170
+ # @return [Numeric,Numeric] @easting, @northing (meters)
171
+ #*************************************************************************
172
+ private def geod_tm
173
+ dlon = @longitude_r - @meridian
174
+ while ( dlon > Math::PI ) do dlon -= (2 * Math::PI) end
175
+ while ( dlon < -Math::PI ) do dlon += ( 2 * Math::PI) end
176
+
177
+ m = meridian_arc(@latitude_r)
178
+
179
+ slt = Math.sin(@latitude_r)
180
+
181
+ eslt = (1.0-@e2*slt*slt)
182
+ eta = @a/Math.sqrt(eslt)
183
+ rho = eta * (1.0-@e2) / eslt
184
+ psi = eta/rho
185
+
186
+ clt = Math.cos(@latitude_r)
187
+ w = dlon
188
+
189
+ wc = clt*w
190
+ wc2 = wc*wc
191
+
192
+ t = slt/clt
193
+ t2 = t*t
194
+ t4 = t2*t2
195
+ t6 = t2*t4
196
+
197
+ trm1 = (psi-t2)/6.0
198
+
199
+ trm2 = (((4.0*(1.0-6.0*t2)*psi + (1.0+8.0*t2))*psi - 2.0*t2)*psi+t4)/120.0;
200
+
201
+ trm3 = (61 - 479.0*t2 + 179.0*t4 - t6)/5040.0
202
+
203
+ gce = (@scalef*eta*dlon*clt)*(((trm3*wc2+trm2)*wc2+trm1)*wc2+1.0)
204
+ @easting = gce/@utom+@falsee
205
+
206
+ trm1 = 1.0/2.0
207
+
208
+ trm2 = ((4.0*psi+1)*psi-t2)/24.0
209
+
210
+ trm3 = ((((8.0*(11.0-24.0*t2)*psi - 28.0*(1.0-6.0*t2))*psi + (1.0-32.0*t2))*psi - 2.0*t2)*psi + t4)/720.0
211
+
212
+ trm4 = (1385.0-3111.0*t2+543.0*t4-t6)/40320.0
213
+
214
+ gcn = (eta*t)*((((trm4*wc2+trm3)*wc2+trm2)*wc2+trm1)*wc2)
215
+ @northing = (gcn+m-@om)*@scalef/@utom+@falsen
216
+
217
+ return @easting, @northing
218
+ end
219
+
220
+ # Functions implementation the TM projection specifically for the
221
+ # NZTM coordinate system
222
+ # @return [Numeric,Numeric] latitude and longitude (decimal degrees)
223
+ def geod( easting, northing )
224
+ @easting = easting
225
+ @northing = northing
226
+ return tm_geod
227
+ end
228
+
229
+ # Functions implementation the TM projection specifically for the
230
+ # NZTM coordinate system
231
+ # @return [Numeric,Numeric] northing and easting (meters)
232
+ def nztm( latitude, longitude )
233
+ @latitude = latitude
234
+ @latitude_r = latitude/(180/Math::PI)
235
+ @longitude = longitude
236
+ @longitude_r = longitude/(180/Math::PI)
237
+ return geod_tm
238
+ end
239
+
240
+ def self.test
241
+ nztm2000 = self.new
242
+ [[1576041.150, 6188574.240],
243
+ [1576542.010, 5515331.050],
244
+ [1307103.220, 4826464.860]].each do |easting,northing|
245
+ latitude, longitude = nztm2000.geod(easting, northing)
246
+ r_easting, r_northing = nztm2000.nztm(latitude, longitude)
247
+
248
+ puts "Input NZTM easting, northing: #{"%12.3f"%easting}, #{"%12.3f"%northing}"
249
+ puts "Output Latitude Longitude: #{"%12.9f"%latitude}, #{"%12.9f"%longitude}"
250
+ puts "Output NZTM easting, northing: #{"%12.3f"%r_easting}, #{"%12.3f"%r_northing}"
251
+ puts "Difference: #{"%12.3f"%(easting - r_easting)}, #{"%12.3f"%(northing - r_northing)}"
252
+ puts
253
+ end
254
+ end
255
+ end
256
+
257
+
@@ -0,0 +1,19 @@
1
+ require "test/unit"
2
+ require "nztm2000"
3
+
4
+ class TestNztm2000 < Test::Unit::TestCase
5
+ def test_sanity
6
+ nztm2000 = NZTM2000.new
7
+ [[1576041.150, 6188574.240, -34.444065991, 172.739193967],
8
+ [1576542.010, 5515331.050, -40.512408980, 172.723105968],
9
+ [1307103.220, 4826464.860, -46.651295012, 169.172062008]
10
+ ].each do |easting,northing, latitude, longitude|
11
+ latitude_r, longitude_r = nztm2000.geod(easting, northing)
12
+ easting_r, northing_r = nztm2000.nztm(latitude_r, longitude_r)
13
+ assert_in_delta(latitude_r, latitude, 0.00005)
14
+ assert_in_delta(longitude_r, longitude, 0.00005)
15
+ assert_in_delta(easting_r, easting, 0.0005)
16
+ assert_in_delta(northing_r, northing, 0.0005)
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nztm2000
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Burrowes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hoe-yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.15'
41
+ description: '2000.'
42
+ email:
43
+ - r.burrowes@auckland.ac.nz
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - History.txt
48
+ - Manifest.txt
49
+ - README.md
50
+ files:
51
+ - History.txt
52
+ - Manifest.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/nztm2000.rb
56
+ - test/test_nztm2000.rb
57
+ homepage: http://rbur004.github.com/nztm2000/
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options:
63
+ - "--markup"
64
+ - markdown
65
+ - "--protected"
66
+ - "--title"
67
+ - nztm2000
68
+ - "--quiet"
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.5.1
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: '2000.'
87
+ test_files: []