コード例 #1
0
        public void Init()
        {
            try
            {
                //根据选择的矢量文件的路径打开工作空间
                string   fileN    = panImage;
                FileInfo fileInfo = new FileInfo(fileN);
                string   filePath = fileInfo.DirectoryName;
                string   fileName = fileInfo.Name;

                IWorkspaceFactory wsf        = new RasterWorkspaceFactory();
                IWorkspace        wp         = wsf.OpenFromFile(filePath, 0);
                IRasterWorkspace  rw         = (IRasterWorkspace)wp;
                IRasterDataset    panDataset = rw.OpenRasterDataset(fileName);

                IRaster2       multiRaster2 = m_raster as IRaster2;
                IRasterDataset multiDataset = multiRaster2.RasterDataset;
                //默认波段顺序,RGB和近红外
                //创建全色和多光谱栅格数据集的full栅格对象
                IRaster panRaster   = ((IRasterDataset2)panDataset).CreateFullRaster();
                IRaster multiRaster = ((IRasterDataset2)multiDataset).CreateFullRaster();
                //设置红外波段
                IRasterBandCollection rasterbandCol = (IRasterBandCollection)multiRaster;
                IRasterBandCollection infredRaster  = new RasterClass();
                infredRaster.AppendBand(rasterbandCol.Item(3));

                //设置全色波段的属性
                IRasterProps panSharpenRasterProps = (IRasterProps)multiRaster;
                IRasterProps panRasterProps        = (IRasterProps)panRaster;
                panSharpenRasterProps.Width  = panRasterProps.Width;
                panSharpenRasterProps.Height = panRasterProps.Height;
                panSharpenRasterProps.Extent = panRasterProps.Extent;
                multiRaster.ResampleMethod   = rstResamplingTypes.RSP_BilinearInterpolationPlus;

                //创建全色锐化过滤器和设置其参数
                IPansharpeningFilter pansharpenFilter = new PansharpeningFilterClass();
                pansharpenFilter.InfraredImage     = (IRaster)infredRaster;
                pansharpenFilter.PanImage          = (IRaster)panRaster;
                pansharpenFilter.PansharpeningType = esriPansharpeningType.esriPansharpeningESRI;
                pansharpenFilter.PutWeights(red, green, blue, infra);

                //将全色锐化过滤器设置于多光谱栅格对象上
                IPixelOperation pixeOperation = (IPixelOperation)multiRaster;
                pixeOperation.PixelFilter = (IPixelFilter)pansharpenFilter;

                //保存结果数据集,并加载显示
                //加载显示裁剪结果图像

                /*IRasterLayer panSharpenLayer = new RasterLayerClass();
                 * panSharpenLayer.CreateFromRaster(multiRaster);
                 * panSharpenLayer.Name = "panSharpen_Result";
                 * panSharpenLayer.SpatialReference = ((IGeoDataset)multiRaster).SpatialReference;
                 * return panSharpenLayer;*/
                m_raster = multiRaster;
            }
            catch (System.Exception ex)//异常处理,输出错误信息
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        public void btnExecute_Click(object sender, EventArgs e)
        {
            string tblNm = txtOutNm.Text;

            if (tblNm == null || tblNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (lsbRaster.Items.Count < 1)
            {
                MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRasterBandCollection rsBc = new RasterClass();

            for (int i = 0; i < lsbRaster.Items.Count; i++)
            {
                rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]);
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Building Raster Attribute Table. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                string                 outDbStr = geoUtil.getDatabasePath(tblNm);
                string                 outName  = System.IO.Path.GetFileNameWithoutExtension(tblNm);
                IWorkspace             wks      = geoUtil.OpenWorkSpace(outDbStr);
                IFunctionRasterDataset fDset    = rsUtil.compositeBandFunction(rsBc);
                outtbl            = rsUtil.calcCombinRasterFunctionTable(fDset, wks, outName);
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished creating attribute table");
                rp.enableClose();
                this.Close();
            }
        }
コード例 #3
0
        private IFunctionRasterDataset transform()
        {
            IRasterBandCollection rsBc = new RasterClass();

            for (int i = 0; i < coef.Length; i++)
            {
                double[] c                 = coef[i];
                double   intercept         = c[0];
                double   slope             = c[1];
                IFunctionRasterDataset tRs = rsUtil.getBand(transformRaster, i);
                IFunctionRasterDataset pRs = rsUtil.calcArithmaticFunction(tRs, slope, esriRasterArithmeticOperation.esriRasterMultiply);
                IFunctionRasterDataset fRs = rsUtil.calcArithmaticFunction(pRs, intercept, esriRasterArithmeticOperation.esriRasterPlus);
                IFunctionRasterDataset bRs = rsUtil.convertToDifFormatFunction(fRs, rsType);
                rsBc.AppendBand(((IRasterBandCollection)bRs).Item(0));
            }
            OutRaster = rsUtil.compositeBandFunction(rsBc);
            return(OutRaster);
        }
コード例 #4
0
 private void buttonXOK_Click(object sender, EventArgs e)
 {
     try
     {
         string           dempath     = m_DEMPath;
         IRaster          raster      = new RasterClass();
         RasterLayerClass rasterlayer = new RasterLayerClass();
         rasterlayer.CreateFromFilePath(dempath);
         IRaster iRaster     = rasterlayer.Raster;
         string  tinFileName = m_TINPath;
         DEMToTIN(iRaster, tinFileName);
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
         return;
     }
 }
        public void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm = txtOutNm.Text;
            if (rstNm == null || rstNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (lsbRaster.Items.Count < 1)
            {
                MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRasterBandCollection rsBc = new RasterClass();
            for (int i = 0; i < lsbRaster.Items.Count; i++)
            {
                rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]);

            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;
            rp.addMessage("Building " + mStr + " Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                if (this.Text == "Create Composite Raster")
                {
                    outraster = rsUtil.createRaster(rsUtil.compositeBandFunction(rsBc));
                }
                else
                {

                    outraster = rsUtil.createRaster(rsUtil.calcCombineRasterFunction(rsBc));
                }
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts = dt2.Subtract(dt);
                string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished " + mStr + " Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
 private void btnExecute_Click(object sender, EventArgs e)
 {
     string rstNm = txtOutNm.Text;
     string funNm = cmbFunction.Text;
     int before = System.Convert.ToInt32(nudBefore.Value);
     int after = System.Convert.ToInt32(nudAfter.Value);
     if (rstNm == null || rstNm == "")
     {
         MessageBox.Show("You must specify a output name","No Output",MessageBoxButtons.OK,MessageBoxIcon.Error);
         return;
     }
     if (lsbRaster.Items.Count < 1)
     {
         MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if ( funNm==null||funNm=="")
     {
         MessageBox.Show("You must select at least on function", "No Function Selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     IRasterBandCollection rsBc = new RasterClass();
     for (int i = 0; i < lsbRaster.Items.Count; i++)
     {
         rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]);
     }
     IFunctionRasterDataset fdset = rsUtil.compositeBandFunction(rsBc);
     rasterUtil.localType op = (rasterUtil.localType)Enum.Parse(typeof(rasterUtil.localType),funNm);
     this.Visible = false;
     esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
     DateTime dt = DateTime.Now;
     rp.addMessage("Calculating raster values. This may take a while...");
     rp.stepPGBar(10);
     rp.TopMost = true;
     rp.Show();
     try
     {
         outraster = rsUtil.focalBandfunction(fdset,op,before,after);
         //rp.addMessage("Number of bands = " + ((IRasterBandCollection)outraster).Count);
         if (mp != null&&addToMap)
         {
             rp.addMessage("Calculating Statistics...");
             rp.Refresh();
             IRasterLayer rstLyr = new RasterLayerClass();
             //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
             rstLyr.CreateFromDataset((IRasterDataset)outraster);
             rstLyr.Name = rstNm;
             rstLyr.Visible = false;
             mp.AddLayer(rstLyr);
         }
         outrastername = rstNm;
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         rp.addMessage(ex.ToString());
     }
     finally
     {
         DateTime dt2 = DateTime.Now;
         TimeSpan ts = dt2.Subtract(dt);
         string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
         rp.stepPGBar(100);
         rp.addMessage("Finished Creating Rasters" + t);
         rp.enableClose();
         this.Close();
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            string ftrNm = cmbSampleFeatureClass.Text;
            if (ftrNm == "" || ftrNm == null)
            {
                MessageBox.Show("You must have a sampling layer selected");
                return;
            }
            if (!System.IO.File.Exists(plrR.SasOutputFile))
            {
                MessageBox.Show("Could not find the sas estimate file. You either needed to first create the classificaiton model or select a feature dataset that has been used to create the model!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int paramLength = plrR.OutParameters.Length;
            int rsBndsCnt = lstRasterBands.Items.Count;
            int bCnt = 0;
            for (int i = 0; i < rsBndsCnt; i++)
            {
                bCnt = bCnt + ((IRasterBandCollection)rstDic[lstRasterBands.Items[i].ToString()]).Count;
            }
            if (bCnt < 1||(paramLength-1)!=bCnt)
            {
                MessageBox.Show("Param = " + (paramLength-1).ToString() + " BandCount = " + bCnt.ToString() + "\nYou must have the same number of rasters selected in the same order as parameter estimates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnViewOrder.PerformClick();
                return;

            }
            IRasterBandCollection rsBc = new RasterClass();
            for (int i = 0; i < rsBndsCnt; i++)
            {
                IRaster rs = rstDic[lstRasterBands.Items[i].ToString()];
                rsBc.AppendBands((IRasterBandCollection)rs);
            }
            this.Visible = false;
            plrR.InRaster = (IRaster)rsBc;

            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new esriUtil.Forms.RunningProcess.frmRunningProcessDialog(false);
            System.DateTime dt1 = System.DateTime.Now;
            rp.addMessage("Creating PLR Classification Raster.");
            rp.addMessage("Bands are organized as follows:\n\tBand1=MLC\n\tBand2=BaseCategory");
            int bcCnt = 3;
            foreach (string c in plrR.Categories)
            {
                rp.addMessage("\tBand" + bcCnt.ToString() + "=" + c);
                bcCnt += 1;
            }
            rp.addMessage("This may take some time...");
            rp.Show();
            rp.TopMost = true;
            rp.stepPGBar(20);
            rp.Refresh();
            IRaster rst = plrR.createModelRaster(seed);
            if (mp != null)
            {
                rp.addMessage("Adding Raster to map");
                rp.Refresh();
                IRasterLayer rsLyr1 = new RasterLayerClass();
                rsLyr1.CreateFromRaster(rst);
                rsLyr1.Name = "PLR_OUT";
                rsLyr1.Visible = false;
                mp.AddLayer(rsLyr1);
            }
            rp.stepPGBar(50);
            rp.addMessage("Finished creating raster");
            rp.Refresh();
            System.DateTime dt2 = System.DateTime.Now;
            System.TimeSpan ts = dt2.Subtract(dt1);
            string prcTime = "Time to complete process:\n" + ts.Days.ToString() + " Days " + ts.Hours.ToString() + " Hours " + ts.Minutes.ToString() + " Minutes " + ts.Seconds.ToString() + " Seconds ";
            rp.addMessage(prcTime);
            rp.stepPGBar(100);
            rp.Refresh();
            rp.enableClose();
            this.Close();
            return;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string ftrNm = cmbSampleFeatureClass.Text;
            string sasDir = cmbModelDir.Text;
            if (ftrNm == "" || ftrNm == null)
            {
                MessageBox.Show("You must have a Workspace selected");
                return;
            }
            if (sasDir == "" || sasDir == null)
            {
                MessageBox.Show("You must have a SAS modeled directory selected");
                return;
            }
            if (!System.IO.File.Exists(rR.SasOutputFile))
            {
                MessageBox.Show("Could not find the sas estimate file. You either needed to first create the classificaiton model or select a feature dataset that has been used to create the model!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int paramLength = rR.OutParameters.Length;
            int rsBndsCnt = lstRasterBands.Items.Count;
            int bCnt = 0;
            for (int i = 0; i < rsBndsCnt; i++)
            {
                bCnt = bCnt + ((IRasterBandCollection)rstDic[lstRasterBands.Items[i].ToString()]).Count;
            }
            if (bCnt < 1 || (paramLength - 1) != bCnt)
            {
                MessageBox.Show("Param = " + (paramLength - 1).ToString() + " BandCount = " + bCnt.ToString() + "\nYou must have the same number of rasters selected in the same order as parameter estimates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnViewOrder.PerformClick();
                return;

            }
            IRasterBandCollection rsBc = new RasterClass();
            for (int i = 0; i < rsBndsCnt; i++)
            {
                IRaster rs = rstDic[lstRasterBands.Items[i].ToString()];
                rsBc.AppendBands((IRasterBandCollection)rs);
            }
            this.Visible = false;
            rR.InRaster = (IRaster)rsBc;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new esriUtil.Forms.RunningProcess.frmRunningProcessDialog(false);
            System.DateTime dt1 = System.DateTime.Now;
            rp.addMessage("Creating Regression Raster.");
            rp.addMessage("Name of the out raster = " + sasDir + ". Bands are in the order of dependent variables");
            int bcnt = 1;
            foreach (string s in rR.Categories)
            {
                rp.addMessage("\tBand_" + bcnt.ToString() + " = " + s);
                bcnt++;
            }
            rp.addMessage("This may take some time...");
            rp.Show();
            rp.TopMost = true;
            rp.stepPGBar(20);
            rp.Refresh();
            try
            {
                outraster = rR.createModelRaster();
                outrastername = sasDir;
                if (mp != null && addToMap)
                {
                    rp.addMessage("Adding Rasters to map");
                    rp.Refresh();
                    IRasterLayer rsLyr1 = new RasterLayerClass();
                    rsLyr1.Name = outrastername;
                    rsLyr1.CreateFromRaster(outraster);
                    rsLyr1.Visible = false;
                    mp.AddLayer(rsLyr1);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception exc)
            {
                rp.addMessage(exc.ToString());
            }
            finally
            {
                rp.stepPGBar(50);
                rp.addMessage("Finished creating raster");
                rp.Refresh();
                System.DateTime dt2 = System.DateTime.Now;
                System.TimeSpan ts = dt2.Subtract(dt1);
                string prcTime = "Time to complete process:\n" + ts.Days.ToString() + " Days " + ts.Hours.ToString() + " Hours " + ts.Minutes.ToString() + " Minutes " + ts.Seconds.ToString() + " Seconds ";
                rp.addMessage(prcTime);
                rp.stepPGBar(100);
                rp.Refresh();
                rp.enableClose();
                this.Close();
            }
            return;
        }
コード例 #9
0
ファイル: frmDLSSimulation.cs プロジェクト: lovelll/DQHP
        private void btnGenerateInputData_Click(object sender, EventArgs e)
        {
            //if (this.strProjectPath.Trim() == "")
            //    return;
            //if (this.cmbBoundary.Text.Trim() == "")
            //    return;
            //if (this.cmbRstraint.Text.Trim() == "")
            //    return;
            //if (this.txtParameter.Text.Trim() == "")
            //    return;
            if (lsbLayerLandUse.Items.Count == 0)
                return;
            //if (lsbLayerDriverFactor.Items.Count == 0)
            //    return;
            int iLanduseType = 5;

            ILayer pLayer = null;
            IRaster pRaster =new RasterClass();

            IGeoDataset pGdsMask = null;
            IGeoDataset pGdsRstraint = null;
            IGeoDataset pGdsLanduse = null;
            IGeoDataset pGdsDriverFactor = null;
            IRasterBandCollection pRasterBandColection=(new RasterClass()) as IRasterBandCollection;
            //try
            //{
                string sLyrMask = this.cmbBoundary.Text;

                //boundaty-->mask
                for (int i = 0; i < pMap.LayerCount; i++)
                {
                    ILayer pLyr = pMap.get_Layer(i);
                    if (pLyr is IRasterLayer)
                    {
                        if (pLyr.Name == sLyrMask)
                        {
                            pRaster = (pLyr as IRasterLayer).Raster;
                            pGdsMask = pRaster as IGeoDataset;
                        }
                    }
                }
                //data
                //限制区
                string sLyrRstraint = this.cmbBoundary.Text;
                //土地利用数据
                string sLyrLanduse = this.lsbLayerLandUse.Items[0].ToString();
                //驱动因子
                string[] arr = new string[this.lsbLayerDriverFactor.Items.Count];

                for (int i = 0; i < this.lsbLayerDriverFactor.Items.Count; i++)
                {
                    arr[i]=this.lsbLayerDriverFactor.Items[i].ToString();
                }

                for (int i = 0; i < pMap.LayerCount; i++)
                {
                    ILayer pLyr = pMap.get_Layer(i);
                    if (pLyr is IRasterLayer)
                    {
                        if (pLyr.Name == sLyrRstraint)
                        {
                            pRaster = (pLyr as IRasterLayer).Raster;
                            pGdsRstraint = pRaster as IGeoDataset;
                        }

                        //土地利用数据
                        if (pLyr.Name == sLyrLanduse)
                        {
                            this.rtxtState.AppendText("读取土地利用参数数据...\n");
                            this.rtxtState.ScrollToCaret();
                            pRaster = (pLyr as IRasterLayer).Raster;
                            pGdsLanduse = pRaster as IGeoDataset;
                            //land use 添加到 IRasterBandCollection
                            pRasterBandColection=pRaster as IRasterBandCollection;
                            //pRasterBandColection.AppendBand(pRaster as IRasterBand);

                            string ascFileNameLanduse = strProjectPath + "\\cov1_all.0";
                            //cov1_0.0;cov1_1.0;
                            Rater2Ascii(pGdsMask, 100, pGdsLanduse, ascFileNameLanduse);

                            //将土地利用数据拆分

                            StreamReader sr = new StreamReader(ascFileNameLanduse, System.Text.Encoding.Default);
                            //try
                            //{

                            //使用StreamReader类来读取文件
                            sr.BaseStream.Seek(0, SeekOrigin.Begin);
                            // 从数据流中读取每一行,直到文件的最后一行,并在richTextBox1中显示出内容
                            //读取头文件
                            string[] header = new string[6];

                            for (int j = 0; j < 6; j++)
                            {
                                header[j] = sr.ReadLine();
                            }
                            //行列数
                            string[] ncols = header[0].Split(' ');
                            string[] nrows = header[1].Split(' ');
                            int icol = int.Parse(ncols[ncols.Length - 1]);
                            int irow = int.Parse(nrows[nrows.Length - 1]);

                            int[,] iLanduse = new int[irow, icol];
                            //
                            string strLine = sr.ReadLine();
                            string[] strData;
                            int ir = 0;
                            while (ir < irow)
                            //while (strLine != null)
                            {
                                strData = strLine.Split(' ');
                                for (int ic = 0; ic < icol; ic++)
                                {
                                    iLanduse[ir, ic] = int.Parse(strData[ic]);
                                }
                                strLine = sr.ReadLine();
                                ir++;
                            }
                            //关闭此StreamReader对象
                            sr.Close();
                            //输出相应的土地利用数据
                            DataTable2Txt(header, iLanduseType, iLanduse, strProjectPath);

                            //}
                            //catch (Exception ex)
                            //{
                            //MessageBox.Show(ex.Message);
                            sr.Close();
                            //}
                        }
                    }
                }
                this.rtxtState.AppendText("输出土地利用参数数据成功。\n");
                this.rtxtState.AppendText("读取驱动因子数据...\n");
                this.rtxtState.ScrollToCaret();
                for (int ifac = 0; ifac < lsbLayerDriverFactor.Items.Count; ifac++)
                {
                    for (int i = 0; i < pMap.LayerCount; i++)
                    {
                        ILayer pLyr = pMap.get_Layer(i);
                        if (pLyr is IRasterLayer)
                        {
                        //输出驱动因子数据  sc1gr0.grid

                            string sFacName = lsbLayerDriverFactor.Items[ifac].ToString();
                            if (pLyr.Name == sFacName)
                            {
                                pRaster = (pLyr as IRasterLayer).Raster;
                                pGdsDriverFactor = pRaster as IGeoDataset;

                                string ascFileNameFac = strProjectPath + "\\sc1gr"+ifac.ToString()+".grid";
                                //cov1_0.0;cov1_1.0;
                                this.rtxtState.AppendText("输出驱动因子数据【" + sFacName + "】\n");
                                Rater2Ascii(pGdsMask, 100, pGdsDriverFactor, ascFileNameFac);
                                this.rtxtState.AppendText("输出驱动因子数据【" + sFacName + "】成功。\n");
                                this.rtxtState.ScrollToCaret();
                                //mask 添加到 IRasterBandCollection
                                IRasterBandCollection rasterbands = (IRasterBandCollection)pRaster;
                                IRasterBand rasterband = rasterbands.Item(0);
                                pRasterBandColection.AppendBand(rasterband);
                                //pRasterBandColection.Add(pRaster as IRasterBand,ifac+1);

                            }
                        }
                    }
                }
                this.rtxtState.AppendText("开始制备驱动因子参数...\n");
                this.rtxtState.ScrollToCaret();
                //sample data
                ITable itFactors=ExportSample(pGdsMask,pRasterBandColection);
                //logistic 回归分析
                DataTable dtFactors = ITable2DTable(itFactors);
                itFactors = null;

                //制备驱动力参数文件
                this.rtxtState.AppendText("读取驱动因子数据表格数据...\n");
                this.rtxtState.ScrollToCaret();
                LogisticRegressionAnalysis lra;
                // Gets the columns of the independent variables
                List<string> names = new List<string>();
                foreach (string name in lsbLayerDriverFactor.Items)
                    names.Add(name);

                String[] independentNames = names.ToArray();
                DataTable independent = dtFactors.DefaultView.ToTable(false, independentNames);
                // Creates the input and output matrices from the source data table
                double[][] input = independent.ToArray();
                double[,] sourceMatrix = dtFactors.ToMatrix(independentNames);

                for(int ild=0;ild<iLanduseType;ild++)
                {
                    String landuseName = (string)this.lsbLayerLandUse.Items[0].ToString();
                    this.rtxtState.AppendText("开始制备土地利用类型【" + ild.ToString() + "】驱动因子参数...\n");
                    this.rtxtState.ScrollToCaret();
                    DataColumn taxColumn =new DataColumn();
                    taxColumn.DataType = System.Type.GetType("System.Int32");
                    taxColumn.ColumnName ="sysland"+ild.ToString();//列名
                    taxColumn.Expression = "iif("+landuseName+" = "+ild.ToString()+",1,0)";//设置该列得表达式,用于计算列中的值或创建聚合列
                    dtFactors.Columns.Add(taxColumn);
                    string dependentName = "sysland" + ild.ToString();

                    DataTable dependent = dtFactors.DefaultView.ToTable(false, dependentName);
                    double[] output = dependent.Columns[dependentName].ToArray();

                    // Creates the Simple Descriptive Analysis of the given source
                    DescriptiveAnalysis sda = new DescriptiveAnalysis(sourceMatrix, independentNames);
                    sda.Compute();

                    // Populates statistics overview tab with analysis data
                    //dgvDistributionMeasures.DataSource = sda.Measures;

                    // Creates the Logistic Regression Analysis of the given source
                    lra = new LogisticRegressionAnalysis(input, output, independentNames, dependentName);

                    // Compute the Logistic Regression Analysis
                    lra.Compute();

                    // Populates coefficient overview with analysis data
                    //lra.Coefficients;
                    MessageBox.Show(lra.Coefficients.Count.ToString());

                    //// Populate details about the fitted model
                    //tbChiSquare.Text = lra.ChiSquare.Statistic.ToString("N5");
                    //tbPValue.Text = lra.ChiSquare.PValue.ToString("N5");
                    //checkBox1.Checked = lra.ChiSquare.Significant;
                    //tbDeviance.Text = lra.Deviance.ToString("N5");
                    //tbLogLikelihood.Text = lra.LogLikelihood.ToString("N5");
                }
                this.rtxtState.AppendText("制备驱动因子参数成功。\n");
                this.rtxtState.ScrollToCaret();
                MessageBox.Show(dtFactors.Rows.Count.ToString());
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);

            //}
        }
コード例 #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            string ftrNm  = cmbSampleFeatureClass.Text;
            string sasDir = cmbModelDir.Text;

            if (ftrNm == "" || ftrNm == null)
            {
                MessageBox.Show("You must have a Workspace selected");
                return;
            }
            if (sasDir == "" || sasDir == null)
            {
                MessageBox.Show("You must have a SAS modeled directory selected");
                return;
            }
            if (!System.IO.File.Exists(rR.SasOutputFile))
            {
                MessageBox.Show("Could not find the sas estimate file. You either needed to first create the classificaiton model or select a feature dataset that has been used to create the model!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int paramLength = rR.OutParameters.Length;
            int rsBndsCnt   = lstRasterBands.Items.Count;
            int bCnt        = 0;

            for (int i = 0; i < rsBndsCnt; i++)
            {
                bCnt = bCnt + ((IRasterBandCollection)rstDic[lstRasterBands.Items[i].ToString()]).Count;
            }
            if (bCnt < 1 || (paramLength - 1) != bCnt)
            {
                MessageBox.Show("Param = " + (paramLength - 1).ToString() + " BandCount = " + bCnt.ToString() + "\nYou must have the same number of rasters selected in the same order as parameter estimates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnViewOrder.PerformClick();
                return;
            }
            IRasterBandCollection rsBc = new RasterClass();

            for (int i = 0; i < rsBndsCnt; i++)
            {
                IRaster rs = rstDic[lstRasterBands.Items[i].ToString()];
                rsBc.AppendBands((IRasterBandCollection)rs);
            }
            this.Visible = false;
            rR.InRaster  = (IRaster)rsBc;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new esriUtil.Forms.RunningProcess.frmRunningProcessDialog(false);
            System.DateTime dt1 = System.DateTime.Now;
            rp.addMessage("Creating Regression Raster.");
            rp.addMessage("Name of the out raster = " + sasDir + ". Bands are in the order of dependent variables");
            int bcnt = 1;

            foreach (string s in rR.Categories)
            {
                rp.addMessage("\tBand_" + bcnt.ToString() + " = " + s);
                bcnt++;
            }
            rp.addMessage("This may take some time...");
            rp.Show();
            rp.TopMost = true;
            rp.stepPGBar(20);
            rp.Refresh();
            try
            {
                outraster     = rR.createModelRaster();
                outrastername = sasDir;
                if (mp != null && addToMap)
                {
                    rp.addMessage("Adding Rasters to map");
                    rp.Refresh();
                    IRasterLayer rsLyr1 = new RasterLayerClass();
                    rsLyr1.Name = outrastername;
                    rsLyr1.CreateFromRaster(outraster);
                    rsLyr1.Visible = false;
                    mp.AddLayer(rsLyr1);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception exc)
            {
                rp.addMessage(exc.ToString());
            }
            finally
            {
                rp.stepPGBar(50);
                rp.addMessage("Finished creating raster");
                rp.Refresh();
                System.DateTime dt2     = System.DateTime.Now;
                System.TimeSpan ts      = dt2.Subtract(dt1);
                string          prcTime = "Time to complete process:\n" + ts.Days.ToString() + " Days " + ts.Hours.ToString() + " Hours " + ts.Minutes.ToString() + " Minutes " + ts.Seconds.ToString() + " Seconds ";
                rp.addMessage(prcTime);
                rp.stepPGBar(100);
                rp.Refresh();
                rp.enableClose();
                this.Close();
            }
            return;
        }
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm = txtOutNm.Text;
            float intercept = System.Convert.ToSingle(nudIntercept.Value);
            if (rstNm == null || rstNm == "")
            {
                MessageBox.Show("You must specify a output name","No Output",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            if (dgvRasterSlopes.Rows.Count < 1)
            {
                MessageBox.Show("You must select at least one Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            IRasterBandCollection rsBc = new RasterClass();
            List<float> slopes = new List<float>();
            slopes.Add(intercept);
            for (int i = 0; i < dgvRasterSlopes.Rows.Count; i++)
            {
                rsBc.AppendBands((IRasterBandCollection)rstDic[dgvRasterSlopes[0,i].Value.ToString()]);
                object vl = dgvRasterSlopes[1, i].Value;
                if (Convert.IsDBNull(vl))
                {
                    vl = 0;
                }
                slopes.Add(System.Convert.ToSingle(vl));
            }
            IFunctionRasterDataset comp = rsUtil.compositeBandFunction(rsBc);
            List<float[]> fslopes = new List<float[]>();
            fslopes.Add(slopes.ToArray());
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;
            rp.addMessage("Transforming Rasters. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                outraster = rsUtil.returnRaster(rsUtil.calcRegressFunction(comp,fslopes));
                if (mp != null&&addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts = dt2.Subtract(dt);
                string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Transforming Rasters" + t);
                rp.enableClose();
                this.Close();
            }
        }
 private IFunctionRasterDataset transform()
 {
     IRasterBandCollection rsBc = new RasterClass();
     for (int i = 0; i < coef.Length; i++)
     {
         double[] c = coef[i];
         double intercept = c[0];
         double slope = c[1];
         IFunctionRasterDataset tRs = rsUtil.getBand(transformRaster, i);
         IFunctionRasterDataset pRs = rsUtil.calcArithmaticFunction(tRs, slope, esriRasterArithmeticOperation.esriRasterMultiply);
         IFunctionRasterDataset fRs = rsUtil.calcArithmaticFunction(pRs, intercept, esriRasterArithmeticOperation.esriRasterPlus);
         IFunctionRasterDataset bRs = rsUtil.convertToDifFormatFunction(fRs, rsType);
         rsBc.AppendBand(((IRasterBandCollection)bRs).Item(0));
     }
     OutRaster = rsUtil.compositeBandFunction(rsBc);
     return OutRaster;
 }
コード例 #13
0
ファイル: frmDLSSimulation.cs プロジェクト: lovelll/DLS
        private void btnGenerateInputData_Click(object sender, EventArgs e)
        {
            //if (this.strProjectPath.Trim() == "")
            //    return;
            if (this.cmbBoundary.Text.Trim() == "")
            {
                MessageBox.Show("请添加边界数据!","提示!",MessageBoxButtons.OK);
                return;
            }
            if (this.cmbRstraint.Text.Trim() == "")
            {
                MessageBox.Show("请添加限制区域数据!", "提示!", MessageBoxButtons.OK);
                return;
            }
            //if (this.txtParameter.Text.Trim() == "")
            //    return;
            if (lsbLayerLandUse.Items.Count == 0)
                return;
            //if (lsbLayerDriverFactor.Items.Count == 0)
            //    return;
            int iLanduseType = 6;

            //ILayer pLayer = null;
            IRaster pRaster = new RasterClass();

            IGeoDataset pGdsMask = null;
            IGeoDataset pGdsRstraint = null;
            IGeoDataset pGdsLanduse = null;
            IGeoDataset pGdsDriverFactor = null;
            IRasterBandCollection pRasterBandColection=(new RasterClass()) as IRasterBandCollection;

            //读取
            double cellSize = 1000;

            //try
            //{
                string sLyrMask = this.cmbBoundary.Text;

                //boundaty-->mask
                for (int i = 0; i < pMap.LayerCount; i++)
                {
                    ILayer pLyr = pMap.get_Layer(i);
                    if (pLyr is IRasterLayer)
                    {
                        if (pLyr.Name == sLyrMask)
                        {
                            IRasterProps pRasterP = (pLyr as IRasterLayer).Raster as IRasterProps;
                            cellSize = pRasterP.MeanCellSize().X;
                            pGdsMask = (pLyr as IRasterLayer).Raster as IGeoDataset;
                        }
                    }
                }

                //data
                //限制区
                string sLyrRstraint = this.cmbRstraint.Text;
                //土地利用数据
                string sLyrLanduse = this.lsbLayerLandUse.Items[0].ToString();

                // 土地利用数据与驱动因子 数据名称(去除格式名)
                // 顺序不能改变  后面 ITable2DTable 使用这个列表进行了名称替换
                lsbNames.Add(sLyrLanduse.Remove(sLyrLanduse.LastIndexOf(".")));
                foreach (string name in lsbLayerDriverFactor.Items)
                {
                    lsbNames.Add(name.Remove(name.LastIndexOf("."))); //去除文件格式
                }

                //驱动因子
                //string[] arr = new string[this.lsbLayerDriverFactor.Items.Count];

                //for (int i = 0; i < this.lsbLayerDriverFactor.Items.Count; i++)
                //{
                //    arr[i]=this.lsbLayerDriverFactor.Items[i].ToString();
                //}

                for (int i = 0; i < pMap.LayerCount; i++)
                {
                    ILayer pLyr = pMap.get_Layer(i);
                    if (pLyr is IRasterLayer)
                    {
                        //IRaster curRaster = new RasterClass();
                        if (pLyr.Name == sLyrRstraint)
                        {
                            //curRaster = (pLyr as IRasterLayer).Raster;
                            //(pLyr as IRasterLayer).Raster.
                            pGdsRstraint = (pLyr as IRasterLayer).Raster as IGeoDataset;

                            //限制数据 region.grid
                            string ascFileNameRstraint = strProjectPath + "\\region.grid";
                            Rater2Ascii(pGdsMask,cellSize , pGdsRstraint, ascFileNameRstraint);
                        }

                        //土地利用数据
                        if (pLyr.Name == sLyrLanduse)
                        {
                            this.rtxtState.AppendText("读取土地利用参数数据...\n");
                            this.rtxtState.ScrollToCaret();

                            //curRaster = (pLyr as IRasterLayer).Raster;
                            pGdsLanduse = (pLyr as IRasterLayer).Raster as IGeoDataset;
                            //land use 添加到 IRasterBandCollection
                            IRasterBandCollection rasterbands = (IRasterBandCollection)(pLyr as IRasterLayer).Raster;
                            IRasterBand rasterband = rasterbands.Item(0);
                            pRasterBandColection.AppendBand(rasterband);

                            //pRasterBandColection = curRaster as IRasterBandCollection;
                            //pRasterBandColection.AppendBand(pRaster as IRasterBand);

                            string ascFileNameLanduse = strProjectPath + "\\cov1_all.0";
                            //cov1_0.0;cov1_1.0;
                            Rater2Ascii(pGdsMask, cellSize, pGdsLanduse, ascFileNameLanduse);
                            //

                            //将土地利用数据拆分

                            StreamReader sr = new StreamReader(ascFileNameLanduse, System.Text.Encoding.Default);
                            //try
                            //{

                            //使用StreamReader类来读取文件
                            sr.BaseStream.Seek(0, SeekOrigin.Begin);
                            // 从数据流中读取每一行,直到文件的最后一行,并在richTextBox1中显示出内容
                            //读取头文件
                            string[] header = new string[6];

                            for (int j = 0; j < 6; j++)
                            {
                                header[j] = sr.ReadLine();
                            }
                            //行列数
                            string[] ncols = header[0].Split(' ');
                            string[] nrows = header[1].Split(' ');
                            int icol = int.Parse(ncols[ncols.Length - 1]);
                            int irow = int.Parse(nrows[nrows.Length - 1]);

                            int[,] iLanduse = new int[irow, icol];
                            //
                            string strLine = sr.ReadLine();
                            string[] strData;
                            int ir = 0;
                            while (ir < irow)
                            //while (strLine != null)
                            {
                                strData = strLine.Split(' ');
                                for (int ic = 0; ic < icol; ic++)
                                {
                                    iLanduse[ir, ic] = int.Parse(strData[ic]);
                                }
                                strLine = sr.ReadLine();
                                ir++;
                            }
                            //关闭此StreamReader对象
                            sr.Close();
                            //输出相应的土地利用数据
                            DataTable2Txt(header, iLanduseType, iLanduse, strProjectPath);

                            //}
                            //catch (Exception ex)
                            //{
                            //MessageBox.Show(ex.Message);
                            sr.Close();
                            //}
                        }
                    }
                }
                this.rtxtState.AppendText("输出土地利用参数数据成功。\n");
                this.rtxtState.AppendText("读取驱动因子数据...\n");
                this.rtxtState.ScrollToCaret();
                for (int ifac = 0; ifac < lsbLayerDriverFactor.Items.Count; ifac++)
                {
                    for (int i = 0; i < pMap.LayerCount; i++)
                    {
                        ILayer pLyr = pMap.get_Layer(i);
                        if (pLyr is IRasterLayer)
                        {
                        //输出驱动因子数据  sc1gr0.grid

                            string sFacName = lsbLayerDriverFactor.Items[ifac].ToString();
                            if (pLyr.Name == sFacName)
                            {
                                //IRaster curRaster = new RasterClass();
                                //curRaster = (pLyr as IRasterLayer).Raster;
                                pGdsDriverFactor = (pLyr as IRasterLayer).Raster as IGeoDataset;

                                string ascFileNameFac = strProjectPath + "\\sc1gr"+ifac.ToString()+".grid";
                                //cov1_0.0;cov1_1.0;
                                this.rtxtState.AppendText("输出驱动因子数据【" + sFacName + "】\n");
                                //IGeoDataset curMask = null;
                                //curMask = pGdsMask;
                                Rater2Ascii(pGdsMask, cellSize, pGdsDriverFactor, ascFileNameFac);
                                this.rtxtState.AppendText("输出驱动因子数据【" + sFacName + "】成功。\n");
                                this.rtxtState.ScrollToCaret();
                                //mask 添加到 IRasterBandCollection
                                IRasterBandCollection rasterbands = (IRasterBandCollection)(pLyr as IRasterLayer).Raster;
                                IRasterBand rasterband = rasterbands.Item(0);
                                pRasterBandColection.AppendBand(rasterband);
                                //pRasterBandColection.Add(pRaster as IRasterBand,ifac+1);

                            }
                        }
                    }
                }
                this.rtxtState.AppendText("开始制备驱动因子参数...\n");
                this.rtxtState.ScrollToCaret();

                //IGeoDataset curtestGeo = null;
                ////boundaty-->mask
                //for (int i = 0; i < pMap.LayerCount; i++)
                //{
                //    ILayer pLyr = pMap.get_Layer(i);
                //    if (pLyr is IRasterLayer)
                //    {
                //        if (pLyr.Name == sLyrMask)
                //        {
                //            curtestGeo = ((pLyr as IRasterLayer).Raster) as IGeoDataset;
                //        }
                //    }
                //}

                //sample data
                ITable itFactors = ExportSample(pGdsMask, pRasterBandColection);

                //logistic 回归分析

                //lsbNames.AddRange(names);
                DataTable dtFactors = ITable2DTable(itFactors);

                itFactors = null;
                //MessageBox.Show(dtFactors.Columns[0].ColumnName + ";" + dtFactors.Columns[1].ColumnName + ";" + dtFactors.Columns[2].ColumnName);

                //制备驱动力参数文件
                this.rtxtState.AppendText("读取驱动因子数据表格数据...\n");
                this.rtxtState.ScrollToCaret();
                LogisticRegressionAnalysis lra;
                // Gets the columns of the independent variables
                List<string> names = new List<string>();
                foreach (string name in lsbLayerDriverFactor.Items)
                {
                    names.Add(name.Remove(name.LastIndexOf("."))); //去除文件格式
                }

                String[] independentNames = names.ToArray();
                DataTable independent = dtFactors.DefaultView.ToTable(false, independentNames);
                // Creates the input and output matrices from the source data table
                double[][] input = independent.ToArray();
                double[,] sourceMatrix = dtFactors.ToMatrix(independentNames);

                StreamWriter sw = new StreamWriter(strProjectPath + "\\alloc1.reg", false);
                for(int ild=1; ild< iLanduseType; ild++)
                {

                    String landuseName = (string)this.lsbLayerLandUse.Items[0].ToString();
                    this.rtxtState.AppendText("开始制备土地利用类型【" + ild.ToString() + "】驱动因子参数...\n");
                    this.rtxtState.ScrollToCaret();
                    DataColumn taxColumn =new DataColumn();
                    taxColumn.DataType = System.Type.GetType("System.Int32");
                    taxColumn.ColumnName ="sysland"+ild.ToString();//列名
                    taxColumn.Expression = "iif("+lsbNames[0]+" = "+ild.ToString()+",1,0)";//设置该列得表达式,用于计算列中的值或创建聚合列
                    dtFactors.Columns.Add(taxColumn);
                    string dependentName = "sysland" + ild.ToString();

                    DataTable dependent = dtFactors.DefaultView.ToTable(false, dependentName);
                    double[] output = dependent.Columns[dependentName].ToArray();

                    // Creates the Simple Descriptive Analysis of the given source
                    DescriptiveAnalysis sda = new DescriptiveAnalysis(sourceMatrix, independentNames);
                    sda.Compute();

                    // Populates statistics overview tab with analysis data
                    //dgvDistributionMeasures.DataSource = sda.Measures;

                    // Creates the Logistic Regression Analysis of the given source
                    lra = new LogisticRegressionAnalysis(input, output, independentNames, dependentName);

                    // Compute the Logistic Regression Analysis
                    lra.Compute();

                    // Populates coefficient overview with analysis data
                    //lra.Coefficients;

                    //MessageBox.Show(lra.Coefficients.Count.ToString());
                    //MessageBox.Show(lra.CoefficientValues[0].ToString());

                    //string str_check = listBox_deVar.Items[var_count].ToString().ToLower();
                    string st = ild.ToString();
                    int Relength = lra.CoefficientValues.Length;

                    int number = 0;
                    for (int i = 1; i < Relength; i++)
                    {
                        //if (< 0.05)
                        //{
                            number++;
                        //}
                    }
                    RegressionResult.Items.Add(st);
                    RegressionResult.Items.Add("\t" + Math.Round(lra.CoefficientValues[1], 6));
                    RegressionResult.Items.Add(number);
                    int var_number = 0;
                    for (int i = 0; i < Relength; i++)//改过了0=1
                    {
                        //if ( < 0.05)
                        //{
                        RegressionResult.Items.Add("\t" + Math.Round(lra.CoefficientValues[i], 6) + "\t" + var_number);
                        //}
                        var_number = var_number + 1;
                    }

                    // 保存alloc1.reg 文件
                    sw.WriteLine(st);
                    sw.WriteLine("\t" + Math.Round(lra.CoefficientValues[1], 6));//改过了1=0
                    sw.WriteLine(number);
                    int var_number2 = 0;
                    for (int i = 0; i < Relength; i++)//改过了0=1
                    {
                        //if ( < 0.05)
                        //{
                        sw.WriteLine("\t" + Math.Round(lra.CoefficientValues[i],6) + "\t" + var_number2);
                        //}
                        var_number2 = var_number2 + 1;
                    }
                    //progressBar1.Value = var_count + 1;
                }
                sw.Close();

                this.rtxtState.AppendText("制备驱动因子参数成功。\n");
                this.rtxtState.ScrollToCaret();
                MessageBox.Show("制备驱动因子参数成功!","提示",MessageBoxButtons.OK);
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
        }
        public void btnExecute_Click(object sender, EventArgs e)
        {
            string tblNm = txtOutNm.Text;
            if (tblNm == null || tblNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (lsbRaster.Items.Count < 1)
            {
                MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRasterBandCollection rsBc = new RasterClass();
            for (int i = 0; i < lsbRaster.Items.Count; i++)
            {
                rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]);

            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;
            rp.addMessage("Building Raster Attribute Table. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                string outDbStr = geoUtil.getDatabasePath(tblNm);
                string outName = System.IO.Path.GetFileNameWithoutExtension(tblNm);
                IWorkspace wks = geoUtil.OpenWorkSpace(outDbStr);
                IFunctionRasterDataset fDset = rsUtil.compositeBandFunction(rsBc);
                outtbl = rsUtil.calcCombinRasterFunctionTable(fDset,wks,outName);
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts = dt2.Subtract(dt);
                string t = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished creating attribute table");
                rp.enableClose();
                this.Close();
            }
        }
コード例 #15
0
ファイル: frmCellStatistic.cs プロジェクト: chinasio/Control
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int startX, endX;
            string shpDir;
              ��
                if (bDataPath == true)
                {
                    fileName = txtOutData.Text;
                    shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                    startX = fileName.LastIndexOf("\\");
                    endX = fileName.Length;
                    shpFile = fileName.Substring(startX + 1, endX - startX - 1);
                }
                else
                {
                    shpDir = txtOutData.Text;
                    shpFile = "����ͳ��դ��";
                }
            try
            {
               IRasterBandCollection pLocalCollection=new  RasterClass();
                ILocalOp pLocalOp=new RasterLocalOpClass();
                for (int i = 0; i <= listBoxAddedLayer.Items.Count - 1; i++)
                {
                    IRaster pInRaster=GetRSLyrFromMapLyr(listBoxAddedLayer.Items[i].ToString().Trim());
                    IRasterDataset pRasterGeo = pInRaster as IRasterDataset;
                    pLocalCollection.AppendBand(pRasterGeo as IRasterBand );
                }
                string sMethod = comboBoxMethod.Text;
                IRasterLayer pRasterLayer = new RasterLayerClass();
                IRaster pOutRaster = null;
                switch (sMethod)
                {
                    case "Majority":
                        pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMajority) as IRaster;
                        break;
                    case "Maximum":
                        pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMaximum) as IRaster;
                        break;
                    case "Mean":
                        pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMean) as IRaster;
                        break;
                    case "Median":
                        pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMedian) as IRaster;
                        break;
                    case "Minimum":
                        pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMinimum ) as IRaster;
                        break;
                    case "Minority":
                        pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMinority ) as IRaster;
                        break;
                    case "Range":
                        pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsRange ) as IRaster;
                        break;
                    case "Standard Deviation":
                        pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsStd ) as IRaster;
                        break;
                    case "Sum":
                        pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsSum ) as IRaster;
                        break;
                    case "Variety":
                        pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsVariety) as IRaster;
                        break;
                }
                pRasterLayer.Name = "����ͳ��դ��";
                Utility.ConvertRasterToRsDataset(shpDir, pOutRaster, "����ͳ��դ��");
                pRasterLayer = Utility.SetStretchRenderer(pOutRaster);
                pMainFrm.getMapControl().AddLayer(pRasterLayer, 0);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());

            }
        }
        /// <summary>
        /// Creates an in Memory Raster given a raster dataset
        /// </summary>
        /// <param name="rsDset">IRasterDataset</param>
        /// <returns>IRaster</returns>
        public IRaster createRaster(IRasterDataset rsDset)
        {
            if (rsDset == null)
            {
                return null;
            }
            else
            {
                string cNm = rsDset.Format.ToLower();
                if (cNm.EndsWith("hdf4") || cNm.EndsWith("ntif"))
                {

                    IRasterBandCollection rsBc = new RasterClass();
                    IRasterDatasetJukebox rsDsetJu = (IRasterDatasetJukebox)rsDset;
                    List<IRaster> rsLst = new List<IRaster>();
                    int subCnt = rsDsetJu.SubdatasetCount;
                    for (int i = 0; i < subCnt; i++)
                    {
                        rsDsetJu.Subdataset = i;
                        IRasterDataset3 subDset = (IRasterDataset3)rsDsetJu;

                        rsLst.Add(subDset.CreateFullRaster());

                    }
                    IFunctionRasterDataset fDset = compositeBandFunction(rsLst.ToArray());
                    return createRaster(fDset);

                }
                else
                {
                    IRasterDataset3 rDset3 = (IRasterDataset3)rsDset;
                    return rDset3.CreateFullRaster();
                }
            }
        }
 private IFunctionRasterDataset createCompositeFunction(string[] paramArr)
 {
     IRasterBandCollection rsBC = new RasterClass();
     foreach(string s in paramArr)
     {
         IFunctionRasterDataset rs = getRaster(s);
         rsBC.AppendBands((IRasterBandCollection)rs);
     }
     return rsUtil.compositeBandFunction(rsBC);
 }
コード例 #18
0
ファイル: CatalogItemFactory.cs プロジェクト: zj8487/HyDM
        public static ILayer CreateLayer(ICatalogItem catalogItem)
        {
            if (catalogItem == null || catalogItem.Dataset == null)
            {
                return(null);
            }

            ILayer          lyrNew      = null;
            enumCatalogType catalogType = catalogItem.Type;

            switch (catalogType)
            {
            case enumCatalogType.Workpace:
            case enumCatalogType.FeatureDataset:
            case enumCatalogType.Table:
                return(null);

            case enumCatalogType.FeatureClassPoint:
            case enumCatalogType.FeatureClassLine:
            case enumCatalogType.FeatureClassArea:
            case enumCatalogType.FeatureClassAnnotation:
            case enumCatalogType.FeatureClassEmpty:
            case enumCatalogType.FeatureClass3D:
            case enumCatalogType.RasterCatalog:
                IFeatureLayer lyrFeature = new FeatureLayerClass();
                lyrFeature.FeatureClass = catalogItem.Dataset as IFeatureClass;
                lyrNew = lyrFeature;
                break;

            case enumCatalogType.RasterMosaic:
            case enumCatalogType.RasterSet:
                IRasterLayer lyrRaster = new RasterLayerClass();
                lyrRaster.CreateFromDataset(catalogItem.Dataset as IRasterDataset);
                lyrNew = lyrRaster;
                break;

            case enumCatalogType.RasterBand:
                IRasterLayer          lyrRasterBand = new RasterLayerClass();
                IRasterBand           rasterBand    = catalogItem.Dataset as IRasterBand;
                IRasterBandCollection colRasterBand = new RasterClass();
                colRasterBand.Add(rasterBand, 0);
                lyrRasterBand.CreateFromRaster(colRasterBand as IRaster);

                lyrNew = lyrRasterBand;
                break;

            case enumCatalogType.Tin:
                ITinLayer lyrTin = new TinLayerClass();
                lyrTin.Dataset = catalogItem.Dataset as ITin;
                lyrNew         = lyrTin;
                break;

            case enumCatalogType.Terrain:
                ITerrainLayer lyrTerrain = new TerrainLayerClass();
                lyrTerrain.Terrain = catalogItem.Dataset as ITerrain;
                lyrNew             = lyrTerrain;
                break;

            case enumCatalogType.Topology:
                ITopologyLayer lyrTopology = new TopologyLayerClass();
                lyrTopology.Topology = catalogItem.Dataset as ITopology;
                lyrNew = lyrTopology as ILayer;
                break;
            }

            return(lyrNew);
        }
 private void calcExtractBand(string[] prmArr, out string name, out IRaster raster)
 {
     name = prmArr[1].Split(new char[] { '@' })[1];
     string inRaster1 = prmArr[2].Split(new char[] { '@' })[1];
     string bands = prmArr[0].Split(new char[] { '@' })[1];
     IRaster rs = null;
     ILongArray lArr = new LongArrayClass();
     IRasterBandCollection rsBc = new RasterClass();
     if (rstDic.ContainsKey(inRaster1)) rs = rstDic[inRaster1];
     else rs = rsUtil.returnRaster(inRaster1);
     foreach (string s in bands.Split(new char[] { ',' }))
     {
         int bndIndex = System.Convert.ToInt32(s.Split(new char[] { '_' })[1]) - 1;
         lArr.Add(bndIndex);
     }
     raster = rsUtil.createRaster(rsUtil.getBands(rs, lArr));
 }
 private void calcLinearTransform(string[] prmArr, out string name, out IRaster raster)
 {
     name = prmArr[0].Split(new char[] { '@' })[1];
     float intercept = System.Convert.ToSingle(prmArr[1].Split(new char[] { '@' })[1]);
     string rasterSlopes = prmArr[2].Split(new char[] { '@' })[1];
     List<float> slpLst = new List<float>();
     slpLst.Add(intercept);
     IRasterBandCollection rsBc = new RasterClass();
     foreach (string s in rasterSlopes.Split(new char[]{','}))
     {
         string[] sArr = s.Split(new char[] { '`' });
         string rsNm = sArr[0];
         string slVl = sArr[1];
         IRaster rs = null;
         if (rstDic.ContainsKey(rsNm))
         {
             rs = rstDic[rsNm];
         }
         else
         {
             rs = rsUtil.returnRaster(rsNm);
         }
         rsBc.AppendBands((IRasterBandCollection)rs);
         slpLst.Add(System.Convert.ToSingle(s.Split(new char[]{'`'})[1]));
     }
     List<float[]> fLst = new List<float[]>();
     fLst.Add(slpLst.ToArray());
     raster = rsUtil.createRaster(rsUtil.calcRegressFunction((IRaster)rsBc, fLst));
 }
コード例 #21
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int    startX, endX;
            string shpDir;

             
            if (bDataPath == true)
            {
                fileName = txtOutData.Text;
                shpDir   = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX   = fileName.LastIndexOf("\\");
                endX     = fileName.Length;
                shpFile  = fileName.Substring(startX + 1, endX - startX - 1);
            }
            else
            {
                shpDir  = txtOutData.Text;
                shpFile = "象素统计栅格";
            }
            try
            {
                IRasterBandCollection pLocalCollection = new  RasterClass();
                ILocalOp pLocalOp = new RasterLocalOpClass();
                for (int i = 0; i <= listBoxAddedLayer.Items.Count - 1; i++)
                {
                    IRaster        pInRaster  = GetRSLyrFromMapLyr(listBoxAddedLayer.Items[i].ToString().Trim());
                    IRasterDataset pRasterGeo = pInRaster as IRasterDataset;
                    pLocalCollection.AppendBand(pRasterGeo as IRasterBand);
                }
                string       sMethod      = comboBoxMethod.Text;
                IRasterLayer pRasterLayer = new RasterLayerClass();
                IRaster      pOutRaster   = null;
                switch (sMethod)
                {
                case "Majority":
                    pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMajority) as IRaster;
                    break;

                case "Maximum":
                    pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMaximum) as IRaster;
                    break;

                case "Mean":
                    pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMean) as IRaster;
                    break;

                case "Median":
                    pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMedian) as IRaster;
                    break;

                case "Minimum":
                    pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMinimum) as IRaster;
                    break;

                case "Minority":
                    pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsMinority) as IRaster;
                    break;

                case "Range":
                    pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsRange) as IRaster;
                    break;

                case "Standard Deviation":
                    pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsStd) as IRaster;
                    break;

                case "Sum":
                    pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsSum) as IRaster;
                    break;

                case "Variety":
                    pOutRaster = pLocalOp.LocalStatistics(pLocalCollection as IGeoDataset, esriGeoAnalysisStatisticsEnum.esriGeoAnalysisStatsVariety) as IRaster;
                    break;
                }
                pRasterLayer.Name = "象素统计栅格";
                Utility.ConvertRasterToRsDataset(shpDir, pOutRaster, "象素统计栅格");
                pRasterLayer = Utility.SetStretchRenderer(pOutRaster);
                pMainFrm.getMapControl().AddLayer(pRasterLayer, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 private void calcSummarize(string[] prmArr, out string name, out IRaster raster)
 {
     name = prmArr[1].Split(new char[] { '@' })[1];
     string inRaster1 = prmArr[2].Split(new char[] { '@' })[1];
     string sumType = prmArr[0].Split(new char[]{'@'})[1];
     rasterUtil.localType op = (rasterUtil.localType)Enum.Parse(typeof(rasterUtil.localType),sumType);
     IRasterBandCollection rsBc = new RasterClass();
     foreach(string s in inRaster1.Split(new char[]{','}))
     {
         IRaster rs = null;
         if (rstDic.ContainsKey(s))
         {
             rs = rstDic[s];
         }
         else
         {
             rs = rsUtil.returnRaster(s);
         }
         rsBc.AppendBands((IRasterBandCollection)rs);
     }
     raster = rsUtil.createRaster(rsUtil.localStatisticsfunction((IRaster)rsBc,op));
 }
コード例 #23
0
ファイル: CatalogItemFactory.cs プロジェクト: hy1314200/HyDM
        public static ILayer CreateLayer(ICatalogItem catalogItem)
        {
            if (catalogItem == null || catalogItem.Dataset==null)
                return null;

            ILayer lyrNew = null;
            enumCatalogType catalogType = catalogItem.Type;
            switch(catalogType)
            {
                case enumCatalogType.Workpace:
                case enumCatalogType.FeatureDataset:
                case enumCatalogType.Table:
                    return null;

                case enumCatalogType.FeatureClassPoint:
                case enumCatalogType.FeatureClassLine:
                case enumCatalogType.FeatureClassArea:
                case enumCatalogType.FeatureClassAnnotation:
                case enumCatalogType.FeatureClassEmpty:
                case enumCatalogType.FeatureClass3D:
                case enumCatalogType.RasterCatalog:
                    IFeatureLayer lyrFeature= new FeatureLayerClass();
                    lyrFeature.FeatureClass = catalogItem.Dataset as IFeatureClass;
                    lyrNew = lyrFeature;
                    break;

                case enumCatalogType.RasterMosaic:
                case enumCatalogType.RasterSet:
                    IRasterLayer lyrRaster = new RasterLayerClass();
                    lyrRaster.CreateFromDataset(catalogItem.Dataset as IRasterDataset);
                    lyrNew = lyrRaster;
                    break;

                case enumCatalogType.RasterBand:
                    IRasterLayer lyrRasterBand = new RasterLayerClass();
                    IRasterBand rasterBand = catalogItem.Dataset as IRasterBand;
                    IRasterBandCollection colRasterBand = new RasterClass();
                    colRasterBand.Add(rasterBand, 0);
                    lyrRasterBand.CreateFromRaster(colRasterBand as IRaster);

                    lyrNew = lyrRasterBand;
                    break;

                case enumCatalogType.Tin:
                    ITinLayer lyrTin = new TinLayerClass();
                    lyrTin.Dataset = catalogItem.Dataset as ITin;
                    lyrNew = lyrTin;
                    break;

                case enumCatalogType.Terrain:
                    ITerrainLayer lyrTerrain = new TerrainLayerClass();
                    lyrTerrain.Terrain = catalogItem.Dataset as ITerrain;
                    lyrNew = lyrTerrain;
                    break;

                case enumCatalogType.Topology:
                    ITopologyLayer lyrTopology = new TopologyLayerClass();
                    lyrTopology.Topology = catalogItem.Dataset as ITopology;
                    lyrNew = lyrTopology as ILayer;
                    break;
            }

            return lyrNew;
        }
 private IFunctionRasterDataset createLinearTransformFunction(string[] paramArr)
 {
     string rrStr = paramArr[0];
     IRasterBandCollection rsBC = new RasterClass();
     foreach (string s in rrStr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
     {
         rsBC.AppendBands((IRasterBandCollection)getRaster(s.Trim()));
     }
     float[] s1 = (from string s in (paramArr[1].Split(new char[]{','})) select System.Convert.ToSingle(s)).ToArray();
     List<float[]> slopes = new List<float[]>();
     slopes.Add(s1);
     return rsUtil.calcRegressFunction((IRaster)rsBC, slopes);
 }
コード例 #25
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm  = txtOutNm.Text;
            string mdPath = txtOutputPath.Text;

            if (rstNm == null || rstNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (mdPath == null || mdPath == "")
            {
                MessageBox.Show("You must specify a model path", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (lsbRaster.Items.Count < 1)
            {
                MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRasterBandCollection rsBc = new RasterClass();

            for (int i = 0; i < lsbRaster.Items.Count; i++)
            {
                rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]);
            }
            IFunctionRasterDataset frDset = rsUtil.compositeBandFunction(rsBc);

            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Building Model Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                Statistics.ModelHelper br = new Statistics.ModelHelper(mdPath, rsUtil.createRaster(frDset), rsUtil);
                outraster = br.getRaster();
                if (mp != null && addToMap)
                {
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Building Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
 private IFunctionRasterDataset createLocalFunction(string[] paramArr)
 {
     IRasterBandCollection rsBC = new RasterClass();
     string rstStr = paramArr[0];
     rasterUtil.localType lType = (rasterUtil.localType)Enum.Parse(typeof(rasterUtil.localType),paramArr[1]);
     foreach (string s in rstStr.Split(new char[] { ',' }))
     {
         IFunctionRasterDataset rs = getRaster(s);
         rsBC.AppendBands((IRasterBandCollection)rs);
     }
     return rsUtil.localStatisticsfunction((IRaster)rsBC,lType);
 }
コード例 #27
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm     = txtOutNm.Text;
            float  intercept = System.Convert.ToSingle(nudIntercept.Value);

            if (rstNm == null || rstNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (dgvRasterSlopes.Rows.Count < 1)
            {
                MessageBox.Show("You must select at least one Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            IRasterBandCollection rsBc   = new RasterClass();
            List <float>          slopes = new List <float>();

            slopes.Add(intercept);
            for (int i = 0; i < dgvRasterSlopes.Rows.Count; i++)
            {
                rsBc.AppendBands((IRasterBandCollection)rstDic[dgvRasterSlopes[0, i].Value.ToString()]);
                object vl = dgvRasterSlopes[1, i].Value;
                if (Convert.IsDBNull(vl))
                {
                    vl = 0;
                }
                slopes.Add(System.Convert.ToSingle(vl));
            }
            IFunctionRasterDataset comp    = rsUtil.compositeBandFunction(rsBc);
            List <float[]>         fslopes = new List <float[]>();

            fslopes.Add(slopes.ToArray());
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Transforming Rasters. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                outraster = rsUtil.returnRaster(rsUtil.calcRegressFunction(comp, fslopes));
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Transforming Rasters" + t);
                rp.enableClose();
                this.Close();
            }
        }
 private IFunctionRasterDataset createModelFunction(string[] paramArr)
 {
     IRasterBandCollection rsBC = new RasterClass();
     string rstStr = paramArr[0];
     string mPath = getModelPath(paramArr[1]);
     foreach (string s in rstStr.Split(new char[]{','}))
     {
         IFunctionRasterDataset rs = getRaster(s);
         rsBC.AppendBands((IRasterBandCollection)rs);
     }
     IFunctionRasterDataset fDset = rsUtil.compositeBandFunction(rsBC);
     Statistics.ModelHelper mH = new Statistics.ModelHelper(mPath, rsUtil.createRaster(fDset), rsUtil);
     return rsUtil.createIdentityRaster(mH.getRaster());
 }
コード例 #29
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm  = txtOutNm.Text;
            string funNm  = cmbFunction.Text;
            int    before = System.Convert.ToInt32(nudBefore.Value);
            int    after  = System.Convert.ToInt32(nudAfter.Value);

            if (rstNm == null || rstNm == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (lsbRaster.Items.Count < 1)
            {
                MessageBox.Show("You must select at least on Raster", "No Rasters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (funNm == null || funNm == "")
            {
                MessageBox.Show("You must select at least on function", "No Function Selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRasterBandCollection rsBc = new RasterClass();

            for (int i = 0; i < lsbRaster.Items.Count; i++)
            {
                rsBc.AppendBands((IRasterBandCollection)rstDic[lsbRaster.Items[i].ToString()]);
            }
            IFunctionRasterDataset fdset = rsUtil.compositeBandFunction(rsBc);

            rasterUtil.localType op = (rasterUtil.localType)Enum.Parse(typeof(rasterUtil.localType), funNm);
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Calculating raster values. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                outraster = rsUtil.focalBandfunction(fdset, op, before, after);
                //rp.addMessage("Number of bands = " + ((IRasterBandCollection)outraster).Count);
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromDataset((IRasterDataset)outraster);
                    rstLyr.Name    = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = rstNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Creating Rasters" + t);
                rp.enableClose();
                this.Close();
            }
        }
 private IFunctionRasterDataset createAggregationFunction(string[] paramArr)
 {
     IRasterBandCollection rsBC = new RasterClass();
     string rstStr = paramArr[0];
     int cells = System.Convert.ToInt32(paramArr[1]);
     rasterUtil.focalType ftype = (rasterUtil.focalType)Enum.Parse(typeof(rasterUtil.focalType), paramArr[2]);
     foreach (string s in rstStr.Split(new char[] { ',' }))
     {
         IFunctionRasterDataset rs = getRaster(s);
         rsBC.AppendBands((IRasterBandCollection)rs);
     }
     return rsUtil.calcAggregationFunction((IRaster)rsBC,cells,ftype);
 }
コード例 #31
0
        private void button1_Click(object sender, EventArgs e)
        {
            string ftrNm = cmbSampleFeatureClass.Text;

            if (ftrNm == "" || ftrNm == null)
            {
                MessageBox.Show("You must have a sampling layer selected");
                return;
            }
            if (!System.IO.File.Exists(plrR.SasOutputFile))
            {
                MessageBox.Show("Could not find the sas estimate file. You either needed to first create the classificaiton model or select a feature dataset that has been used to create the model!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int paramLength = plrR.OutParameters.Length;
            int rsBndsCnt   = lstRasterBands.Items.Count;
            int bCnt        = 0;

            for (int i = 0; i < rsBndsCnt; i++)
            {
                bCnt = bCnt + ((IRasterBandCollection)rstDic[lstRasterBands.Items[i].ToString()]).Count;
            }
            if (bCnt < 1 || (paramLength - 1) != bCnt)
            {
                MessageBox.Show("Param = " + (paramLength - 1).ToString() + " BandCount = " + bCnt.ToString() + "\nYou must have the same number of rasters selected in the same order as parameter estimates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnViewOrder.PerformClick();
                return;
            }
            IRasterBandCollection rsBc = new RasterClass();

            for (int i = 0; i < rsBndsCnt; i++)
            {
                IRaster rs = rstDic[lstRasterBands.Items[i].ToString()];
                rsBc.AppendBands((IRasterBandCollection)rs);
            }
            this.Visible  = false;
            plrR.InRaster = (IRaster)rsBc;

            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new esriUtil.Forms.RunningProcess.frmRunningProcessDialog(false);
            System.DateTime dt1 = System.DateTime.Now;
            rp.addMessage("Creating PLR Classification Raster.");
            rp.addMessage("Bands are organized as follows:\n\tBand1=MLC\n\tBand2=BaseCategory");
            int bcCnt = 3;

            foreach (string c in plrR.Categories)
            {
                rp.addMessage("\tBand" + bcCnt.ToString() + "=" + c);
                bcCnt += 1;
            }
            rp.addMessage("This may take some time...");
            rp.Show();
            rp.TopMost = true;
            rp.stepPGBar(20);
            rp.Refresh();
            IRaster rst = plrR.createModelRaster(seed);

            if (mp != null)
            {
                rp.addMessage("Adding Raster to map");
                rp.Refresh();
                IRasterLayer rsLyr1 = new RasterLayerClass();
                rsLyr1.CreateFromRaster(rst);
                rsLyr1.Name    = "PLR_OUT";
                rsLyr1.Visible = false;
                mp.AddLayer(rsLyr1);
            }
            rp.stepPGBar(50);
            rp.addMessage("Finished creating raster");
            rp.Refresh();
            System.DateTime dt2     = System.DateTime.Now;
            System.TimeSpan ts      = dt2.Subtract(dt1);
            string          prcTime = "Time to complete process:\n" + ts.Days.ToString() + " Days " + ts.Hours.ToString() + " Hours " + ts.Minutes.ToString() + " Minutes " + ts.Seconds.ToString() + " Seconds ";

            rp.addMessage(prcTime);
            rp.stepPGBar(100);
            rp.Refresh();
            rp.enableClose();
            this.Close();
            return;
        }
 public IFunctionRasterDataset compositeBandFunction(IRaster[] rsArray)
 {
     IRasterBandCollection rsBc = new RasterClass();
     for (int i = 0; i < rsArray.Length; i++)
     {
         rsBc.AppendBands((IRasterBandCollection)rsArray[i]);
     }
     return compositeBandFunction(rsBc);
 }