Ejemplo n.º 1
0
        //public IFeatureClass createPolygons3()
        //{
        //    createFeatureClass();

        //}
        public IFeatureClass createPolygons2()
        {
            createFeatureClass();
            IRasterProps           rsProp   = (IRasterProps)inputRaster;
            int                    bndCnt   = ((IRasterBandCollection)inputRaster).Count;
            IPnt                   rsPnt    = rsProp.MeanCellSize();
            double                 cellArea = rsPnt.X * rsPnt.Y;
            double                 tCells   = minArea / cellArea;
            IFunctionRasterDataset sDset    = rsUtil.createMeanShiftFuction(inputRaster, (int)tCells);

            FunctionRasters.meanShiftFunctionDataset rFunc = (FunctionRasters.meanShiftFunctionDataset)sDset.Function;
            IRaster2               rs2   = (IRaster2)rsUtil.createRaster(sDset);
            IRasterCursor          rsCur = rs2.CreateCursorEx(null);
            IRasterDomainExtractor dExt  = new RasterDomainExtractorClass();

            do
            {
                IPixelBlock            pb     = rsCur.PixelBlock;
                IFunctionRasterDataset pbDset = rsUtil.PixelBlockToRaster(pb, rsCur.TopLeft, sDset);
                IRaster rs          = rsUtil.createRaster(pbDset);
                int     numClusters = rFunc.NumClusters;
                for (int c = 0; c < numClusters; c++)
                {
                    IFunctionRasterDataset fd  = rsUtil.calcEqualFunction(pbDset, c);
                    IFunctionRasterDataset fd2 = rsUtil.setNullValue(fd, 0);
                    IPolygon polys             = dExt.ExtractDomain(rsUtil.createRaster(fd2), true);
                }
            } while (rsCur.Next() == true);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur);



            return(outftr);
        }
Ejemplo 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);
        }
Ejemplo n.º 3
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();
            }
        }