Creating KML data by converting ManyTime app data
On Mac, this ruby script translates ManyTime data to KML data.
This ruby script performs and translates the manytime-2.txt file
to the output.txt file. It works in the terminal on Mac OS X 10.8.5.
The Ruby 1.8.7 is used.
$ ruby convertKML.rb manytime-2.txt > output.kml
manytime-2.txt:
output.txt:
convertKML.rb:
This ruby script performs and translates the manytime-2.txt file
to the output.txt file. It works in the terminal on Mac OS X 10.8.5.
The Ruby 1.8.7 is used.
$ ruby convertKML.rb manytime-2.txt > output.kml
manytime-2.txt:
2013-12-05 21:18:00 2013-12-05 21:23:00 [2013-12-05 21:20:51,34.985458,135.757755] 2013-12-05 22:25:00 2013-12-05 22:30:00 [2013-12-05 22:25:56,35.039370,135.729243]
output.txt:
2013-12-05 21:20:51 135.757755,34.985458,undefined 2013-12-05 22:25:56 135.729243,35.039370,undefined
convertKML.rb:
#From the argument aString that is the result of the pattern match, #create arow to output. def nameString(aMatchString) withoutParentheses = aMatchString.sub(/\[/,"") withoutParentheses = withoutParentheses.sub(/\]/,"") anArray = withoutParentheses.split(",") return " #{anArray[0]} " end #From the argument previousString that is a string in front of the pattern match result, #create arow to output. def descriptionString(previousMatchString) return " " end #From the argument aCoordinates that is an array of coordinate value data, #create a row to output. Height data does not exist, so output "undefined". def pointString(aCoordinates) #In row, it is output in the form . return " longitude, latitude, height " end #From the argument aCoordinates that is an array of coordinates values, #create a string of the coordinates value. def coordinatesString(aCoordinates) #For example, it returns the string form of "2013-11-21 18:35:46,34.555555,135.777777". date = "#{aCoordinates[0]}-#{aCoordinates[1]}-#{aCoordinates[2]}" time = "#{aCoordinates[3]}:#{aCoordinates[4]}:#{aCoordinates[5]}" coordinates = "#{aCoordinates[6]},#{aCoordinates[7]}" return "#{date} #{time},#{coordinates}" end aHash = Hash.new File.open(ARGV[0], "r") { | f | puts "" puts " #{aCoordinates[7]},#{aCoordinates[6]},undefined " puts " " }" while line = f.gets #Create an array with coordinate values that match the regular expression. #Specify the pattern, for example, to match "2013-11-21 18:35:46,34.555555,135.777777". coordinatesArray = line.scan(/\[([1]{1}[9]{1}[9]{1}\d{1}|[2-9]{1}\d{3})-([0,1]?\d{1})-([0-2]?\d{1}|[3][0,1]{1})\s([0]?\d|1\d|2[0-3]):([0-5]\d):([0-5]\d),(\-?\d{1,2}\.\d{6}),(\-?\d{1,3}\.\d{6})\]/) #If there is a matched coordinates value in the line, perform text output process. if (coordinatesArray.length > 0) #Get the last coordinates value from the results of the scan. lastCoordinates = coordinatesArray.last #Get a string of coordinates value from an array of coordinates values. aCoordinatesString = coordinatesString(lastCoordinates) #Create the condition of pattern matching. aMatch = "\\[" + aCoordinatesString + "\\]" #Pattern-match the last coordinates value in the line. /#{aMatch}/ =~ line puts " " puts "" puts " #{nameString($&)}" puts " #{descriptionString($`)}" puts " #{pointString(lastCoordinates)}" puts " " end end puts "
2013-12-16 01:39