Ejemplo n.º 1
0
        /*
         * private void classification_Click(object sender, EventArgs e)
         * {
         *  //获取参数
         *  int ClassNums = int.Parse(textBox2.Text);
         *  int SampleStep = int.Parse(textBox3.Text);
         *  int MaxLoopCount =int.Parse(textBox4.Text) ;
         *  double MoveThrs = double.Parse(textBox5.Text);
         *  //int MinCellNums = int.Parse(textBox9.Text);
         *  int MinCellNums = Convert.ToInt32(double.Parse(textBox9.Text) * width * height);
         *  double MaxStd = double.Parse(textBox8.Text);
         *  int MaxLumpNums = int.Parse(textBox7.Text);
         *  double MinInterClassDist = double.Parse(textBox6.Text);
         *  string DstRasURL = textBox1.Text;
         *  int RBand = int.Parse(System.Text.RegularExpressions.Regex.Replace(RBandCmb.Text, @"[^0-9]+", ""));
         *  int GBand = int.Parse(System.Text.RegularExpressions.Regex.Replace(GBandCmb.Text, @"[^0-9]+", ""));
         *  int BBand = int.Parse(System.Text.RegularExpressions.Regex.Replace(BBandCmb.Text, @"[^0-9]+", ""));
         *
         *  selectBands[0] = RBand;
         *  selectBands[1] = GBand;
         *  selectBands[2] = BBand;
         *
         *  if (selectRasterCmb.Items.Contains(textBox1.Text))
         *  {
         *      MessageBox.Show("该文件已存在!请重新输入文件名。");
         *      textBox1.Text = "";
         *      return;
         *  }
         *
         *
         *  rds = themeLayer.GetData() as RasterDataSet;
         *  //MessageBox.Show(rds.ClsName);
         *  //构建栅格分类器
         *  RasClass rc = new RasClass();
         *  //设置待分类影像
         *  rc.SetData(rds);
         *  //设置处理范围
         *  rc.SetCommonParam(selectBands,0,0,height,width);
         *  //设置分类结果URL
         *  DstRasURL = "GDBP://MapGisLocal/" + selectDBCmb.Text + "/ras/"+ textBox1.Text;
         *  //调用分类器
         *  //监督分类:最大似然法
         *  int i = rc.RsMaxLiklihoodSupervisedClassification(0.1, DstRasURL);
         *  //非监督分类:ISODATA
         *  //int i = rc.RsIsoClusterUnsupervisedClassification(ClassNums, MaxStd, MaxLoopCount, MoveThrs, MinInterClassDist, MinCellNums, MaxLumpNums, SampleStep, DstRasURL);
         *  selectRasterCmb.Items.Add(textBox1.Text);
         *
         *
         *  if (i == 1) {
         *      MessageBox.Show("分类成功!");
         *      //将分类结果展示到界面上
         *      rds.Open(textBox1.Text, 0);
         *      Map map = new Map();
         *      themeLayer = new RasterLayer();
         *
         *      if (rds != null)
         *          themeLayer.AttachData(rds);
         *
         *      map.Append(themeLayer);
         *      this.mapControl.ActiveMap = map;
         *      mapControl.Refresh();
         *
         *      //获取分类结果
         *      after_cls_rds.OpenByURL(DstRasURL, RasAccessType.RasAccessType_Update);
         *      //如果是监督分类,需要给结果集设置AOI;
         *      //after_cls_rds.SetAOIs((AOIPloygon[])rds.GetAOIs().Clone());
         *      after_cls_rds = setaoi(rds, after_cls_rds);
         *      MessageBox.Show("分类结果的aoi有:"+after_cls_rds.GetAOIs().Length.ToString());
         *      //分类结果精度评定
         *      RasClassificationAnalyse rca = new RasClassificationAnalyse();
         *      //设置待评价影像(分类结果)
         *      rca.SetData(after_cls_rds,after_cls_rds.BandCount);
         *      //设置处理范围
         *      rca.SetCommonParam(0, 0, height, width);
         *
         *      int j = rca.RsClassificationAccuracyAnalyse(rds, true, true, true, true, "classifaction_ana1.txt");
         *      MessageBox.Show("精度评定" + j.ToString());
         *  }
         *  else{
         *      MessageBox.Show("分类失败");
         *  }
         * }
         */
        private RasterDataSet setaoi(RasterDataSet oldrds, RasterDataSet newrds)
        {
            //设置AOI信息
            AOIPloygon[] oldaois = oldrds.GetAOIs();
            AOIPloygon[] newaois = newrds.GetAOIs();
            AOIPloygon   aoi     = new AOIPloygon();

            for (int i = 0; i < oldaois.Length; i++)
            {
                newaois[i].R = oldaois[i].R;
                newaois[i].G = oldaois[i].G;
                newaois[i].B = oldaois[i].B;
            }
            bool flag = newrds.SetAOIs(newaois);

            if (flag)
            {
                MessageBox.Show("AOI信息设置成功");
                return(newrds);
            }
            else
            {
                MessageBox.Show("AOI信息设置失败");
                return(null);
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //获取参数
            int    ClassNums         = int.Parse(this.ClassNums.Text);
            int    SampleStep        = int.Parse(this.SampleStep.Text);
            int    MaxLoopCount      = int.Parse(this.MaxLoopCount.Text);
            double MoveThrs          = double.Parse(this.MoveThrs.Text);
            int    MinCellNums       = Convert.ToInt32(double.Parse(this.MinCellNums.Text) * form.width * form.height);
            double MaxStd            = double.Parse(this.MaxStd.Text);
            int    MaxLumpNums       = int.Parse(this.MaxLumpNums.Text);
            double MinInterClassDist = double.Parse(this.MinInterClassDist.Text);
            string DstRasURL         = "GDBP://MapGisLocal/" + form.selectDBCmb.Text + "/ras/" + this.DstRasURL.Text;



            //获取待分类影像
            RasterDataSet rds = form.themeLayer.GetData() as RasterDataSet;

            //获取波段信息
            int[] selectBands = new int[rds.BandCount];
            for (int n = 1; n <= rds.BandCount; n++)
            {
                selectBands[n - 1] = n;
            }

            //构建栅格分类器
            RasClass rc = new RasClass();

            //设置待分类影像
            rc.SetData(rds);
            //设置处理范围
            rc.SetCommonParam(selectBands, 0, 0, form.height, form.width);
            //调用分类器
            //非监督分类:ISODATA
            int i = rc.RsIsoClusterUnsupervisedClassification(ClassNums, MaxStd, MaxLoopCount, MoveThrs, MinInterClassDist, MinCellNums, MaxLumpNums, SampleStep, DstRasURL);

            if (i == 1)
            {
                MessageBox.Show("分类成功!");
                //将分类结果展示到界面上
                rds.Open(DstRasURL, 0);
                //添加分类影像到数据库
                form.selectRasterCmb.Text = this.DstRasURL.Text;
                Map map = new Map();
                form.themeLayer = new RasterLayer();

                if (rds != null)
                {
                    form.themeLayer.AttachData(rds);
                }

                map.Append(form.themeLayer);
                form.mapControl.ActiveMap = map;
                form.mapControl.Refresh();
                this.Close();
            }
            else
            {
                MessageBox.Show("分类失败!");
            }
        }
        private void button_Click(object sender, EventArgs e)
        {
            //获取参数
            //原始图像路径
            string OriRasURL = "GDBP://MapGisLocal/" + selectDBCmb1.Text + "/ras/" + selectRasterCmb1.Text;
            //分类图像路径
            string ClsRasURL = "GDBP://MapGisLocal/" + selectDBCmb2.Text + "/ras/" + selectRasterCmb2.Text;
            //评价结果路径
            string result = resultPath.Text;

            //统计参数
            bool ErrMatrix = false;
            bool ClsAccu   = false;
            bool TtlAccu   = false;
            bool Kappa     = false;

            if (this.ErrMatrix.Checked == true)
            {
                ErrMatrix = true;
            }
            if (this.ClsAccu.Checked == true)
            {
                ClsAccu = true;
            }
            if (this.TtlAccu.Checked == true)
            {
                TtlAccu = true;
            }
            if (this.Kappa.Checked == true)
            {
                Kappa = true;
            }


            RasterDataSet ori_rds = new RasterDataSet();
            RasterDataSet cls_rds = new RasterDataSet();

            ori_rds.OpenByURL(OriRasURL, RasAccessType.RasAccessType_Update);
            cls_rds.OpenByURL(ClsRasURL, RasAccessType.RasAccessType_Update);
            //显示图像信息
            height = cls_rds.GetPixelHeight();
            width  = cls_rds.GetPixelWidth();

            //生成评价器
            RasClassificationAnalyse rca = new RasClassificationAnalyse();

            //设置初始参数
            rca.SetData(cls_rds, cls_rds.BandCount);
            //设置处理范围
            rca.SetCommonParam(0, 0, height, width);
            //调用评价器
            int i = rca.RsClassificationAccuracyAnalyse(ori_rds, ErrMatrix, ClsAccu, TtlAccu, Kappa, result);

            if (i > 0)
            {
                MessageBox.Show("精度评价完成!");
            }
            else
            {
                MessageBox.Show("精度评价失败!");
            }
        }
Ejemplo n.º 4
0
        private void selectRasterCmb_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (selectDBCmb.Text == null || selectRasterCmb.Text == null)
            {
                return;
            }

            RBandCmb.Items.Clear();
            GBandCmb.Items.Clear();
            BBandCmb.Items.Clear();

            rds = new RasterDataSet(GDB);
            rds.Open(selectRasterCmb.Text, 0);

            //将波段添加到各个comoBox中
            for (int i = 0; i < rds.GetBandNum(); i++)
            {
                RasBand = rds.GetRasterBand(i + 1);
                RBandCmb.Items.Add("波段" + (i + 1));
                GBandCmb.Items.Add("波段" + (i + 1));
                BBandCmb.Items.Add("波段" + (i + 1));
            }



            //在地图空间中显示该图层
            Map map = new Map();

            themeLayer = new RasterLayer();

            if (rds != null)
            {
                themeLayer.AttachData(rds);
            }

            map.Append(themeLayer);
            this.mapControl.ActiveMap = map;
            this.mapControl.Restore();


            RBandCmb.Text = "";
            GBandCmb.Text = "";
            BBandCmb.Text = "";

            if (RBandCmb.Items.Count >= 3 && GBandCmb.Items.Count >= 3 && BBandCmb.Items.Count >= 3)
            {
                RBandCmb.Enabled = true;
                GBandCmb.Enabled = true;
                BBandCmb.Enabled = true;

                RBandCmb.SelectedIndex = 0;
                GBandCmb.SelectedIndex = 1;
                BBandCmb.SelectedIndex = 2;
            }
            else
            {
                RBandCmb.Enabled = false;
                GBandCmb.Enabled = false;
                BBandCmb.Enabled = false;
            }

            //显示图像信息
            height = rds.GetPixelHeight();
            width  = rds.GetPixelWidth();

            labelHeight.Text = height.ToString();
            labelWidth.Text  = Width.ToString();

            labelHeight.Visible = true;
            labelWidth.Visible  = true;

            //显示图像分辨率
            resolutionX = rds.GetResolutionX();
            resolutionY = rds.GetResolutionY();

            labelResolutionX.Text = resolutionX.ToString();
            labelResolutionY.Text = resolutionY.ToString();

            labelResolutionX.Visible = true;
            labelResolutionY.Visible = true;



            //给分类器设置参数

            /*
             * textBox2.Text = "4";
             * textBox3.Text = "16";
             * textBox4.Text = "20";
             * textBox5.Text = "0.01";
             * textBox9.Text = "0.005";
             * textBox8.Text = "9.8";
             * textBox7.Text = "5";
             * textBox6.Text = "6.4";
             */
        }
Ejemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            int[] selectBands = new int[3];

            //获取波段信息
            int RBand = int.Parse(System.Text.RegularExpressions.Regex.Replace(form.RBandCmb.Text, @"[^0-9]+", ""));
            int GBand = int.Parse(System.Text.RegularExpressions.Regex.Replace(form.GBandCmb.Text, @"[^0-9]+", ""));
            int BBand = int.Parse(System.Text.RegularExpressions.Regex.Replace(form.BBandCmb.Text, @"[^0-9]+", ""));

            selectBands[0] = RBand;
            selectBands[1] = GBand;
            selectBands[2] = BBand;

            double minProbability = 0;

            //获取参数
            try
            {
                minProbability = double.Parse(this.minProb.Text);
            }
            catch (Exception ex) {
                MessageBox.Show("参数“最小概率”输入非法");
                return;
            }
            string DstRasURL = "GDBP://MapGisLocal/" + form.selectDBCmb.Text + "/ras/" + distanceURL.Text;

            //MessageBox.Show(DstRasURL);
            if (form.selectRasterCmb.Items.Contains(distanceURL.Text))
            {
                MessageBox.Show("该文件已存在!请重新输入文件名。");
                distanceURL.Text = "";
                return;
            }

            //获取待分类影像
            RasterDataSet rds = form.themeLayer.GetData() as RasterDataSet;

            //构建栅格分类器
            RasClass rc = new RasClass();

            //设置待分类影像
            rc.SetData(rds);
            //设置处理范围
            rc.SetCommonParam(selectBands, 0, 0, form.height, form.width);
            //调用分类器
            //监督分类:最大似然法
            int i = rc.RsMaxLiklihoodSupervisedClassification(minProbability, DstRasURL);

            form.selectRasterCmb.Items.Add(distanceURL.Text);

            if (i == 1)
            {
                MessageBox.Show("分类成功!");
                //将分类结果展示到界面上
                rds.Open(distanceURL.Text, 0);
                //添加分类影像到数据库
                form.selectRasterCmb.Text = distanceURL.Text;
                Map map = new Map();
                form.themeLayer = new RasterLayer();

                if (rds != null)
                {
                    form.themeLayer.AttachData(rds);
                }

                map.Append(form.themeLayer);
                form.mapControl.ActiveMap = map;
                form.mapControl.Refresh();
                this.Close();
            }
            else
            {
                MessageBox.Show("分类失败!");
            }
        }