private void makeImage(List <EpwData> fieldvalues, string filename) { int widthPerChart = 930; int heightPerChart = 340; int cols = 2; int rows = (int)Math.Ceiling(fieldvalues.Count / 2.0); int width = cols * widthPerChart; int height = rows * heightPerChart; Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); // white back ground g.Clear(Color.White); int colNum = 0; int rowNum = 0; for (int v = 0; v < fieldvalues.Count; v++) { EpwData data = fieldvalues[v]; int d = 0; int h = 0; int startX = colNum * 930 + 50; int startY = (rowNum + 1) * heightPerChart - 50; Font tFont = new Font("Arial", 20); SolidBrush sBrush = new SolidBrush(System.Drawing.Color.Black); //image title if (v == 0) { g.DrawString(filename.Substring(filename.LastIndexOf("\\")), tFont, sBrush, startX, startY + 25); } //graph title tFont = new Font("Arial", 16); g.DrawString(data.name, tFont, sBrush, startX, ((rowNum) * heightPerChart) + 25); float x = 0; float y = 0; Color c = new Color(); for (int i = 0; i < data.values.Count; i++) { y = startY - h * 10; x = startX + d * 2; if (data.values[i] >= data.nullValue) { c = Color.Black; } else { if (Double.IsNaN(data.values[i])) { c = Color.Black; } else { if (data.name == "DV") { c = this.defineColorRadial(data.values[i], data.min, data.max); } else { c = this.rainbowRGB(data.values[i], data.min, data.max); } } } SolidBrush p = new SolidBrush(c); g.FillRectangle(p, x, y, 2, 10); h++; if (h == 24) { d++; h = 0; } } //scale bar double range = data.max - data.min; double inc = range / 11; double val = 0; for (int s = 0; s < 11; s++) { val = data.min + s * inc; if (data.name == "DV") { c = this.defineColorRadial(val, data.min, data.max); } else { c = this.rainbowRGB(val, data.min, data.max); } SolidBrush p = new SolidBrush(c); g.FillRectangle(p, x + 30, ((rowNum + 1) * heightPerChart) - 60 - (s * 22), 20, 22); g.DrawString(Math.Round(val, 1).ToString(), tFont, sBrush, x + 60, ((rowNum + 1) * heightPerChart) - 60 - (s * 22)); } colNum++; if (colNum == 2) { colNum = 0; rowNum++; } } String fname = filename.Substring(0, filename.LastIndexOf(".")); bitmap.Save(fname + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); }
private List <EpwData> getAnnualValues(String filename) { EpwData ghr = new EpwData(); ghr.setName("GlobalHR"); EpwData diffhr = new EpwData(); diffhr.setName("DiffHR"); EpwData directhr = new EpwData(); directhr.setName("DirectHR"); EpwData hr = new EpwData(); hr.setName("HR"); EpwData nub = new EpwData(); nub.setName("NUB"); EpwData pr = new EpwData(); pr.setName("PR"); EpwData t = new EpwData(); t.setName("TS"); EpwData dv = new EpwData(); dv.setName("DV"); EpwData vv = new EpwData(); vv.setName("VV"); EpwData dpt = new EpwData(); dpt.setName("DPT"); EpwData ehr = new EpwData(); ehr.setName("ExtraTerrHR"); StreamReader sr = new StreamReader(filename); String line = sr.ReadLine(); int lineCount = 0; while (line != null) { if (lineCount >= 8) { String[] fields = line.Split(','); for (int i = 0; i < fields.Length; i++) { switch (i) { case 6: t.values.Add(Convert.ToDouble(fields[i])); break; case 7: dpt.values.Add(Convert.ToDouble(fields[i])); break; case 8: hr.values.Add(Convert.ToDouble(fields[i])); break; case 10: ehr.values.Add(Convert.ToDouble(fields[i])); break; case 13: ghr.values.Add(Convert.ToDouble(fields[i])); break; case 14: directhr.values.Add(Convert.ToDouble(fields[i])); break; case 15: diffhr.values.Add(Convert.ToDouble(fields[i])); break; case 20: dv.values.Add(Convert.ToDouble(fields[i])); break; case 21: vv.values.Add(Convert.ToDouble(fields[i])); break; case 22: nub.values.Add(Convert.ToDouble(fields[i])); break; case 33: pr.values.Add(Convert.ToDouble(fields[i])); break; } } } line = sr.ReadLine(); lineCount++; } sr.Close(); List <EpwData> fieldvalues = new List <EpwData>(); fieldvalues.Add(t); fieldvalues.Add(dpt); fieldvalues.Add(ehr); fieldvalues.Add(ghr); fieldvalues.Add(directhr); fieldvalues.Add(diffhr); fieldvalues.Add(hr); fieldvalues.Add(dv); fieldvalues.Add(vv); fieldvalues.Add(pr); fieldvalues.Add(nub); return(fieldvalues); }