Created
January 26, 2014 01:29
-
-
Save BrianEnigma/8626708 to your computer and use it in GitHub Desktop.
Generate a kml heatmap from a csv input
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/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