Module: GeoUtm::UTMZones

Defined in:
lib/geoutm/utm_zones.rb

Overview

This module is used by the UTM class and is generally never used directly

Constant Summary collapse

SPECIAL_ZONES =

:nodoc:

{
	'31V' => {:lat => (56.0..64.0), :lon => (0.0..3.0), :lon_origin => 3.0}, 
	'32V' => {:lat => (56.0..64.0), :lon => (3.0..12.0), :lon_origin => 15.0}, 
	'31X' => {:lat => (72.0..84.0), :lon => (0.0..9.0), :lon_origin => 3.0}, 
	'33X' => {:lat => (72.0..84.0), :lon => (9.0..21.0), :lon_origin => 15.0}, 
	'35X' => {:lat => (72.0..84.0), :lon => (21.0..33.0), :lon_origin => 27.0}, 
	'37X' => {:lat => (72.0..84.0), :lon => (33.0..42.0), :lon_origin => 39.0}
}
BANDS =
{
    'X' => 72.0..84.0,
    'W' => 64.0..72.0,
    'V' => 56.0..64.0,
    'U' => 48.0..56.0,
    'T' => 40.0..48.0,
    'S' => 32.0..40.0,
    'R' => 24.0..32.0,
    'Q' => 16.0..24.0,
    'P' => 8.0..16.0,
    'N' => 0.0..8.0,
    'M' => -8.0..0.0,
    'L' => -16.0..-8.0,
    'K' => -24.0..-16.0,
    'J' => -32.0..-24.0,
    'H' => -40.0..-32.0,
    'G' => -48.0..-40.0,
    'F' => -56.0..-48.0,
    'E' => -64.0..-56.0,
    'D' => -72.0..-64.0,
    'C' => -80.0..-72.0,
}

Class Method Summary collapse

Class Method Details

.calc_utm_default_letter(lat) ⇒ Object

:nodoc:

Raises:



62
63
64
65
66
# File 'lib/geoutm/utm_zones.rb', line 62

def UTMZones.calc_utm_default_letter(lat)
    result = BANDS.find {|letter, lats| lats.member?(lat) }
    raise GeoUtmException, "Latitude #{lat} out of UTM range" unless result
    result.first
end

.calc_utm_default_zone(lat, lon) ⇒ Object

:nodoc:



51
52
53
# File 'lib/geoutm/utm_zones.rb', line 51

def UTMZones.calc_utm_default_zone(lat, lon)
    '%d%s' % [((clean_longitude(lon) + 180)/6).to_i + 1, calc_utm_default_letter(lat)]
end

.calc_utm_zone(lat, lon) ⇒ Object

:nodoc:



40
41
42
# File 'lib/geoutm/utm_zones.rb', line 40

def UTMZones.calc_utm_zone(lat, lon)
    search_for_special_zones(lat, lon) || calc_utm_default_zone(lat, lon)
end

.clean_longitude(lon) ⇒ Object

:nodoc:



94
95
96
# File 'lib/geoutm/utm_zones.rb', line 94

def UTMZones.clean_longitude(lon)
  lon - ((lon + 180)/360).to_i * 360
end

.lon_origin(zone) ⇒ Object

:nodoc:



56
57
58
59
# File 'lib/geoutm/utm_zones.rb', line 56

def UTMZones.lon_origin(zone)
  sp = SPECIAL_ZONES[zone]
  (sp && sp[:lon_origin]) || (zone_number_from_zone(zone) - 1) * 6 - 180 + 3
end

.northern_hemisphere?(zone) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


89
90
91
# File 'lib/geoutm/utm_zones.rb', line 89

def UTMZones.northern_hemisphere?(zone)
  zone.match /[NPQRSTUVWX]$/
end

.search_for_special_zones(lat, lon) ⇒ Object

:nodoc:



45
46
47
48
# File 'lib/geoutm/utm_zones.rb', line 45

def UTMZones.search_for_special_zones(lat, lon)
  result = SPECIAL_ZONES.find {|k, v| v[:lat].member?(lat) && v[:lon].member?(lon)}
  result && result.first
end

.split_zone(zone_in) ⇒ Object

:nodoc:

Raises:



74
75
76
77
78
79
80
# File 'lib/geoutm/utm_zones.rb', line 74

def UTMZones.split_zone(zone_in)      
  m = zone_in.match /^(\d+)([CDEFGHJKLMNPQRSTUVWX])$/
  raise GeoUtmException, 'Illegal zone: ' + zone_in unless m
  zn, zl = m[1].to_i, m[2]
  raise GeoUtmException, 'Illegal zone: ' + zone_in unless (1..60).member? zn
  return zn, zl
end

.validate_zone(zone_in) ⇒ Object

:nodoc:



83
84
85
86
# File 'lib/geoutm/utm_zones.rb', line 83

def UTMZones.validate_zone(zone_in)
  UTMZones.split_zone zone_in # throw exception
  true
end

.zone_number_from_zone(zone) ⇒ Object

:nodoc:



69
70
71
# File 'lib/geoutm/utm_zones.rb', line 69

def UTMZones.zone_number_from_zone(zone)
  UTMZones.split_zone(zone).first.to_i
end