Created
January 13, 2014 20:30
-
-
Save mattray/8407529 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/ruby | |
require 'ruby_kml' | |
# http://www.boutell.com/zipcodes/ | |
# read zipcodes.csv into hash, get lat/long for each zip | |
zipcodes = {} | |
File.open('zipcode.csv', 'r') do |file| | |
file.each_line do |line| | |
entry = line.gsub('"','').split(",") | |
zipcodes[entry[0]] = [entry[3],entry[4]] | |
end | |
end | |
# read employees.txt, get hash of names and zips | |
employees = [] | |
File.open("employees.txt", "r") do |file| | |
file.each_line do |line| | |
if line =~ /^\|/ && !(line =~ /^\|\|/) | |
line.gsub!(/{color:#000000}/,'') | |
line.gsub!(/{color}/,'') | |
line.gsub!(/\\\\/,'') | |
entry = line.split('| ') | |
entry.collect! {|x| x.strip} | |
if entry[9].length != 5 | |
if entry[7] == 'Seattle' | |
# Seattle | |
employees << ["#{entry[1]} #{entry[2]}", 47.6, -122.3166] | |
end | |
if entry[9] == 'GL6 6EH' | |
# Gloucestire | |
employees << ["#{entry[1]} #{entry[2]}", 51.75824, -2.23978] | |
end | |
if entry[9] == 'BT6 0DH' | |
# Belfast | |
employees << ["#{entry[1]} #{entry[2]}", 54.57707, -5.90594] | |
end | |
next | |
end | |
name = "#{entry[1]} #{entry[2]}" | |
zc = zipcodes[entry[9]] | |
lat = zc[0] | |
long = zc[1] | |
employees << [name , lat, long] | |
end | |
end | |
end | |
# write KML of employee with lat/long as points | |
kml = KMLFile.new | |
folder = KML::Folder.new(:name => 'Chef Employees') | |
employees.each do |name, lat, lng| | |
folder.features << KML::Placemark.new( | |
:name => name, | |
:geometry => KML::Point.new(:coordinates => {:lat => lat, :lng => lng}) | |
) | |
end | |
kml.objects << folder | |
puts kml.render | |
#http://maps.google.com/maps?q=https://dl.dropboxusercontent.com/s/ztau5k4t86qdqkn/employees.kml?dl=1&token_hash=AAE-ibIGf7zOYf6Q0gQ7zytDAgpcPMyRiCovXY7_D6VnrA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment