Created
August 11, 2013 15:28
-
-
Save zerodivisi0n/6205356 to your computer and use it in GitHub Desktop.
This file contains 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 -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