RINEXデータから緯度経度を取得(簡易版)

rinexデータのヘッダ部分にある「APPROX POSITION XYZ」から緯度経度を求めるスクリプト

rinexデータは国土地理院から取得できるファイルを使用します

lonlat.rb

#!/bin/env ruby 


class LonLat
	def exec(file)
		x,y,z=get_xyz(file)
		lat=Math.asin(z.to_f/6371000)*180.0/Math::PI
		lon=Math.atan2(y.to_f,x.to_f)*180.0/Math::PI
		p "latitude="+lat.to_s
		p "longitude="+lon.to_s
	end

	def get_xyz(file)
		open(file).each do |line|
			if line.include?("APPROX POSITION XYZ") then
				return line.gsub(/APPROX POSITION XYZ/,"").split(" ")
			end
		end
	end
end

if __FILE__ == $0 then
	if ARGV[0] == nil then
		p "usage:"+$0+" rinex.o"
		exit 0
	end
	LonLat.new.exec(ARGV[0])
end

実行結果

$ ruby lonlat.rb 00010700.11o
"latitude=45.1780484488787"
"longitude=141.7504468409626"