class Sarin::SLFActivity

Attributes

radius[R]
ref_lat[R]
ref_lon[R]
xml_doc[R]

Public Class Methods

new(xml_string, radius = 100.0, ref_lat = false, ref_lon = false) click to toggle source
# File lib/sarin.rb, line 8
def initialize(xml_string, radius = 100.0, ref_lat = false, ref_lon = false)
        @xml_doc = Nokogiri::XML(xml_string)
        @radius = radius
        if not ref_lat
                ref_lat = self.mean_lat
        end
        if not ref_lon
                ref_lon = self.mean_lon
        end
        @ref_lat = ref_lat
        @ref_lon = ref_lon
end

Public Instance Methods

correct_positions() click to toggle source
# File lib/sarin.rb, line 63
def correct_positions
        angle = 0
        self.entries.each { |entry|
                distance = entry["distance"].to_f
                angle = angle + self.delta_angle_for_distance(distance)
                entry["longitude"] = self.lon_for_angle(angle).to_s
                entry["latitude"] = self.lat_for_angle(angle).to_s
        }
end
delta_angle_for_distance(distance) click to toggle source
# File lib/sarin.rb, line 43
def delta_angle_for_distance(distance)
        2*Math.asin(distance/(2*self.radius))
end
delta_x_for_angle(angle) click to toggle source
# File lib/sarin.rb, line 47
def delta_x_for_angle(angle)
        self.radius*Math.cos(angle)
end
delta_y_for_angle(angle) click to toggle source
# File lib/sarin.rb, line 51
def delta_y_for_angle(angle)
        self.radius*Math.sin(angle)
end
entries() click to toggle source
# File lib/sarin.rb, line 21
def entries
        self.xml_doc.xpath("//Activity//Entries/Entry")
end
lat_for_angle(angle) click to toggle source
# File lib/sarin.rb, line 55
def lat_for_angle(angle)
        self.ref_lat - self.delta_y_for_angle(angle)/111300.0
end
lon_for_angle(angle) click to toggle source
# File lib/sarin.rb, line 59
def lon_for_angle(angle)
        self.ref_lon - self.delta_x_for_angle(angle)/(Math.cos(self.ref_lat * Math::PI / 180)*111300.0)
end
mean_lat() click to toggle source
# File lib/sarin.rb, line 25
def mean_lat
        lat_arr = self.entries.map { |entry|
                entry["latitude"].to_f
        }.select { |entry|
                entry != 0
        }
        lat_arr.inject{ |sum, el| sum + el }.to_f / lat_arr.size
end
mean_lon() click to toggle source
# File lib/sarin.rb, line 34
def mean_lon
        lon_arr = self.entries.map { |entry|
                entry["longitude"].to_f
        }.select { |entry|
                entry != 0
        }
        lon_arr.inject{ |sum, el| sum + el }.to_f / lon_arr.size
end
to_s() click to toggle source
# File lib/sarin.rb, line 73
def to_s
        self.xml_doc.to_s
end