Skip to content

Instantly share code, notes, and snippets.

@juliandunn
Forked from mattray/employees.rb
Last active January 3, 2016 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliandunn/8408301 to your computer and use it in GitHub Desktop.
Save juliandunn/8408301 to your computer and use it in GitHub Desktop.
#!/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]}", entry[5], 47.6, -122.3166]
end
if entry[9] == 'GL6 6EH'
# Gloucestire
employees << ["#{entry[1]} #{entry[2]}", entry[5], 51.75824, -2.23978]
end
if entry[9] == 'BT6 0DH'
# Belfast
employees << ["#{entry[1]} #{entry[2]}", entry[5], 54.57707, -5.90594]
end
if entry[9] == 'SM5 3SB'
# London, England
employees << ["#{entry[1]} #{entry[2]}", entry[5], 51.5072, 0.1275]
end
if entry[9] == 'LA1'
# Lancaster, UK
employees << ["#{entry[1]} #{entry[2]}", entry[5], 54.047, -2.801]
end
next
end
name = "#{entry[1]} #{entry[2]}"
dept = entry[5]
zc = zipcodes[entry[9]]
lat = zc[0]
long = zc[1]
employees << [name, dept, 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, dept, lat, lng|
folder.features << KML::Placemark.new(
:name => name,
:description => dept,
: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