Exemplo n.º 1
0
        //计算相关性
        private void btn_Calculate_Click(object sender, EventArgs e)
        {
            string imgPath       = this.txb_inputImg.Text;
            string shapefileName = this.cmb_QualityList.SelectedValue.ToString();

            List <string> waterFieldList = new List <string>();

            if (this.checkBox_COD.Checked)
            {
                waterFieldList.Add("CODmn");
            }
            if (checkBox_NH4N.Checked)
            {
                waterFieldList.Add("NH4_N");
            }
            if (checkBox_TN.Checked)
            {
                waterFieldList.Add("TN");
            }
            if (checkBox_TP.Checked)
            {
                waterFieldList.Add("TP");
            }
            //获取栅格数据集
            IRasterDataset pRasterDataset = GetDataClass.GetRasterDataset(imgPath);
            //获取矢量要素
            IFeatureClass pFeatureClass = GetDataClass.GetFeatureClassByName(shapefileName);
            //计算相关系数
            InversionClass pInversionClass = new InversionClass(this.richtxb_result);

            pInversionClass.CalculateRelativityInit(pFeatureClass, pRasterDataset, waterFieldList);
        }
Exemplo n.º 2
0
        //计算回归模型
        private void btn_Calculate_Click(object sender, EventArgs e)
        {
            //输入影像
            IRasterDataset pRasterDataset = GetDataClass.GetRasterDataset(this.txb_inputImg.Text);

            if (pRasterDataset == null)
            {
                MessageBox.Show("输入影像数据不能为空!");
                return;
            }
            //水质期数
            IFeatureClass pFeatureClass = GetDataClass.GetFeatureClassByName(this.cmb_QualityList.SelectedValue.ToString());

            if (pFeatureClass == null)
            {
                MessageBox.Show("选择矢量数据不能为空!");
                return;
            }
            //反演字段
            string        selectWaterField = _waterFieldsDictionary[GetSelectRadText(gb_waterFields)];
            List <string> fieldsList       = new List <string>()
            {
                selectWaterField
            };
            //获取水质数据和全部影像波段数据
            InversionClass inversionClass = new InversionClass(this.richtxb_info);

            double[][] imgDataArray = inversionClass.GetImgCellValue(pFeatureClass, pRasterDataset);
            Dictionary <string, double[]> waterDataDictionary = inversionClass.GetQualityByFields(pFeatureClass, fieldsList);

            //获取需要反演的水质参数
            double[] selectWaterData = waterDataDictionary[selectWaterField];
            //获取选择的波段组合数据
            double[][] selectBandsCombData = GetSelectBandData(imgDataArray);
            //获取选择的反演方法
            string regressionMethod = GetSelectRadText(gb_regressionMethod);


            if (regressionMethod == "一元线性")
            {
                AddInfoToRichTextBox("============开始反演============");
                AddInfoToRichTextBox("反演波段为:" + selectWaterField);
                AddInfoToRichTextBox("反演方法为一元线性,回归模型为Y=b+a*X");
                int bandCombCount = selectBandsCombData.Length;
                for (int i = 0; i < bandCombCount; i++)
                {
                    double[] resultDoubles = RegressionClass.SimpleLinearRegression(selectBandsCombData[i],
                                                                                    selectWaterData);
                    AddInfoToRichTextBox(string.Format("{0}:自变量为{1}", i + 1, _bandCombList[i]));
                    AddInfoToRichTextBox(string.Format("{0,7}{1,7}{2,7}{3,7}{4,7}{5,7}{6,7}{7,7}", "回归系数b", "回归系数a",
                                                       "偏差平方和", "平均标准偏差", "回归平方和", "最大偏差", "最小偏差", "偏差平均值"));
                    AddInfoToRichTextBox(string.Format("{0,10}{1,10}{2,11}{3,11}{4,12}{5,13}{6,12}{7,12}",
                                                       resultDoubles[0].ToString("0.###"), resultDoubles[1].ToString("0.###"),
                                                       resultDoubles[2].ToString("0.###"), resultDoubles[3].ToString("0.###"),
                                                       resultDoubles[4].ToString("0.###"), resultDoubles[5].ToString("0.###"),
                                                       resultDoubles[6].ToString("0.###"), resultDoubles[7].ToString("0.###")));
                }
                AddInfoToRichTextBox("============反演结束============\n");
            }
            else if (regressionMethod == "多元线性")
            {
                AddInfoToRichTextBox("============开始反演============");
                //获取反演结果
                List <double[]> resultList = RegressionClass.MultiLinearRegression(selectBandsCombData, selectWaterData);
                //输出
                AddInfoToRichTextBox("反演波段为:" + selectWaterField);
                AddInfoToRichTextBox("反演方法为多元线性,回归模型为:");
                StringBuilder strBuilder1 = new StringBuilder();
                strBuilder1.Append("Y=");
                int bandComCount = _bandCombList.Count;
                for (int i = 0; i < bandComCount; i++)
                {
                    strBuilder1.AppendFormat("a{0}*{1}+", i, _bandCombList[i]);
                }
                strBuilder1.AppendFormat("a{0}", bandComCount);
                AddInfoToRichTextBox(strBuilder1.ToString());
                //模型参数
                double[] a = resultList[0];
                AddInfoToRichTextBox(string.Format("模型参数a0到a{0}分别为:", bandComCount));
                StringBuilder strbBuilder = new StringBuilder();
                int           alength     = a.Length;
                for (int i = 0; i < alength; i++)
                {
                    strbBuilder.Append(a[i].ToString("0.###") + "   ");
                }
                AddInfoToRichTextBox(strbBuilder.ToString());
                //模型偏差
                AddInfoToRichTextBox("\n模型偏差:");
                double[] dt = resultList[1];
                AddInfoToRichTextBox(string.Format("{0,7}{1,7}{2,7}{3,7}", "偏差平方和", "平均标准偏差", "相关系数", "回归平方和"));
                AddInfoToRichTextBox(string.Format("{0,10}{1,10}{2,14}{3,12}", dt[0].ToString("0.###"),
                                                   dt[1].ToString("0.###"), dt[2].ToString("0.###"), dt[3].ToString("0.###")));
                AddInfoToRichTextBox("============反演结束============");
            }
        }
Exemplo n.º 3
0
        //插值
        private void btn_interpolation_Click(object sender, EventArgs e)
        {
            this.label_fun.Text = "";
            //获取加密点矢量
            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
            IWorkspace        pWorkspace        = pWorkspaceFactory.OpenFromFile(@"D:\RasterMaSysTemp\hhData", 0);
            IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
            IFeatureClass     pFeatureClass     = pFeatureWorkspace.OpenFeatureClass("加密点.shp");
            //获取栅格波段
            IRasterDataset pRasterDataset = GetDataClass.GetRasterDataset(this.txb_inputImg.Text);
            InversionClass inversionClass = new InversionClass(new RichTextBox());

            double[][] imgAllBands = inversionClass.GetImgCellValue(pFeatureClass, pRasterDataset);

            //所有波段组合的值
            Dictionary <string, double[]> imgBandscomb = calculateBandscomb(imgAllBands);

            string selectMethod     = this.GetSelectRadText(gb_regressionMethod);
            string selectFieldRad   = this.GetSelectRadText(gb_waterFields);
            string selectWaterField = _waterFieldsDictionary[selectFieldRad];

            _labelFun = string.Format("回归拟合方程为:{0}=", selectWaterField);
            //获取结果值
            if (selectMethod == "二次模型" || selectMethod == "指数模型")
            {
                MessageBox.Show("请选择其他拟合算法");
                return;
            }
            List <double> resultList = this.GetResultValue(imgBandscomb, selectMethod, imgAllBands[0].Length);

            //显示拟合函数
            this.label_fun.Text += _labelFun;

            //更新加密点属性
            if (resultList.Count == 0)
            {
                MessageBox.Show("获取数据失败");
                return;
            }
            this.UpdatePointValue(pFeatureClass, selectWaterField, resultList);

            //插值
            if (this.txb_output.Text.Trim() != "")
            {
                GpToolsClass gpTools = new GpToolsClass();
                gpTools.CalKriging(selectWaterField, this.txb_output.Text);
            }
            //如果生成插值图成功,则添加显示
            if (File.Exists(this.txb_output.Text))
            {
                if (File.Exists(@"D:\RasterMaSysTemp\hhData\水质插值专题图.mxd"))
                {
                    MapDocument mapDoc = new MapDocumentClass();
                    mapDoc.Open(@"D:\RasterMaSysTemp\hhData\水质插值专题图.mxd", "");
                    axPageLayoutControl1.PageLayout = mapDoc.PageLayout;

                    IMap         pMap         = mapDoc.get_Map(0);
                    IRasterLayer pRasterLayer = pMap.Layer[0] as IRasterLayer;
                    pRasterLayer.CreateFromFilePath(this.txb_output.Text);
                    axPageLayoutControl1.PageLayout.ZoomToWhole();
                    IPage page = axPageLayoutControl1.Page;
                    axPageLayoutControl1.Refresh();
                }
                else
                {
                    IMap         pMap         = this.axPageLayoutControl1.ActiveView.FocusMap;
                    IRasterLayer pRasterLayer = new RasterLayerClass();
                    pRasterLayer.CreateFromFilePath(this.txb_output.Text);
                    pMap.AddLayer(pRasterLayer);
                }
            }
            else
            {
                MessageBox.Show("处理失败!");
            }
        }