private void toolBtnContour_Click(object sender, EventArgs e)
{
if (m_MyTable == null) return;
if (m_MyTable.DefaultView.Count <= 0)//没有数据返回
{
MessageBox.Show("没有数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string strAppPath = System.Windows.Forms.Application.StartupPath;
FileStream fs = new FileStream(strAppPath + @"\Data.dat", FileMode.Create);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
StringBuilder strLine = new StringBuilder("");
double MaxValue = 0.0, Rain = 0.0;
// 写内容
for (int i = 0; i < m_MyTable.DefaultView.Count; i++)
{
strLine.Remove(0, strLine.Length);
strLine.Append(m_MyTable.DefaultView["经度"] + "\t");
strLine.Append(m_MyTable.DefaultView["纬度"] + "\t");
strLine.Append(m_MyTable.DefaultView["站名"] + "\t");
strLine.Append(m_MyTable.DefaultView["雨量"]);
sw.WriteLine(strLine);
if (m_MyTable.DefaultView["雨量"].ToString() != "") //雨量不为空
{
Rain = Convert.ToDouble(m_MyTable.DefaultView["雨量"].ToString());
if (Rain > MaxValue) MaxValue = Rain;
}
}
sw.Flush();
fs.Close();
// 调用Surfer画等值线
Surfer.Application app = new Surfer.Application();
app.Visible = true;
app.WindowState = SrfWindowState.srfWindowStateMaximized;
app.Caption = @"龙岩市区域自动站雨量等值线图";
// Type.Missing为缺省参数
app.GridData(strAppPath + @"\Data.dat", 1, 2, 4, Type.Missing, //5
Type.Missing, Type.Missing, Type.Missing, 200, 200, //10
115.8f, 117.8f, 24.3f, 26.1f, Type.Missing, //15
false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, //20
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, //25
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, //30
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, //35
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, //40
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, //45
Type.Missing, Type.Missing, Type.Missing, Type.Missing, strAppPath + @"\data.grd", //50
SrfGridFormat.srfGridFmtAscii, Type.Missing, Type.Missing, Type.Missing, Type.Missing, //55
Type.Missing, Type.Missing
);
app.GridBlank(strAppPath + @"\data.grd", strAppPath + @"\龙岩市地图边界.bln", strAppPath + @"\out.grd", SrfGridFormat.srfGridFmtAscii);
Surfer.IDocuments Docs = app.Documents;// = new Surfer.IDocuments();
Surfer.IPlotDocument PlotDoc = (Surfer.IPlotDocument)Docs.Add(SrfDocTypes.srfDocPlot);
Surfer.IMapFrame MapF = PlotDoc.Shapes.AddContourMap(strAppPath + @"\out.grd");
PlotDoc.Shapes.AddBaseMap(strAppPath + @"\龙岩市地图边界.bln", "");
PlotDoc.Shapes.AddBaseMap(strAppPath + @"\县界.bln", "");
IPostMap PostMap = (IPostMap)PlotDoc.Shapes.AddPostMap(strAppPath + @"\Data.dat", 1, 2, 3, 0, 0).Overlays.Item(1);
IPostMap PostMap1 = (IPostMap)PlotDoc.Shapes.AddPostMap(strAppPath + @"\Data.dat", 1, 2, 4, 0, 0).Overlays.Item(1);
// 数据和站点显示
PostMap.LabelPos = SrfPostPosType.srfPostPosBelow;
PostMap.LabelFont.Face = @"宋体";
PostMap.LabelFont.Size = 9;
PostMap.Symbol.Index = 11;
PostMap.Symbol.Color = srfColor.srfColorBlue;
PostMap.Symbol.Size = 0.04;
PostMap1.LabelPos = SrfPostPosType.srfPostPosAbove;
PostMap1.LabelFont.Face = @"宋体";
PostMap1.LabelFont.Size = 9;
PostMap1.Symbol.Index = 11;
PostMap1.Symbol.Color = srfColor.srfColorBlue;
PostMap1.Symbol.Size = 0.04;
//等值线填充
Surfer.IContourMap ContourMap = (Surfer.IContourMap)MapF.Overlays.Item(1);
ContourMap.FillContours = true;
ContourMap.ShowColorScale = true;
ContourMap.SmoothContours = SrfConSmoothType.srfConSmoothHigh;
//生成等级文件
string strLevel = "Value 0 \"黑色\" \"Invisible\" 0 \"ForeColor\" \"R12 G12 B12\" \"纯色\" 1 1 1";
string strLineLevel = "";
string[] strColor = new string[21] { "R117 G78 B255", "R81 G54 B255", "R44 G30 B255", "R8 G5 B255", "R0 G48 B207",
"R0 G109 B146", "R0 G169 B86", "R0 G230 B25", "R36 G255 B0", "R97 G255 B0", "R157 G255 B0", "R218 G255 B0",
"R255 G241 B0", "R255 G205 B0", "R255 G168 B0", "R255 G132 B0", "R255 G98 B0", "R255 G73 B0", "R255 G49 B0",
"R255 G25 B0", "红色"
};
if (MaxValue < 20.0) MaxValue = 20.0;
MaxValue = 100;
int interval = (int)MaxValue / 20;
//if (((int)MaxValue / 20) > 0) interval += 1;
fs = new FileStream(strAppPath + @"\RainBow1.lvl", FileMode.Create);
sw = new StreamWriter(fs, Encoding.Default);
sw.WriteLine("LVL2");
sw.WriteLine("'等级 标志 线色 线条式样 线宽 填充前景色 填充背景色 填充图案 F模式");
for (int i = 0; i < 20; i++)
{
strLineLevel = strLevel;
strLineLevel = strLineLevel.Replace("Value", (i * interval).ToString());
strLineLevel = strLineLevel.Replace("ForeColor", strColor);
sw.WriteLine(strLineLevel);
}
sw.Flush();
fs.Close();
//====生成等级文件
ContourMap.Levels.LoadFile(strAppPath + @"\RainBow1.lvl");
//ContourMap.Levels.LoadFile(strAppPath + @"\RainBow.clr");
//ContourMap.Levels.AutoGenerate( 0, 20, 2);
ContourMap.BlankLine.Style = "Invisible";
ContourMap.BlankFill.
ContourMap.Levels.Count = 6;
ContourMap.Levels.Item(1).Value = 0;
//ContourMap.Levels.Item(1).Fill.ForeColor = srfColor.srfColorBluePurple;
ContourMap.Levels.Item(2).Value = 20;
//ContourMap.Levels.Item(2).Fill.ForeColor = srfColor.srfColorBlue;
ContourMap.Levels.Item(3).Value = 40;
//ContourMap.Levels.Item(3).Fill.ForeColor = srfColor.srfColorGreen;
ContourMap.Levels.Item(4).Value = 60;
//ContourMap.Levels.Item(4).Fill.ForeColor = srfColor.srfColorYellow;
ContourMap.Levels.Item(5).Value = 80;
//ContourMap.Levels.Item(5).Fill.ForeColor = srfColor.srfColorOrange;
ContourMap.Levels.Item(6).Value = 100;
//ContourMap.Levels.Item(6).Fill.ForeColor = srfColor.srfColorRed;
ContourMap.Levels.Item(1).Fill. . ForeColor = srfColor.srfColorBabyBlue;
//覆盖所有地图
PlotDoc.Shapes.SelectAll();
Surfer.IMapFrame MapFrame = PlotDoc.Selection.OverlayMaps();
MapFrame.Axes.Item(1).Visible = false;
MapFrame.Axes.Item(2).Visible = false;
MapFrame.Axes.Item(3).Visible = false;
MapFrame.Axes.Item(4).Visible = false;
//MessageBox.Show(MapFrame.Width.ToString() +","+ MapFrame.Height.ToString());
PlotDoc.SaveAs(strAppPath + @"\Data.srf", "", SrfSaveFormat.srfSaveFormatDat);
string strWidthHeight = string.Format("width={0:f0},height={1:f0}", 600.0 * 1.5, 465.0 * 1.5);
PlotDoc.Export(strAppPath + @"\DataContour.gif", true, strWidthHeight);
app.Quit();
pictureBox1.Image = Bitmap.FromFile(strAppPath + @"\DataContour.gif");
}