usingSurfer;
//色标
public static string colorfile = null;
//系统运行时物理路径-suf相关数据目录
public static string strAppPath =System.Windows.Forms.Application.StartupPath + @"\Suf";
//生成的图片文件名
public static string pname = null;
//是否有图片要插入
public static bool inpicBool = false;
//是否显示Suf
public static bool SufBool = false;
//图片高宽
public static int mapw;
public static int maph;
public void ht(string picname)
{
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 < dataGridView1.Rows.Count; i++)
{
strLine.Remove(0,strLine.Length);
strLine.Append(dataGridView1.Rows[i].Cells[1].Value.ToString() +"\t");
strLine.Append(dataGridView1.Rows[i].Cells[2].Value.ToString() +"\t");
strLine.Append(dataGridView1.Rows[i].Cells[3].Value.ToString() +"\t");
strLine.Append(dataGridView1.Rows[i].Cells[4].Value.ToString());
sw.WriteLine(strLine);
if(dataGridView1.Rows[i].Cells[4].Value.ToString() != "") //雨量不为空
{
Rain =Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value.ToString());
if (Rain > MaxValue)MaxValue = Rain;
}
}
if (MaxValue == 0)
{
MessageBox.Show("改时间段无降水数据或所有站点降水为0");
return;
}
sw.Flush();
fs.Close();
// 调用Surfer画等值线
Surfer.Application app = new Surfer.Application();
app.Visible = SufBool;
app.Caption = @"荆门市区域自动站雨量等值线图";
// Type.Missing为缺省参数
app.GridData(strAppPath + @"\Data.dat", 1, 2, 4, Type.Missing,//5
Type.Missing, Type.Missing,Type.Missing, 200, 200, //10
111.8663f, 113.5f, 30.4042f, 31.6101f, 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 +@"\jm.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 + @"\jm.bln","");
PlotDoc.Shapes.AddBaseMap(strAppPath + @"\jm.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;
ContourMap.Levels.LoadFile(strAppPath + @"\colorlev\" +colorfile);
//覆盖所有地图
PlotDoc.Shapes.SelectAll();
Surfer.IMapFrame MapFrame = PlotDoc.Selection.OverlayMaps();
MapFrame.Axes.Item(1).Visible = true;
MapFrame.Axes.Item(2).Visible = true;
MapFrame.Axes.Item(3).Visible = true;
MapFrame.Axes.Item(4).Visible = true;
PlotDoc.SaveAs(strAppPath + @"\Data.srf", "",SrfSaveFormat.srfSaveFormatDat);
string strWidthHeight =string.Format("width={0:f0},height={1:f0}", mapw, maph);
PlotDoc.Export(strAppPath + @"\basepic\" + picname, true,strWidthHeight);
if (SufBool == false)
{
app.Quit();
}
pictureBox1.Image = Bitmap.FromFile(strAppPath + @"\basepic\"+ picname);
}
以上程序测试通过,并且已经在应用中。