Class: Gooby::Point

Inherits:
GoobyObject show all
Defined in:
lib/gooby_point.rb

Direct Known Subclasses

CsvPoint, Trackpoint

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GoobyKernel

#character_align, #default_delimiter, #invalid_altitude, #invalid_heartbeat, #invalid_latitude, #invalid_longitude, #invalid_time, #project_author, #project_copyright, #project_date, #project_embedded_comment, #project_license, #project_name, #project_version_number, #project_year, #read_as_ascii_lines, #read_lines, #strip_lines, #tokenize

Constructor Details

#initialize(*args) ⇒ Point

Returns a new instance of Point.



15
16
17
18
19
20
21
22
23
24
# File 'lib/gooby_point.rb', line 15

def initialize(*args)
  @number, @latitude, @longitude, @altitude, @uom, @heartbeat, @note = '', '', '', '', 'm', -1, ''
  if args
    if args.size == 1
      initialize_from_string(args[0]) # yaml 
    else
      initialize_from_array(args)
    end      
  end
end

Instance Attribute Details

#altitudeObject

Returns the value of attribute altitude.



13
14
15
# File 'lib/gooby_point.rb', line 13

def altitude
  @altitude
end

#latitudeObject

Returns the value of attribute latitude.



13
14
15
# File 'lib/gooby_point.rb', line 13

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



13
14
15
# File 'lib/gooby_point.rb', line 13

def longitude
  @longitude
end

#noteObject

Returns the value of attribute note.



13
14
15
# File 'lib/gooby_point.rb', line 13

def note
  @note
end

#numberObject

Returns the value of attribute number.



13
14
15
# File 'lib/gooby_point.rb', line 13

def number
  @number
end

#uomObject

Returns the value of attribute uom.



13
14
15
# File 'lib/gooby_point.rb', line 13

def uom
  @uom
end

Instance Method Details

#altitude_as_floatObject



100
101
102
# File 'lib/gooby_point.rb', line 100

def altitude_as_float
  @altitude ? @altitude.to_f : invalid_altitude
end

#csv_delimObject



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

def csv_delim
  '|'
end

#deg2rad(degrees) ⇒ Object



163
164
165
# File 'lib/gooby_point.rb', line 163

def deg2rad(degrees)
  (((0 + degrees) * Math::PI) / 180)
end

#degrees_diff(another_point) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/gooby_point.rb', line 108

def degrees_diff(another_point)      
  if (another_point)
    puts "this:  #{to_s}" if false
    puts "other: #{another_point.to_s}"  if false
    puts "lats:  #{latitude_as_float}  #{another_point.latitude_as_float}"  if false
    puts "lngs:  #{longitude_as_float}  #{another_point.longitude_as_float}"  if false
    lat_diff = latitude_as_float  - another_point.latitude_as_float
    lng_diff = longitude_as_float - another_point.longitude_as_float
    diff = lat_diff.abs + lng_diff.abs
    puts "diff: #{diff} #{lat_diff} #{lng_diff}"  if false
    diff
  else
    360
  end
end

#english_systemObject



30
31
32
33
34
35
36
# File 'lib/gooby_point.rb', line 30

def english_system
  if @uom
    (@uom == 'm') ? true : false
  else
    return true  # english is the default
  end
end

#has_coordinates?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/gooby_point.rb', line 68

def has_coordinates?
  return false if @latitude == nil
  return false if @latitude.size < 1
  return false if @longitude == nil
  return false if @longitude .size < 1
  return true
end

#heartbeat_as_floatObject



104
105
106
# File 'lib/gooby_point.rb', line 104

def heartbeat_as_float
  @heartbeat? @heartbeat.to_f : invalid_heartbeat
end

#initialize_from_array(args) ⇒ Object



42
43
44
45
46
47
# File 'lib/gooby_point.rb', line 42

def initialize_from_array(args)
  @latitude  = args[0] if args.size > 0
  @longitude = args[1] if args.size > 1
  @altitude  = args[2] if args.size > 2
  @note      = args[3] if args.size > 3
end

#initialize_from_string(yaml_value_string) ⇒ Object



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

def initialize_from_string(yaml_value_string) 
  tokens = yaml_value_string.split
  if (tokens.size > 2)
    @latitude    = tokens[0]
    @longitude   = tokens[1]
    @note        = ''
    count        = 0
    tokens.each { |tok|
      count = count + 1
      if (count > 2)
        @note << tok
        @note << ' '
      end
    } 
  end
end

#latitude_as_floatObject



92
93
94
# File 'lib/gooby_point.rb', line 92

def latitude_as_float
  @latitude ? @latitude.to_f : invalid_latitude
end

#longitude_as_floatObject



96
97
98
# File 'lib/gooby_point.rb', line 96

def longitude_as_float
  @longitude ? @longitude.to_f : invalid_longitude
end

#metric_systemObject



38
39
40
# File 'lib/gooby_point.rb', line 38

def metric_system
  return false if !english_system
end

#proximity(another_point, uom) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/gooby_point.rb', line 124

def proximity(another_point, uom)
  if (another_point)
    arg1  = latitude_as_float
    arg2  = another_point.latitude_as_float
    arg3  = latitude_as_float
    arg4  = another_point.latitude_as_float
    theta = longitude_as_float - another_point.longitude_as_float  
    res1  = Math.sin(deg2rad(arg1))
    res2  = Math.sin(deg2rad(arg2))
    res3  = Math.cos(deg2rad(arg3))
    res4  = Math.cos(deg2rad(arg4))
    res5  = Math.cos(deg2rad(theta.to_f))
    dist  = ((res1 * res2) + (res3 * res4 * res5)).to_f
    
    if (!dist.nan?)
      dist = Math.acos(dist.to_f)
      if (!dist.nan?)    
        dist = rad2deg(dist)
        if (!dist.nan?)
          dist = dist * 60 * 1.1515;
          if (!dist.nan?)
            if uom == "km"
               dist = dist * 1.609344;
            end 
            if uom == "n"
               dist = dist * 0.8684;
            end  
          end
        end
      end
      return dist.to_f
    else
      return 0
    end
  else
    return 0
  end
end

#rad2deg(radians) ⇒ Object



167
168
169
# File 'lib/gooby_point.rb', line 167

def rad2deg(radians)
  (((0 + radians) * 180) / Math::PI)
end

#to_csvObject



88
89
90
# File 'lib/gooby_point.rb', line 88

def to_csv
  return "#{@latitude}#{csv_delim}#{@longitude}#{csv_delim}#{@altitude}"
end

#to_formatted_stringObject



80
81
82
83
84
85
86
# File 'lib/gooby_point.rb', line 80

def to_formatted_string
  s =  "lat: #{@latitude.to_s.ljust(20)}"
  s << " lng: #{@longitude.to_s.ljust(20)}"
  s << " poi.#{@number.to_s.ljust(12)}"  if @number
  s << " #{@note}" if @note
  s      
end

#to_sObject



76
77
78
# File 'lib/gooby_point.rb', line 76

def to_s
  return "lat: #{@latitude} lng: #{@longitude} alt: #{@altitude} note: #{@note}"
end