Class: Rack::Ketai::Position
- Inherits:
-
Object
- Object
- Rack::Ketai::Position
- Defined in:
- lib/rack/ketai/position.rb
Class Method Summary collapse
-
.d2dms(d) ⇒ Object
度表記を度分秒に変換.
-
.dms2d(dms) ⇒ Object
Position.dms2d([35, 00, 35.6]) Position.dms2d(“+35.00.35.600”).
Instance Method Summary collapse
-
#initialize(options = { }) ⇒ Position
constructor
Position.new(:lat => 135.69322222222, :lng => 35.009888888889) Position.new(:lat => [35, 0,35.6], :lng => [135, 41, 35.6]) Position.new(:lat => “35.00.35.600”, :lng => “135.41.35.600”).
- #lat(datum = :wgs84) ⇒ Object
- #latlng(datum = :wgs84) ⇒ Object
- #lng(datum = :wgs84) ⇒ Object
Constructor Details
#initialize(options = { }) ⇒ Position
Position.new(:lat => 135.69322222222, :lng => 35.009888888889) Position.new(:lat => [35, 0,35.6], :lng => [135, 41, 35.6]) Position.new(:lat => “35.00.35.600”, :lng => “135.41.35.600”)
39 40 41 42 |
# File 'lib/rack/ketai/position.rb', line 39 def initialize( = { }) @lat = [:lat].kind_of?(Numeric) ? [:lat] : self.class.dms2d([:lat]) @lng = [:lng].kind_of?(Numeric) ? [:lng] : self.class.dms2d([:lng]) end |
Class Method Details
.d2dms(d) ⇒ Object
度表記を度分秒に変換
25 26 27 28 29 30 31 32 33 |
# File 'lib/rack/ketai/position.rb', line 25 def d2dms(d) di = d.to_i dd = (d.to_f - di) dm = (dd * 60) ds = (dd * 60 - dm.to_i) * 60 dsd = (dd * 60 * 60 - dm.to_i * 60 - ds.to_i) * 60 [di, dm.to_i, "#{ds.to_i}.#{dsd.to_i}".to_f] end |
.dms2d(dms) ⇒ Object
Position.dms2d([35, 00, 35.6]) Position.dms2d(“+35.00.35.600”)
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rack/ketai/position.rb', line 10 def dms2d(dms) if dms.is_a?(String) if dms =~ /^(\+|\-)?(\d+)\.(\d+)\.(\d+\.\d+)$/ dms = ["#{$1}#{$2}".to_i, $3.to_i, $4.to_f] else raise ArgumentError, "Invalid dms format." end end di, dm, ds = dms return di.to_i + dm.to_f/60 + ds.to_f/3600 end |
Instance Method Details
#lat(datum = :wgs84) ⇒ Object
44 45 46 |
# File 'lib/rack/ketai/position.rb', line 44 def lat(datum = :wgs84) latlng(datum)[0] end |
#latlng(datum = :wgs84) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rack/ketai/position.rb', line 52 def latlng(datum = :wgs84) case datum.to_sym when :tokyo97 DatumConv.jgd2tky(@lat,@lng) when :wgs84 [@lat, @lng] else [nil, nil] end end |
#lng(datum = :wgs84) ⇒ Object
48 49 50 |
# File 'lib/rack/ketai/position.rb', line 48 def lng(datum = :wgs84) latlng(datum)[1] end |