Class: EnergyPlus::KmlFile
- Inherits:
-
Object
- Object
- EnergyPlus::KmlFile
- Defined in:
- lib/energyplus/KmlFile.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(path) ⇒ KmlFile
constructor
A new instance of KmlFile.
- #savefile ⇒ Object
Constructor Details
#initialize(path) ⇒ KmlFile
Returns a new instance of KmlFile.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/energyplus/KmlFile.rb', line 30 def initialize(path) @path = path @data = [] @region_lu = Hash.new("regions") @region_lu["1_africa_wmo_region_1"] = "Africa, WMO Region 1" @region_lu["2_asia_wmo_region_2"] = "Asia, WMO Region 2" @region_lu["3_south_america_wmo_region_3"] = "South America, WMO Region 3" @region_lu["4_north_and_central_america_wmo_region_4"] = "North and Central America, WMO Region 4" @region_lu["5_southwest_pacific_wmo_region_5"] = "Southwest Pacific Ocean, WMO Region 5" @region_lu["6_europe_wmo_region_6"] = "Europe, WMO Region 6" end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
28 29 30 |
# File 'lib/energyplus/KmlFile.rb', line 28 def data @data end |
Instance Method Details
#savefile ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/energyplus/KmlFile.rb', line 44 def savefile kmlfile = File.new(@path, 'w') kmlxml = Builder::XmlMarkup.new(:target => kmlfile, :indent=>2) #setup the xml/kml file kmlxml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" kmlxml.kml("xmlns" => "http://www.opengis.net/kml/2.2") { kmlxml.Document { kmlxml.name "EnergyPlus Weather Data" kmlxml.visibility "0" kmlxml.description { kmlxml.cdata!("<img src=\"kml/ep_header6.png\" width=280><p>Weather data for use with EnergyPlus building energy simulation software (http://www.energyplus.gov).<p>Locations are organized by World Meteorological Organization (WMO) region, country, and state/province. Download individual weather data files through links in each location description.") } kmlxml.LookAt { kmlxml.longitude "-105" kmlxml.latitude "15" kmlxml.altitude "0" kmlxml.range "15000000" kmlxml.tilt "6.880472140100155e-015" kmlxml.heading "4.971764876159099e-015" kmlxml.altitudeMode "relativeToGround" } kmlxml.Style("id" => "weatherlocation_normal") { kmlxml.IconStyle { kmlxml.scale "0.6" kmlxml.Icon { kmlxml.href "kml/E+_logo.png" } } kmlxml.BalloonStyle { kmlxml.text { kmlxml.cdata!("<b><font color=\"#CC0000\" size=\"+3\">$[name]</font></b><br/><font>$[description]</font>") } kmlxml.bgColor "ffffffbb" } } kmlxml.StyleMap("id" => "weatherlocation") { kmlxml.Pair { kmlxml.key "normal" kmlxml.styleUrl "#weatherlocation_normal" } kmlxml.Pair { kmlxml.key "highlight" kmlxml.styleUrl "#weatherlocation_hiliteicon" } } kmlxml.Style("id" => "weatherlocation_hiliteicon") { kmlxml.IconStyle { kmlxml.scale "0.9" kmlxml.Icon { kmlxml.href "kml/E+_logo.png" } kmlxml.hotSpot { kmlxml.x "0.5" kmlxml.y "0.5" kmlxml.xunits "fraction" kmlxml.yunits "fraction" } kmlxml.BalloonStyle { kmlxml.text { kmlxml.cdata!("<b><font color=\"#CC0000\" size=\"+3\">$[name]</font></b> <br/><font>$[description]</font>") } kmlxml.bgColor "ffffffbb" } } } #write out each location #the data is stored in a custom format that is two layers dep using the DataHash.rb #file that Nicholas Long wrote @data.each do |region| kmlxml.Folder { kmlxml.name @region_lu[region.name] kmlxml.visibility "0" kmlxml.description { kmlxml.cdata!("<img src=\"kml/ep_header7.png\" align=right>") } region.data.each do |country| kmlxml.Folder { kmlxml.name country.name kmlxml.visibility "0" country.data.each do |state| if state != "" && state != "-" then kmlxml.Folder { kmlxml.name state.name kmlxml.visibility "0" state.data.each do |weather| weather.toKml(kmlxml) end } else state.data.each do |weather| weather.toKml(kmlxml) end end end } end } end @data.each do |reg| puts reg.name reg.data.each do |reg_data| puts " #{reg_data.name}" reg_data.data.each do |reg_data_2| puts " #{reg_data_2.name}" reg_data_2.data.each do |reg_data_3| puts " #{reg_data_3.path}" end end end end } } end |