Class: NZTM2000

Inherits:
Object
  • Object
show all
Defined in:
lib/nztm2000.rb

Constant Summary collapse

VERSION =
'1.1.0'
NZTM_A =

Define the parameters for the International Ellipsoid used for the NZGD2000 datum (and hence for NZTM)

6378137.0
NZTM_RF_GRS80 =

GRS80 Inverse flattening between equatorial and polar.

298.257222101
NZTM_RF_WGS84 =

Inverse flattening.

298.257223563
NZTM_RF =
NZTM_RF_GRS80
NZTM_CM =
173
NZTM_OLAT =
0.0
NZTM_SF =
0.9996
NZTM_FE =
1600000.0
NZTM_FN =
10000000.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(easting: nil, northing: nil, latitude: nil, longitude: nil) ⇒ NZTM2000

Initialize Without arguments, use geod or nztm methods. Given easting: and northing:, @latitude and @longitude will be calculated Given latitude: and longitude:, @easting: and @northing will be calculated

Parameters:

  • easting: (Hash) (defaults to: nil)

    a customizable set of options

  • northing: (Hash) (defaults to: nil)

    a customizable set of options

  • latitude: (Hash) (defaults to: nil)

    a customizable set of options

  • longitude: (Hash) (defaults to: nil)

    a customizable set of options



39
40
41
42
43
44
45
46
# File 'lib/nztm2000.rb', line 39

def initialize(easting: nil, northing: nil, latitude: nil, longitude: nil)
  tm_initialize(NZTM_A, NZTM_RF, NZTM_CM/(180/Math::PI), NZTM_SF, NZTM_OLAT/(180/Math::PI), NZTM_FE, NZTM_FN, 1.0)
  if easting != nil && northing != nil
    geod(easting, northing)
  elsif( latitude != nil && longitude != nil)
    nztm(latitude, longitude)
  end
end

Instance Attribute Details

#aObject

Ellipsoid parameters



22
23
24
# File 'lib/nztm2000.rb', line 22

def a
  @a
end

#e2Object

Ellipsoid parameters



22
23
24
# File 'lib/nztm2000.rb', line 22

def e2
  @e2
end

#eastingObject

NZTM 2000 easting (meters)



29
30
31
# File 'lib/nztm2000.rb', line 29

def easting
  @easting
end

#ep2Object

Ellipsoid parameters



22
23
24
# File 'lib/nztm2000.rb', line 22

def ep2
  @ep2
end

#fObject

Ellipsoid parameters



22
23
24
# File 'lib/nztm2000.rb', line 22

def f
  @f
end

#falseeObject

False easting



19
20
21
# File 'lib/nztm2000.rb', line 19

def falsee
  @falsee
end

#falsenObject

False northing



20
21
22
# File 'lib/nztm2000.rb', line 20

def falsen
  @falsen
end

#latitudeObject

Latitude (decimal degrees)



24
25
26
# File 'lib/nztm2000.rb', line 24

def latitude
  @latitude
end

#latitude_rObject

Latitude (radians)



25
26
27
# File 'lib/nztm2000.rb', line 25

def latitude_r
  @latitude_r
end

#longitudeObject

Longitude (Decimal degrees)



26
27
28
# File 'lib/nztm2000.rb', line 26

def longitude
  @longitude
end

#longitude_rObject

Longitude (radians)



27
28
29
# File 'lib/nztm2000.rb', line 27

def longitude_r
  @longitude_r
end

#meridianObject

Central meridian



16
17
18
# File 'lib/nztm2000.rb', line 16

def meridian
  @meridian
end

#northingObject

NZTM 2000 northing (meters)



28
29
30
# File 'lib/nztm2000.rb', line 28

def northing
  @northing
end

#orglatObject

Origin latitude



18
19
20
# File 'lib/nztm2000.rb', line 18

def orglat
  @orglat
end

#rfObject

Ellipsoid parameters



