Exemplo n.º 1
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string inRst1Nm = cmbInRaster1.Text;
            string inRst2Nm = cmbInRaster2.Text;
            string inRst3Nm = cmbInRaster3.Text;
            string outNmRst = txtOutName.Text;

            if (inRst1Nm == "" || inRst1Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 1", "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 (inRst3Nm == "" || inRst3Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 3 or type in a number", "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, rs3;

            if (rstDic.ContainsKey(inRst1Nm))
            {
                rs1 = rstDic[inRst1Nm];
            }
            else
            {
                MessageBox.Show("You must specify an input raster for In Raster 1", "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;
            }
            if (rstDic.ContainsKey(inRst3Nm))
            {
                rs3 = rstDic[inRst3Nm];
            }
            else if (rsUtil.isNumeric(inRst3Nm))
            {
                rs3 = inRst3Nm;
            }
            else
            {
                MessageBox.Show("You must specify an input raster for In Raster 3 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            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
            {
                outraster     = rsUtil.createRaster(rsUtil.conditionalRasterFunction(rs1, rs2, rs3));
                outrastername = outNmRst;
                if (mp != null && aM)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    //rsUtil.calcStatsAndHist(outraster);
                    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 Conditional Analysis" + t);
                rp.enableClose();
                this.Close();
            }
        }
Exemplo n.º 2
0
        public string sumSedimentValues()
        {
            string outCSV = graphDir + "\\SedimentByArivalTime.csv";

            using (System.IO.StreamWriter swr = new System.IO.StreamWriter(outCSV))
            {
                string ln = "Alternative,Fires,Period,Sed10,Sed50,Sed10_A,Sed50_A,ArivalTime,CellCount";
                swr.WriteLine(ln);
                if (iterLst.Count < 2)
                {
                    Console.WriteLine("copying files over");
                    copyNaToResults(ref iterLst);
                }
                int    iterCnt = 0;
                string itop    = "";
                foreach (int iter in iterLst)
                {
                    if (iterCnt == 0)
                    {
                        itop = "No Action";
                    }
                    else
                    {
                        itop = "Optimum";
                    }
                    iterCnt++;
                    createPeriodRasters(iter);
                    for (int f = 1; f <= numFir; f++)
                    {
                        for (int i = 1; i <= numPer; i++)
                        {
                            string strln = "Building raster for iteration " + iter.ToString() + " fire " + f.ToString() + " period " + i.ToString();
                            if (rpForm != null)
                            {
                                rpForm.addMessage(strln);
                                rpForm.stepPGBar(5);
                                rpForm.Refresh();
                            }
                            else
                            {
                                Console.WriteLine(strln);
                            }
                            //treatment rasters
                            IFunctionRasterDataset perRs          = periodRasterLst[i - 1];
                            IFunctionRasterDataset noActionPeriod = rsUtil.calcEqualFunction(perRs, 0);
                            IFunctionRasterDataset t10            = rsUtil.calcArithmaticFunction(perRs, rst1Fine10, esriRasterArithmeticOperation.esriRasterMultiply);
                            IFunctionRasterDataset f10            = rsUtil.calcArithmaticFunction(noActionPeriod, rsfine10, esriRasterArithmeticOperation.esriRasterMultiply);
                            IFunctionRasterDataset t50            = rsUtil.calcArithmaticFunction(perRs, rst1Fine50, esriRasterArithmeticOperation.esriRasterMultiply);
                            IFunctionRasterDataset f50            = rsUtil.calcArithmaticFunction(noActionPeriod, rsfine50, esriRasterArithmeticOperation.esriRasterMultiply);
                            IFunctionRasterDataset sum10          = rsUtil.calcArithmaticFunction(t10, f10, esriRasterArithmeticOperation.esriRasterPlus);
                            IFunctionRasterDataset sum50          = rsUtil.calcArithmaticFunction(t50, f50, esriRasterArithmeticOperation.esriRasterPlus);
                            //flamelength rasters
                            string flameRasterPath         = resultsDir + "\\nodeflamelength" + iter.ToString() + "_" + f.ToString() + "_" + i.ToString() + ".txt";
                            IFunctionRasterDataset flmLng  = rsUtil.createIdentityRaster(flameRasterPath);
                            IFunctionRasterDataset flmBool = createBooleanFlame(flmLng);
                            //combined raster
                            IFunctionRasterDataset final10 = rsUtil.conditionalRasterFunction(flmBool, rshsf10, sum10);
                            IFunctionRasterDataset final50 = rsUtil.conditionalRasterFunction(flmBool, rshsf50, sum50);
                            //arrival zones
                            string ArivalRasterPath          = resultsDir + "\\arrivaltime" + iter.ToString() + "_" + f.ToString() + "_" + i.ToString() + ".txt";
                            IFunctionRasterDataset ariv      = rsUtil.createIdentityRaster(ArivalRasterPath);
                            IFunctionRasterDataset arivZones = createArivaltimeZones(ariv);
                            strln = "Summarizing arrival zones for iteration " + iter.ToString() + " fire " + f.ToString() + " period " + i.ToString();
                            if (rpForm != null)
                            {
                                rpForm.addMessage(strln);
                                rpForm.stepPGBar(5);
                                rpForm.Refresh();
                            }
                            else
                            {
                                Console.WriteLine(strln);
                            }
                            ln = getSummaryValue(itop, f, i, final10, final50, arivZones);
                            swr.Write(ln);
                            if (createinter)
                            {
                                strln = "Saving all intermediate rasters...";
                                if (rpForm != null)
                                {
                                    rpForm.addMessage(strln);
                                    rpForm.stepPGBar(5);
                                    rpForm.Refresh();
                                }
                                else
                                {
                                    Console.WriteLine(strln);
                                }
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(noActionPeriod), "noAct_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(t10), "t10_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(f10), "na10_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(t50), "t50_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(f50), "na50_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(sum10), "s10_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(sum50), "s50_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(flmBool), "flm_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(final10), "fl10_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(final50), "fl50_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                rsUtil.saveRasterToDataset(rsUtil.createRaster(arivZones), "az" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                            }
                            if (createcore)
                            {
                                if (!createinter)
                                {
                                    strln = "Saving core rasters...";
                                    if (rpForm != null)
                                    {
                                        rpForm.addMessage(strln);
                                        rpForm.stepPGBar(5);
                                        rpForm.Refresh();
                                    }
                                    else
                                    {
                                        Console.WriteLine(strln);
                                    }
                                    rsUtil.saveRasterToDataset(rsUtil.createRaster(final10), "fl10_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                    rsUtil.saveRasterToDataset(rsUtil.createRaster(final50), "fl50_" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                    rsUtil.saveRasterToDataset(rsUtil.createRaster(arivZones), "az" + iter.ToString() + f + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                                }
                            }
                            if (!createcore && !createinter)
                            {
                                try
                                {
                                    if (sedRaster != null)
                                    {
                                        rsUtil.deleteRasterDataset(((IRasterDataset)sedRaster).CompleteName);
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.ToString());
                                }
                            }
                        }
                    }
                }
                swr.Close();
            }
            outcsvpath = outCSV;
            //removelocks();
            return(outCSV);
        }