请问如何用C#调用surfer 来画等值线图

jdsqxj 2009-05-20 08:24:34
我是想用C#调用surfer 来画等值线图,但是对sunfer里面很多函数的参数运用不清楚,请大虾门能不能贴点代码,或者发个例子啊,不盛感激!

邮箱:wwj830@163.com
...全文
917 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Forrest23 2010-05-20
  • 打赏
  • 举报
回复

using System;
using System.Threading;
using System.Drawing;

// Before using this code you need to add a reference to the Surfer.exe program,
// which will automatically cause a type library to be generated.
// 1. In Visual Studio .NET, open the Solution Explorer
// 2. Right-click on References and select "Add Reference"
// 3. Click "Browse", find Surfer.exe and click "Open"
// 4. Click OK
// You can all add "using Surfer;" to the top of this file to to avoid having to
// reference the Server namespace on declarations.
//
//

namespace TT
{
/// <summary>
/// Demonstrates how to control surfer from a C# class
/// </summary>
public class SurferControl {
public Surfer.IColorMap ColorMap;

public SurferControl() {
//
// TODO: Add constructor logic here
//
// Make an instance of the application
Surfer.ApplicationClass AppSurfer = new Surfer.ApplicationClass();

// Make the application visible
AppSurfer.Visible = true;

// Get the Documents collection
Surfer.IDocuments Docs = AppSurfer.Documents;

// Add a new document to the Documents collection
Surfer.IPlotDocument Doc = (Surfer.IPlotDocument) Docs.Add(Surfer.SrfDocTypes.srfDocPlot);

// Get the Shapes collection from the document
Surfer.IShapes Shapes = Doc.Shapes;

// Create a shaded relief map from the helens2.grd file
Surfer.IMapFrame MapFrame = Shapes.AddReliefMap(AppSurfer.Path + @"\samples\helens2.grd");

// Get the shaded relief overlay from the map frame
Surfer.IReliefMap ReliefMap = (Surfer.IReliefMap) MapFrame.Overlays.Item(1);

// Get the ColorMap used by the relief map
ColorMap = ReliefMap.ColorMap;

// Animate the colors of the shaded relief map from the default black to red.
Thread AnimateThread = new Thread(new ThreadStart(AnimateColorMap));
AnimateThread.Start();

}



hsfangxs 2010-05-20
  • 打赏
  • 举报
回复
ActiveX 对象名:Suefer.ApplicationClass
//具体方法
Suefer.ApplicationClass AppSurfer=new Surfer.ApplicationClass();
//对Surfer的调用
AppSurfer.Visible=false;//注Surfer窗口是不显现
AppSurfer.ScreenUpdating=false;//Surfer制图过程是否显示;
//建立一个绘图文档和一个绘图窗口
Surfer.IPlotDocumentDoc=(Surfer.IPlotDocument) AppSufer.Document Add(SrfDocType.srfDocPlot);
//给对象AppSurfer添加空白绘图文档,并取名为Doc;
Surfer.MapFrame mapframe=Doc.Shapes.AddPostMap(PostCSVFile,3,2,7,5,0);
/*新建一个给地图添加标注文件的图层
PostCSVFile就是标注文件的路径加文件名, 3代表文件中的第三列是经度, 2代表第二列是纬度, 7代表第七列是需要标注的名称, 5表示所需要选用的
符号, 0是标注选用的角度;*/
mapframe.Axes.Item(1).LablelFormat Postfix="E";
mapframe.Axes.Item(3).LablelFormat Postfix="N";
//注:给标注图的横坐标轴后面添加E,纵坐标轴后面添加N;
Surfer.IPostMap postmap=(Surfer.IPostMap)mapframe.Overlays.Item(1);
//注:定义postmap 是mapframe上的一个标注图层;
postmap.LableFont.Bold=false;
postmap.LableFont.Size=10;
postmap.Symbol.Size=0.05;
//注: postmap 图层上的文字等不加粗,字体大小为10号,符号大小为0. 05;
AppSurfer.GridData(InCSVFile,2,3,5,nil,Surfer.SrfDupMethod.srfDupNon,0.03,0.03,nil,nil,//
10
92,110,32,43,
Surfer.SrfGridAlgrithm.srfKing,false,nil,nil,nil,nil,//20
nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,//30
nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,//40
nil,nil,nil,nil,nil,nil,nil,nil,nil,GridFile,//50
Surfer.SrfGridFormat.srfGridFmatAscii,nil,nil,nil,nil,nil,nil,)
//注:将所提供的降水文件格点化, InCSVFile即需要格点化的文件名加路径,文件第2列是经度,第3列是纬度,第5列是降水量值,网格经纬向的分
//辨率都是0. 03,起始经度是92度,终止经度是110度,起始纬度是32度,终止纬度是43度,选择的插值方法是Kriging方法, GridFile即时离散插值后生
//成的路径加文件名(其后缀应该是“. grd”, . grd文件格式是Ascii码的形式;
bit=AppSurfer.GridBlank (GridFile, outpath+ "\"+"GANKONG.BLN",GridFile,SrfGridFormat.srfGridFmtAscii);
//注:第一个GridFile为输入的离散化文件路径加文件名,将其利用bln文件去掉边界外的数据,第二个GridFile 为输出的离散化文件路径加文件
//名,其输出格式也是Ascii码;
Surfer.IMapFrame MapFrame1=Doc.Shapes.AddContourMap(GridFile);
//注:将格点化文件GridFile生成等值线图,并给其命名为MapFrame1;
Surfer.IContourMap ClassedCounterMap=(Surfer.IContourMap)MapFrame1.Overlays.Item(1);
//注:将等值线图形属性指定给变量ClassedCounterMap;
ClassedCounterMap.Levels.LoadFile (outpath +"\ " + " 01. lvl" ) ;
ClassedCounterMap.SmoothContours.Equals(4);
ClassedCounterMap.FillContours=true;
ClassedCounterMap.ShowColorScale=true;
/// /注:等值线图的色彩填充文件为01. lvl, Surf2er都带有这个文件,
//SmoothContours为平滑等值线边界,选择填充等值线,显示色标;
Surfer.IMapFrame mapframe2=Doc.Shapes.AddBaseMap(outpath + " \ " + " GANMAP. BLN ",outpath + " \ " + " GANKONG. BLN" ) ;
//注:添加BLN 底图并将此图层命名为map2frame2;
double[ ] CustomLevels=new double[14];
CustomLevels[0]=0;
CustomLevels[1]=1;
CustomLevels[2]=5;
CustomLevels[3]=10;
//注:定义色标的标注值,可以根据具体情况而定;
Surfer.ILevels Levels=((Surfer.IContourMap)MapFrame.Overlays.Item(1)).Levels;
Levels.Set(CustomLevels);
Levels.Item(1).Fill.ForeColor=Surfer.srfColor.srfColorLightYellow;
Levels.Item (2).Fill.ForeColor=Surfer.srfColor.srfColorBananaYellow;
Levels.Item (3).Fill.ForeColor=Surfer.srfColor.srfColorSeaGreen;
Levels.Item (4).Fill.ForeColor=Surfer.srfColor.srfColorOceanGreen;
//注:给MapFrame图层上加色标,色标方案是此处定义的颜色方案;
Levels.Item(1).ShowLabel=true;
Levels.Item(2).ShowLabel=true;
Levels.Item(3).ShowLabel=true;
Levels.Item(4).ShowLabel=true;
//注:显示色标值;
Doc.Shapes.SelectAll( );
Surfer.ISelectionsel=Doc.Selection;
sel.OverlayMaps( );
//注:将图层全部选定,然后覆盖地图;
if(bit){Surfer.IMapFrame lMapFrame=((Surfer.IMapFrame)Doc.Shapes.Item("Map")) ;
((Surfer.IContourMap)lMapFrame Overlays.Item ("Contours")).SetZOrder(Surfer.SrfZOrder.srfZOToBack);
}
((Surfer.IMapFrame)Doc.Shapes.Item("Map")).SetLimits(92,110,32,43);
//注:定义新的图层lMapFrame,新图层的大小仍然是经度92 - 110度,纬度32 - 43度;
Doc.Export(outGraphic,false,"Defaults=1,Width=720,KeepAspect=1,ColorDepth=24,Automatic=0,Quality=100");
AppSurfer.Documents.CloseAll(Surfer.SrfSave2Types.srfSaveChangesNo);
AppSurfer.Quit();
//注:输出文件加路径名是outGraphic,即图片名称,可以选择几种后缀(如png、jpg等) ,定义图片的大小、颜色、质量等等,最后退出AppSurfer;



enzoshi 2009-10-29
  • 打赏
  • 举报
回复
up...again...
bbb332 2009-05-22
  • 打赏
  • 举报
回复
up
freewind0521 2009-05-22
  • 打赏
  • 举报
回复
没做过,顶一下
liugangsys 2009-05-20
  • 打赏
  • 举报
回复
期侍中......

111,131

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