Пример #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);
        }
Пример #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("============反演结束============");
            }
        }