Created
March 13, 2014 05:50
-
-
Save venj/9522499 to your computer and use it in GitHub Desktop.
Dat to KML
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 | |
require "FileUtils" | |
include FileUtils | |
exit if ARGV.size != 1 | |
cd ARGV[0] do | |
Dir["*.dat"].each do |dat| | |
basename = File.basename(dat, ".dat") | |
line = open(dat).readlines[2] | |
outfile_name = "#{basename}.kml" | |
open(outfile_name, "w+") do |out| | |
out.puts %[<?xml version="1.0" encoding="UTF-8"?>] | |
out.puts %[<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">] | |
out.puts %[<Document>] | |
out.puts "<name>#{outfile_name}</name>" | |
regex = /\[(.*)\]/ | |
center_text = regex.match(line)[1] | |
center_text.split("][").each_with_index do |coord, index| | |
lat, lng = coord.split(",") | |
out.puts %Q(<Placemark> | |
<name>#{basename}_#{index}</name> | |
<styleUrl>#m_ylw-pushpin</styleUrl> | |
<Point> | |
<gx:drawOrder>#{index+1}</gx:drawOrder> | |
<coordinates>#{lng},#{lat},0</coordinates> | |
</Point> | |
</Placemark>) | |
end | |
out.puts "</Document>" | |
out.puts "</kml>" | |
end | |
#exit | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment