Created
October 8, 2019 02:28
-
-
Save imvenj/9903dd32df84decae6bcca219ad35849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Generate gpx for Xcode from Google Earth kml. | |
require 'time' | |
require 'nokogiri' | |
seconds_per_point = 2 | |
timestamp = Time.now.to_i | |
doc = Nokogiri::XML(open(ARGV[0])) | |
coordinates = doc.css('coordinates').text.strip.split(/\s+/).map { |s| s.split(',') } | |
builder = Nokogiri::XML::Builder.new do |xml| | |
xml.gpx do | |
coordinates.each_with_index do |coord, index| | |
xml.wpt(:lat => coord[1], :lon => coord[0]) do | |
xml.ele { xml.text coord[2] } | |
xml.time { xml.text Time.at(timestamp + index * seconds_per_point).iso8601 } | |
end | |
end | |
end | |
end | |
puts builder.to_xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment