Permalink
Browse files

Spec running again

  • Loading branch information...
1 parent 866f678 commit 29a7389cf9ab2c48adb37ab36d4dd466ee0c65d4 @tallakt committed Oct 28, 2011
Showing with 26 additions and 23 deletions.
  1. +1 −1 lib/geoutm/latlon.rb
  2. +2 −2 lib/geoutm/utm.rb
  3. +12 −17 lib/geoutm/utm_zones.rb
  4. +2 −3 spec/geoutm_spec.rb
  5. +9 −0 spec/utm_spec.rb
View
@@ -18,7 +18,7 @@ def to_s
'%0.6f%s %0.6f%s' % [@lat.abs, north_south, @lon.abs, east_west]
end
- def to_utm(ellipsoid = Ellipsoid::WGS84, options = {})
+ def to_utm(options = {})
UTM::latlon_to_utm self, options
end
end
View
@@ -84,11 +84,11 @@ def to_lat_lon
(5 + 3 * t1 + 10 * c1 - 4 * c1 * c1 - 9 * eccPrimeSquared) * d ** 4 / 24 +
(61 + 90 * t1 + 298 * c1 + 45 * t1 * t1 -
252 * eccPrimeSquared - 3 * c1 * c1) * d ** 6 / 720)
- latitude_deg = latitude_rad * 180.0 * Math::PI
+ latitude_deg = latitude_rad * 180.0 / Math::PI
lon_tmp = (d - (1 + 2 * t1 + c1) * d ** 3 / 6 +
(5 - 2 * c1 + 28 * t1 - 3 * c1 * c1 + 8 * eccPrimeSquared +
24 * t1 * t1) * d ** 5 / 120) / Math::cos(phi1rad)
- longitude_deg = UTMZones::lon_origin(@zone) + lon_tmp * 180.0 * Math::PI
+ longitude_deg = UTMZones::lon_origin(@zone) + lon_tmp * 180.0 / Math::PI
LatLon.new latitude_deg, longitude_deg
end
View
@@ -3,15 +3,15 @@
module GeoUtm
module UTMZones # :nodoc:
SPECIAL_ZONES = {
- '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)}
+ '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}
}
- REGULAR_BANDS = {
+ BANDS = {
'X' => 72.0..84.0,
'W' => 64.0..72.0,
'V' => 56.0..64.0,
@@ -47,23 +47,18 @@ def UTMZones.search_for_special_zones(lat, lon)
# :nodoc:
def UTMZones.calc_utm_default_zone(lat, lon)
- '%02d%s' % [((clean_longitude(lon) + 180)/6).to_i + 1, calc_utm_default_letter(lat)]
+ '%d%s' % [((clean_longitude(lon) + 180)/6).to_i + 1, calc_utm_default_letter(lat)]
end
# :nodoc:
def UTMZones.lon_origin(zone)
- info = SPECIAL_ZONES[zone]
- if info
- range = info[:lon]
- 0.5 * (range.min + range.max)
- else
- (zone_number_from_zone(zone) - 1) * 6 - 180 + 3
- end
+ sp = SPECIAL_ZONES[zone]
+ (sp && sp[:lon_origin]) || (zone_number_from_zone(zone) - 1) * 6 - 180 + 3
end
# :nodoc:
def UTMZones.calc_utm_default_letter(lat)
- result = REGULAR_BANDS.find {|letter, lats| lats.member?(lat) }
+ result = BANDS.find {|letter, lats| lats.member?(lat) }
raise GeoUtmException, "Latitude #{lat} out of UTM range" unless result
result.first
end
@@ -90,7 +85,7 @@ def UTMZones.validate_zone(zone_in)
# :nodoc:
def UTMZones.northern_hemisphere?(zone)
- zone.match /..[NPQRSTUVWX]/
+ zone.match /[NPQRSTUVWX]$/
end
# :nodoc:
View
@@ -19,7 +19,7 @@ module GeoUtm
it "should convert from lat/lon to UTM" do
@testdata.each do |sample|
latlon = LatLon.new sample[:latitude].to_f, sample[:longitude].to_f
- utm = latlon.to_utm Ellipsoid::lookup(sample[:ellipsoid])
+ utm = latlon.to_utm :ellipsoid => sample[:ellipsoid]
utm.n.should be_within(0.01).of(sample[:northing].to_f)
utm.e.should be_within(0.01).of(sample[:easting].to_f)
utm.zone.should == sample[:zone]
@@ -28,8 +28,7 @@ module GeoUtm
it "should convert from UTM to lat/lon" do
@testdata.each do |sample|
- utm = UTM.new sample[:zone], sample[:easting].to_f, sample[:northing].to_f,
- Ellipsoid::lookup(sample[:ellipsoid])
+ utm = UTM.new sample[:zone], 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)
View
@@ -66,5 +66,14 @@ module GeoUtm
it 'should accept valid UTM zones' do
lambda {UTMZones::split_zone '51C'}.should_not raise_error
end
+
+ it 'should calculate correct longitude origin' do
+ UTMZones::lon_origin('32U').should == 9
+ UTMZones::lon_origin('32R').should == 9
+ UTMZones::lon_origin('32W').should == 9
+ UTMZones::lon_origin('32V').should == 15
+ UTMZones::lon_origin('32X').should == 9
+ UTMZones::lon_origin('40H').should == 57
+ end
end
end

0 comments on commit 29a7389

Please sign in to comment.