Skip to content

Instantly share code, notes, and snippets.

@zerodivisi0n
Created August 11, 2013 15:28
Show Gist options
  • Save zerodivisi0n/6205356 to your computer and use it in GitHub Desktop.
Save zerodivisi0n/6205356 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -w
# My first Ruby program
require "json"
if ARGV.empty?
puts "Usage gpx2json.rb filename"
exit
end
text = File.read(ARGV[0])
points = Array.new
text.each_line do |line|
result = /lat="([0-9.]+)".+lon="([0-9.]+)"/.match(line)
if result != nil
lat = result[1].to_f
lng = result[2].to_f
points.push([lat, lng])
end
end
puts JSON.generate(points)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment