Exemple #1
0
        private void GenerateContourMap()
        {
            Surfer.Application app    = new Surfer.Application();
            IDocuments         docs   = app.Documents;
            IPlotDocument      Doc    = (IPlotDocument)docs.Add(SrfDocTypes.srfDocPlot); //創建一個空白繪圖文檔
            IShapes            Shapes = Doc.Shapes;

            #region 添加等值面
            IMapFrame contourMapFrame = Shapes.AddContourMap(path + "temp.grd");        //加載網格文件
            for (int i = 1; i <= contourMapFrame.Axes.Count; i++)
            {
                contourMapFrame.Axes.Item(i).Visible       = false;
                contourMapFrame.Axes.Item(i).MajorTickType = SrfTickType.srfTickNone;
                contourMapFrame.Axes.Item(i).ShowLabels    = false;
            }
            contourMapFrame.SetLimits(xMin: 140000,     //x最小值
                                      xMax: 370000,     //x最大者
                                      yMin: 2400000,    //y最小值
                                      yMax: 2800000     //y最大值
                                      );
            contourMapFrame.xMapPerPU = 23000;          //設置比例
            contourMapFrame.yMapPerPU = 20000;          //設置比例


            IContourMap contourMap = (IContourMap)contourMapFrame.Overlays.Item(1);

            /*
             * contourMap.ShowColorScale = true;										// 顯示對應色柱
             * contourMap.ColorScale.Top = 10;										//色柱y方向位置
             * contourMap.ColorScale.Left = contourMap.Left + contourMap.Width + 0.8;//色柱x方向位置
             * contourMap.ColorScale.Width = 1;									//色柱寬度
             * contourMap.ColorScale.Height = 10;										//色柱高度
             * contourMap.ColorScale.LabelFont.Size = 10;
             * contourMap.ColorScale.LabelFont.Face = "Time New Roman";
             * contourMap.ColorScale.LabelFrequency = 1;
             * contourMap.ColorScale.Name = "PM2.5 (μg/m3)";
             */

            contourMap.FillContours = true;    //添加顏色填充
            //通過文件加載顏色
            ILevels levels = contourMap.Levels;
            levels.LoadFile(path + "PM25.lvl");

            //加載系統顏色
            //contourMap.FillForegroundColorMap.LoadFile(path + "Rainbow.clr");
            //contourMap.ApplyFillToLevels(1, 1, 0);

            //使用灰色
            //contourMap.Levels.AutoGenerate(contourMap.Grid.zMin,contourMap.Grid.zMax,10);

            for (int i = 0; i < contourMap.Levels.Count; i++)
            {
                contourMap.Levels.Item(i + 1).ShowLabel  = false;                               //顯示等值線上的數值
                contourMap.Levels.Item(i + 1).ShowHach   = false;                               //
                contourMap.Levels.Item(i + 1).Line.Style = "Invisible";                         //不顯示線
            }

            contourMap.SmoothContours = SrfConSmoothType.srfConSmoothNone;       //平滑等值線邊界當前設置不平滑
            #endregion


            #region 添加邊界
            //後添加的會覆蓋在先前添加的圖片之上
            IMapFrame boundryMapFrame = Shapes.AddBaseMap(path + "city.shp", "Defaults=1");
            for (int i = 1; i <= boundryMapFrame.Axes.Count; i++)
            {
                boundryMapFrame.Axes.Item(i).Visible       = false;                   //隱藏軸線
                boundryMapFrame.Axes.Item(i).MajorTickType = SrfTickType.srfTickNone; //隱藏邊線
                boundryMapFrame.Axes.Item(i).ShowLabels    = false;                   //隱藏軸線上的坐標
            }
            boundryMapFrame.SetLimits(xMin: 140000,                                   //x最小值
                                      xMax: 370000,                                   //x最大者
                                      yMin: 2400000,                                  //y最小值
                                      yMax: 2800000                                   //y最大值
                                      );
            boundryMapFrame.xMapPerPU = 23000;
            boundryMapFrame.yMapPerPU = 20000;

            IBaseMap boundryBaseMap = (IBaseMap)boundryMapFrame.Overlays.Item(1);
            boundryBaseMap.Line.Width = 0.001;                          //設置邊線寬度
            #endregion

            string strWH = string.Format("width = {0:f0}, height = {1:f0}, KeepAspect = 1, ColorDepth = 32", 680, 1280); //設置輸出圖片的高度和寬度
            Doc.Export2(path + "Image.png", SelectionOnly: false, Options: strWH, FilterId: "png");                      //設置輸出圖片格式名
            Doc.Close(SrfSaveTypes.srfSaveChangesNo);                                                                    //不生成srf文件
            app.Quit();
            System.GC.Collect(System.GC.GetGeneration(app));
        }
Exemple #2
0
        private void DatToGrid(string algorithmText)
        {
            //determine algorithm
            Surfer.SrfGridAlgorithm algorithm = new Surfer.SrfGridAlgorithm();
            switch (algorithmText)
            {
            case "InverseDistance":
                algorithm = Surfer.SrfGridAlgorithm.srfInverseDistance;
                break;

            case "Kriging":
                algorithm = Surfer.SrfGridAlgorithm.srfKriging;
                break;

            case "LocalPolynomial":
                algorithm = Surfer.SrfGridAlgorithm.srfLocalPolynomial;
                break;

            case "MinCurvature":
                algorithm = Surfer.SrfGridAlgorithm.srfMinCurvature;
                break;

            case "MovingAverage":
                algorithm = Surfer.SrfGridAlgorithm.srfMovingAverage;
                break;

            case "NaturalNeighbor":
                algorithm = Surfer.SrfGridAlgorithm.srfNaturalNeighbor;
                break;

            case "NearestNeighbor":
                algorithm = Surfer.SrfGridAlgorithm.srfNearestNeighbor;
                break;

            case "RadialBasis":
                algorithm = Surfer.SrfGridAlgorithm.srfRadialBasis;
                break;

            case "Regression":
                algorithm = Surfer.SrfGridAlgorithm.srfRegression;
                break;

            case "Shepards":
                algorithm = Surfer.SrfGridAlgorithm.srfShepards;
                break;

            case "Triangulation":
                algorithm = Surfer.SrfGridAlgorithm.srfTriangulation;
                break;
            }
            Surfer.Application app = new Surfer.Application();
            app.GridData2(DataFile: path + "temp.dat",                   //数据文件地址
                          xCol: 1,                                       //x为第一列数据
                          yCol: 2,                                       //y为第二列数据
                          zCol: 3,                                       //z为第三列数据
                          DupMethod: Surfer.SrfDupMethod.srfDupNone,
                          xMin: 140000,                                  //x最小值
                          xMax: 370000,                                  //x最大者
                          yMin: 2400000,                                 //y最小值
                          yMax: 2800000,                                 //y最大值
                          Algorithm: algorithm,                          //插值算法
                          NumCols: 39,                                   //x方向插值数据量
                          NumRows: 100,                                  //y方向插值数据量
                          OutGrid: path + "temp.grd",                    //返回文件为gridfile
                          OutFmt: Surfer.SrfGridFormat.srfGridFmtAscii); //返回文件编码为Ascii
            app.Quit();
            System.GC.Collect(System.GC.GetGeneration(app));
        }