Skip to content

Instantly share code, notes, and snippets.

@imvenj
Created October 8, 2019 02:28
Show Gist options
  • Save imvenj/9903dd32df84decae6bcca219ad35849 to your computer and use it in GitHub Desktop.
Save imvenj/9903dd32df84decae6bcca219ad35849 to your computer and use it in GitHub Desktop.
#!/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