22
23
24
# File 'lib/nztm2000.rb', line 22

def rf
  @rf
end

#scalefObject

Scale factor



17
18
19
# File 'lib/nztm2000.rb', line 17

def scalef
  @scalef
end

#utomkObject

Unit to metre conversion



21
22
23
# File 'lib/nztm2000.rb', line 21

def utomk
  @utomk
end

Class Method Details

.testObject



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/nztm2000.rb', line 259

def self.test
  nztm2000 = self.new
  [[1576041.150, 6188574.240], 
   [1576542.010, 5515331.050],
   [1307103.220, 4826464.860]].each do |easting,northing|
     latitude, longitude = nztm2000.geod(easting, northing)
     r_easting, r_northing = nztm2000.nztm(latitude, longitude)
   
     puts "Input  NZTM easting, northing: #{"%12.3f"%easting}, #{"%12.3f"%northing}"
     puts "Output     Latitude Longitude: #{"%12.9f"%latitude}, #{"%12.9f"%longitude}"
     puts "Output NZTM easting, northing: #{"%12.3f"%r_easting}, #{"%12.3f"%r_northing}"
     puts "Difference:                    #{"%12.3f"%(easting - r_easting)}, #{"%12.3f"%(northing - r_northing)}"
     puts
   end
end

Instance Method Details

#geod(f_easting = nil, f_northing = nil, easting: nil, northing: nil) ⇒ Object

Functions implementation the TM projection specifically for the

NZTM coordinate system

Parameters:

  • easting: (Numeric) (defaults to: nil)

    nztm2000 easting, either named, or the first argument

  • northing: (Numeric) (defaults to: nil)

    nztm2000 northing, either named, or the second argument @return [Numeric,Numeric] latitude and longitude (decimal degrees)

Raises:

  • (ArgumentError)


238
239
240
241
242
243
# File 'lib/nztm2000.rb', line 238

def geod( f_easting = nil, f_northing = nil, easting: nil, northing: nil )
  @easting = easting || f_easting
  @northing = northing || f_northing
  raise ArgumentError.new("Not Numeric") if ! (@easting.is_a?(Numeric) && @northing.is_a?(Numeric) )
  return tm_geod
end

#nztm(f_latitude = nil, f_longitude = nil, latitude: nil, longitude: nil) ⇒ Object

Functions implementation the TM projection specifically for the

NZTM coordinate system

Parameters:

  • latitude: (Numeric) (defaults to: nil)

    GRS80 latitude, either named, or the first argument

  • longitude: (Numeric) (defaults to: nil)

    GRS80 longitude, either named, or the second argument @return [Numeric,Numeric] northing and easting (meters)

Raises:

  • (ArgumentError)


250
251
252
253
254
255
256
257
# File 'lib/nztm2000.rb', line 250

def nztm( f_latitude = nil, f_longitude = nil, latitude: nil, longitude: nil )
  @latitude = latitude || f_latitude
  @longitude = longitude || f_longitude
  raise ArgumentError.new("Not Numeric") if ! (@latitude.is_a?(Numeric) && @longitude.is_a?(Numeric) )
  @latitude_r = @latitude/(180/Math::PI)
  @longitude_r = @longitude/(180/Math::PI)
  return geod_tm
end

#tm_initialize(a, rf, cm, sf, lto, fe, fn, utom) ⇒ Object

Initialize the TM projection parameters



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/nztm2000.rb', line 49

def tm_initialize( a, rf, cm, sf, lto, fe, fn, utom )
   @meridian = cm
   @scalef = sf
   @orglat = lto
   @falsee = fe
   @falsen = fn
   @utom = utom
   f = rf != 0.0 ? 1.0/rf : 0.0
   @a = a
   @rf = rf
   @f = f
   @e2 = 2.0*f - f*f
   @ep2 = @e2/( 1.0 - @e2 )

   @om = meridian_arc( lto )
end