Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify zones with hemisphere instead of letter, fix spec and coords in 32V #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion geoutm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.has_rdoc = true
s.homepage = %q{http://www.github.com/tallakt/geoutm}
s.rdoc_options = ["--main", "README.rdoc"]
s.require_path = ["lib"]
s.require_path = "lib"
s.description = %q{Conversion between latitude and longitude coordinates and UTM coordiantes}
s.summary = "Converting map coordinates"
s.files = Dir.glob("{spec,lib}/**/*") + %w(LICENCE README.rdoc History.txt)
Expand Down
2 changes: 1 addition & 1 deletion lib/geoutm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
require 'geoutm/latlon'

module GeoUtm
VERSION = '1.0.1'
VERSION = '1.0.3'
end
19 changes: 9 additions & 10 deletions lib/geoutm/utm_zones.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module GeoUtm
module UTMZones
# :nodoc:
SPECIAL_ZONES = {
'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}
'31V' => {:lat => (56.0..64.0), :lon => (0.0..3.0)},
'32V' => {:lat => (56.0..64.0), :lon => (3.0..12.0)},
'31X' => {:lat => (72.0..84.0), :lon => (0.0..9.0)},
'33X' => {:lat => (72.0..84.0), :lon => (9.0..21.0)},
'35X' => {:lat => (72.0..84.0), :lon => (21.0..33.0)},
'37X' => {:lat => (72.0..84.0), :lon => (33.0..42.0)}
}

BANDS = {
Expand Down Expand Up @@ -54,8 +54,7 @@ def UTMZones.calc_utm_default_zone(lat, lon)

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

# :nodoc:
Expand All @@ -72,7 +71,7 @@ def UTMZones.zone_number_from_zone(zone)

# :nodoc:
def UTMZones.split_zone(zone_in)
m = zone_in.match /^(\d+)([CDEFGHJKLMNPQRSTUVWX])$/
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
Expand All @@ -87,7 +86,7 @@ def UTMZones.validate_zone(zone_in)

# :nodoc:
def UTMZones.northern_hemisphere?(zone)
zone.match /[NPQRSTUVWX]$/
zone.match /[NPQRSTUVWX\+]$/
end

# :nodoc:
Expand Down
11 changes: 11 additions & 0 deletions spec/geoutm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,16 @@ module GeoUtm
latlon.lon.should be_within(0.01).of(sample[:longitude].to_f)
end
end

it "should convert from UTM to lat/lon without zone letter" do
@testdata.each do |sample|
zone = UTMZones.split_zone sample[:zone]
hemisphere = (UTMZones::northern_hemisphere?sample[:zone]) ? '+' : '-'
utm = UTM.new "#{zone.first}#{hemisphere}", sample[:easting].to_f, sample[:northing].to_f, sample[:ellipsoid]
latlon = utm.to_lat_lon
latlon.lat.should be_within(0.01).of(sample[:latitude].to_f)
latlon.lon.should be_within(0.01).of(sample[:longitude].to_f)
end
end
end
end