Exemplo n.º 1
0
        private void populateComboBox()
        {
            if (mp != null)
            {
                IEnumLayer rstLyrs = vUtil.getActiveViewLayers(viewUtility.esriIRasterLayer);
                ILayer     lyr     = rstLyrs.Next();
                while (lyr != null)
                {
                    string       lyrNm  = lyr.Name;
                    IRasterLayer rstLyr = (IRasterLayer)lyr;
                    IRaster      rst    = rsUtil.createRaster(((IRaster2)rstLyr.Raster).RasterDataset);
                    if (!rstDic.ContainsKey(lyrNm))
                    {
                        rstDic.Add(lyrNm, rst);
                        cmbInRaster1.Items.Add(lyrNm);
                        cmbInRaster2.Items.Add(lyrNm);
                    }
                    lyr = rstLyrs.Next();
                }
            }
            foreach (string s in new string[] { ">", "<", ">=", "<=", "=", "and", "or" })
            {
                rasterUtil.logicalType opVl = rasterUtil.logicalType.GE;
                switch (s)
                {
                case ">":
                    opVl = rasterUtil.logicalType.GT;
                    break;

                case "<":
                    opVl = rasterUtil.logicalType.LT;
                    break;

                case "<=":
                    opVl = rasterUtil.logicalType.LE;
                    break;

                case "=":
                    opVl = rasterUtil.logicalType.EQ;
                    break;

                case "and":
                    opVl = rasterUtil.logicalType.AND;
                    break;

                case "or":
                    opVl = rasterUtil.logicalType.OR;
                    break;

                default:
                    opVl = rasterUtil.logicalType.GE;
                    break;
                }
                cmbProcess.Items.Add(s);
                oprDic.Add(s, opVl);
            }
        }
Exemplo n.º 2
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string inRst1Nm = cmbInRaster1.Text;
            string inRst2Nm = cmbInRaster2.Text;
            string opNm     = cmbProcess.Text;
            string outNmRst = txtOutName.Text;

            if (inRst1Nm == "" || inRst1Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (inRst2Nm == "" || inRst2Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 2 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (opNm == "" || opNm == null)
            {
                MessageBox.Show("You must select a process from the dropdown menu", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNmRst == "" || outNmRst == null)
            {
                MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            object rs1, rs2;

            if (rstDic.ContainsKey(inRst1Nm))
            {
                rs1 = rstDic[inRst1Nm];
            }
            else if (rsUtil.isNumeric(inRst1Nm))
            {
                rs1 = inRst1Nm;
            }
            else
            {
                MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (rstDic.ContainsKey(inRst2Nm))
            {
                rs2 = rstDic[inRst2Nm];
            }
            else if (rsUtil.isNumeric(inRst2Nm))
            {
                rs2 = inRst2Nm;
            }
            else
            {
                MessageBox.Show("You must specify an input raster for In Raster 2 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            rasterUtil.logicalType op = oprDic[opNm];
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Creating Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            try
            {
                switch (op)
                {
                case rasterUtil.logicalType.GT:
                    outraster = rsUtil.returnRaster(rsUtil.calcGreaterFunction(rs1, rs2));
                    break;

                case rasterUtil.logicalType.LT:
                    outraster = rsUtil.returnRaster(rsUtil.calcLessFunction(rs1, rs2));
                    break;

                case rasterUtil.logicalType.GE:
                    outraster = rsUtil.returnRaster(rsUtil.calcGreaterEqualFunction(rs1, rs2));
                    break;

                case rasterUtil.logicalType.LE:
                    outraster = rsUtil.returnRaster(rsUtil.calcLessEqualFunction(rs1, rs2));
                    break;

                case rasterUtil.logicalType.EQ:
                    outraster = rsUtil.returnRaster(rsUtil.calcEqualFunction(rs1, rs2));
                    break;

                case rasterUtil.logicalType.AND:
                    outraster = rsUtil.returnRaster(rsUtil.calcAndFunction(rs1, rs2));
                    break;

                case rasterUtil.logicalType.OR:
                    outraster = rsUtil.returnRaster(rsUtil.calcOrFunction(rs1, rs2));
                    break;

                default:
                    break;
                }
                outrastername = outNmRst;
                if (mp != null && aM)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    IRasterLayer rsLyr = new RasterLayerClass();
                    rsLyr.CreateFromRaster(outraster);
                    rsLyr.Name    = outrastername;
                    rsLyr.Visible = false;
                    mp.AddLayer((ILayer)rsLyr);
                }
                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 Logical Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }