Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate a kml heatmap from a csv input
#!/usr/bin/ruby
require 'csv'
HEADER = '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Puzzled Pint Heat Map</name>
'
FOOTER = ' </Document>
</kml>'
out = File.new('pdx2.kml', 'w')
out << HEADER
CSV.foreach("pdx.csv") do |row|
name = row[0]
addr = row[1]
lat = row[2]
long = row[3]
value = 400 * row[4].to_i / 90
zvalue = 50 * 90 / row[4].to_i
out << " <Placemark>
<visibility>1</visibility>
<name>#{name}</name>
<address>#{addr}</address>
<Point>
<coordinates>#{long},#{lat},0</coordinates>
</Point>
<Model>
<altitudeMode>relativeToGround</altitudeMode>
<Location><longitude>#{long}</longitude><latitude>#{lat}</latitude><altitude>0</altitude></Location>
<Scale><x>#{value}</x><y>#{value}</y><z>#{zvalue}</z></Scale>
<Link><href>scaleIcon.dae</href></Link>
</Model>
</Placemark>"
end
out << FOOTER
out.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment