Пример #1
0
 public void Bind(object pArgument)
 {
     if (pArgument is FocalFunctionArguments)
     {
         FocalFunctionArguments args = (FocalFunctionArguments)pArgument;
         inrs     = args.InRaster;
         orig     = args.OriginalRaster;
         inop     = args.Operation;
         inWindow = args.WindowType;
         lsiter   = args.Fastiter;
         windowN  = args.WindowCount;
         //Console.WriteLine(lsiter.Count());
         clms   = args.Columns;
         rws    = args.Rows;
         radius = args.Radius;
         myFunctionHelper.Bind(inrs);
         myFunctionHelperOrig.Bind(orig);
         myRasterInfo = myFunctionHelper.RasterInfo;
         myPixeltype  = myRasterInfo.PixelType;
         myValidFlag  = true;
     }
     else
     {
         throw new System.Exception("Incorrect arguments object. Expected: FocalFunctonArguments");
     }
 }
 public void Bind(object pArgument)
 {
     if (pArgument is glcmFunctionArguments)
     {
         glcmFunctionArguments args = (glcmFunctionArguments)pArgument;
         inrs = args.InRaster;
         orig = args.OriginalRaster;
         inWindow = args.WindowType;
         iter = args.GenericIterator;
         clms = args.Columns;
         rws = args.Rows;
         radius = args.Radius;
         glcmMetrics = args.GLCMMETRICS;
         horizontal = args.Horizontal;
         myFunctionHelper.Bind(inrs);
         myFunctionHelperOrig.Bind(orig);
         myRasterInfo = myFunctionHelper.RasterInfo;
         myPixeltype = myRasterInfo.PixelType;
         myValidFlag = true;
     }
     else
     {
         throw new System.Exception("Incorrect arguments object. Expected: glcmFunctonArguments");
     }
 }
Пример #3
0
 public void Bind(object pArgument)
 {
     if (pArgument is glcmFunctionArguments)
     {
         glcmFunctionArguments args = (glcmFunctionArguments)pArgument;
         inrs        = args.InRaster;
         orig        = args.OriginalRaster;
         inWindow    = args.WindowType;
         iter        = args.GenericIterator;
         clms        = args.Columns;
         rws         = args.Rows;
         radius      = args.Radius;
         glcmMetrics = args.GLCMMETRICS;
         horizontal  = args.Horizontal;
         myFunctionHelper.Bind(inrs);
         myFunctionHelperOrig.Bind(orig);
         myRasterInfo = myFunctionHelper.RasterInfo;
         myPixeltype  = myRasterInfo.PixelType;
         myValidFlag  = true;
     }
     else
     {
         throw new System.Exception("Incorrect arguments object. Expected: glcmFunctonArguments");
     }
 }
 public void Bind(object pArgument)
 {
     if (pArgument is FocalFunctionArguments)
     {
         FocalFunctionArguments args = (FocalFunctionArguments)pArgument;
         inrs = args.InRaster;
         orig = args.OriginalRaster;
         inop = args.Operation;
         inWindow = args.WindowType;
         lsiter = args.Fastiter;
         windowN = args.WindowCount;
         //Console.WriteLine(lsiter.Count());
         clms = args.Columns;
         rws = args.Rows;
         radius = args.Radius;
         myFunctionHelper.Bind(inrs);
         myFunctionHelperOrig.Bind(orig);
         myRasterInfo = myFunctionHelper.RasterInfo;
         myPixeltype = myRasterInfo.PixelType;
         myValidFlag = true;
     }
     else
     {
         throw new System.Exception("Incorrect arguments object. Expected: FocalFunctonArguments");
     }
 }
 public void Bind(object pArgument)
 {
     if (pArgument is LandscapeFunctionArguments)
     {
         LandscapeFunctionArguments args = (LandscapeFunctionArguments)pArgument;
         inrs = args.InRaster;
         orig = args.OriginalRaster;
         inop = args.Operation;
         landType = args.LandscapeType;
         inWindow = args.WindowType;
         clms = args.Columns;
         rws = args.Rows;
         radius = args.Radius;
         myFunctionHelper.Bind(inrs);
         myFunctionHelperCoef.Bind(orig);
         myRasterInfo = myFunctionHelper.RasterInfo;
         myPixeltype = myRasterInfo.PixelType;
         myValidFlag = true;
     }
     else
     {
         throw new System.Exception("Incorrect arguments object. Expected: FocalFunctonArguments");
     }
 }
Пример #6
0
 public void Bind(object pArgument)
 {
     if (pArgument is LandscapeFunctionArguments)
     {
         LandscapeFunctionArguments args = (LandscapeFunctionArguments)pArgument;
         inrs     = args.InRaster;
         orig     = args.OriginalRaster;
         inop     = args.Operation;
         landType = args.LandscapeType;
         inWindow = args.WindowType;
         clms     = args.Columns;
         rws      = args.Rows;
         radius   = args.Radius;
         myFunctionHelper.Bind(inrs);
         myFunctionHelperCoef.Bind(orig);
         myRasterInfo = myFunctionHelper.RasterInfo;
         myPixeltype  = myRasterInfo.PixelType;
         myValidFlag  = true;
     }
     else
     {
         throw new System.Exception("Incorrect arguments object. Expected: FocalFunctonArguments");
     }
 }
Пример #7
0
        public void Read(IPnt pTlc, IRaster pRaster, IPixelBlock pPixelBlock, int clms, int rws, IRasterFunctionHelper orig, rasterUtil.windowType wd)
        {
            try
            {
                if (wd == rasterUtil.windowType.RECTANGLE)
                {
                    try
                    {
                        int          pBHeight = pPixelBlock.Height;
                        int          pBWidth = pPixelBlock.Width;
                        IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                        IPnt         pbBigSize = new PntClass();
                        IPnt         pbBigLoc = new PntClass();
                        int          l, t;
                        l = clms / 2;
                        t = rws / 2;
                        int pbBigWd = pBWidth + clms; // -1;
                        int pbBigHt = pBHeight + rws; // -1;
                        pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                        pbBigSize.SetCoords(pbBigWd, pbBigHt);
                        IPixelBlock3 pbBig = (IPixelBlock3)orig.Raster.CreatePixelBlock(pbBigSize);
                        orig.Read(pbBigLoc, null, orig.Raster, (IPixelBlock)pbBig);

                        object[,] clmsValues = new object[pBWidth, pBHeight];
                        for (int nBand = 0; nBand < pbBig.Planes; nBand++)
                        {
                            float[,] pixelValues    = (float[, ])(ipPixelBlock.get_PixelData(nBand));
                            float[,] pixelValuesBig = (float[, ])(pbBig.get_PixelData(nBand));
                            for (int r = 0; r < pBHeight; r++)//coordinates in terms of the small pixel block
                            {
                                int er = r + rws;
                                for (int c = 0; c < pBWidth; c++)
                                {
                                    int ec = c + clms;

                                    Dictionary <int, int[]> uDic = findUniqueRegions.getUniqueRegions(pixelValuesBig, ec, er, clms, rws, c, r, (float)rasterUtil.getNoDataValue(rstPixelType.PT_FLOAT)); //key(int) = cell value value(int[2] = number of cells and number of edges)
                                    float uniqueMax = findUniqueRegionsValue(uDic);

                                    pixelValues.SetValue(uniqueMax, c, r);
                                }
                            }
                            try
                            {
                                ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        System.Exception myExc = new System.Exception("Exception caught in neighborhood landscape base rectangle helper Function. " + e.Message, e);
                        throw myExc;
                    }
                }
                else
                {
                    try
                    {
                        List <int[]> iter = new List <int[]>();
                        int[,] circleWindow = rasterUtil.createFocalWidow(clms, clms, wd, out iter);
                        System.Array noDataValueArr = (System.Array)((IRasterProps)pRaster).NoDataValue;
                        int          pBHeight = pPixelBlock.Height;
                        int          pBWidth = pPixelBlock.Width;
                        IPixelBlock3 ipPixelBlock = (IPixelBlock3)pPixelBlock;
                        IPnt         pbBigSize = new PntClass();
                        IPnt         pbBigLoc = new PntClass();
                        int          pbBigWd = pBWidth + clms;
                        int          pbBigHt = pBHeight + rws;
                        int          l, t;
                        l = clms / 2;
                        t = rws / 2;
                        pbBigLoc.SetCoords((pTlc.X - l), (pTlc.Y - t));
                        pbBigSize.SetCoords(pbBigWd, pbBigHt);
                        IPixelBlock3 pbBig = (IPixelBlock3)orig.Raster.CreatePixelBlock(pbBigSize);
                        orig.Read(pbBigLoc, null, orig.Raster, (IPixelBlock)pbBig);
                        object[,] clmsValues = new object[pBWidth, pBHeight];
                        for (int nBand = 0; nBand < pbBig.Planes; nBand++)
                        {
                            float noDataValue = System.Convert.ToSingle(noDataValueArr.GetValue(nBand));
                            float[,] pixelValues    = (float[, ])(ipPixelBlock.get_PixelData(nBand));
                            float[,] pixelValuesBig = (float[, ])(pbBig.get_PixelData(nBand));
                            for (int r = 0; r < pBHeight; r++)
                            {
                                int er = r + rws;
                                for (int c = 0; c < pBWidth; c++)
                                {
                                    int ec = c + clms;

                                    Dictionary <int, int[]> uDic = findUniqueRegions.getUniqueRegions(pixelValuesBig, ec, er, clms, rws, c, r, noDataValue, circleWindow); //key(int) = cell value value(int[2] = number of cells and number of edges)
                                    float uniqueMax = findUniqueRegionsValue(uDic);


                                    try
                                    {
                                        pixelValues.SetValue(uniqueMax, c, r);
                                    }
                                    catch
                                    {
                                        pixelValues.SetValue(noDataValue, c, r);
                                    }
                                }
                            }
                            ((IPixelBlock3)pPixelBlock).set_PixelData(nBand, pixelValues);
                        }
                    }
                    catch (Exception e)
                    {
                        System.Exception myExc = new System.Exception("Exception caught in neighborhood landscape base circle helper Function. " + e.Message, e);
                        throw myExc;
                    }
                }
            }
            catch (Exception exc)
            {
                System.Exception myExc = new System.Exception("Exception caught in neighborhood landscape base helper Function. " + exc.Message, exc);
                throw myExc;
            }
        }
Пример #8
0
        private void createRaster()
        {
            string rstNm    = cmbRaster.Text;
            string rstOut   = mtbOutName.Text.Trim();
            string windType = cmbWindowType.Text;
            string windDir  = cmbDirections.Text;
            string glcmType = cmbGlcmTypes.Text;
            int    clms     = System.Convert.ToInt32(nudColumns.Value);
            int    rows     = System.Convert.ToInt32(nudRows.Value);
            List <rasterUtil.glcmMetric> glcmArr = new List <rasterUtil.glcmMetric>();

            if (rstNm == "" || rstNm == null || rstOut == "" || rstOut == null)
            {
                MessageBox.Show("You must have both a raster and output name specified to use this tool!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (windType == null || windType == "" || windDir == "" || windDir == null)
            {
                MessageBox.Show("Window Type and Direction are not specified!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (glcmType == null || glcmType == "" || glcmType == "" || glcmType == null)
            {
                MessageBox.Show("Glcm Type is not specified!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            bool horz = true;

            rasterUtil.windowType wt = (rasterUtil.windowType)Enum.Parse(typeof(rasterUtil.windowType), windType);
            rasterUtil.glcmMetric gm = (rasterUtil.glcmMetric)Enum.Parse(typeof(rasterUtil.glcmMetric), glcmType);
            if (windDir.ToUpper() != "HORIZONTAL")
            {
                horz = false;
            }
            bool radius = false;

            if (wt != rasterUtil.windowType.RECTANGLE)
            {
                radius = true;
            }

            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog((perm == false));
            System.DateTime t1 = System.DateTime.Now;
            rp.addMessage("Start date and time = " + t1.Month.ToString() + "\\" + t1.Day.ToString() + "\\" + t1.Year.ToString() + " " + t1.Hour.ToString() + ":" + t1.Minute.ToString() + ":" + t1.Second.ToString());
            rp.addMessage("Creating the following " + windDir + " GLCM surfaces for the specified Raster:");
            rp.stepPGBar(15);
            if (perm)
            {
                rp.Show();
            }
            rp.Refresh();
            rp.TopMost = true;
            foreach (rasterUtil.glcmMetric g in glcmArr)
            {
                rp.addMessage("\t" + g.ToString());
            }
            rp.Refresh();
            IRaster inRs = rstDic[rstNm];

            try
            {
                if (radius)
                {
                    rst = rstUtil.createRaster(rstUtil.fastGLCMFunction(inRs, clms, horz, gm));
                }
                else
                {
                    rst = rstUtil.createRaster(rstUtil.fastGLCMFunction(inRs, clms, rows, horz, gm));
                }
                if (mp != null && perm)
                {
                    IRasterLayer rsLyr = new RasterLayerClass();
                    //rstUtil.calcStatsAndHist(rst);
                    rsLyr.CreateFromRaster(rst);
                    rsLyr.Name    = rstOut;
                    rsLyr.Visible = false;
                    mp.AddLayer((ILayer)rsLyr);
                }
                System.DateTime t2 = System.DateTime.Now;
                rp.addMessage("End date and time = " + t2.Month.ToString() + "\\" + t2.Day.ToString() + "\\" + t2.Year.ToString() + " " + t2.Hour.ToString() + ":" + t2.Minute.ToString() + ":" + t2.Second.ToString());
                rp.stepPGBar(100);
                rp.Refresh();
                oNm = rstOut;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                rp.enableClose();
                this.Close();
            }
            return;
        }
Пример #9
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string inRst1Nm       = cmbRaster.Text;
            string inFocalStat    = cmbFocalStat.Text;
            string windowType     = cmbWindowType.Text;
            string landMetricType = cmbMetric.Text;
            string outNmRst       = txtOutName.Text;
            int    clms           = System.Convert.ToInt32(nudColumns.Value);
            int    rws            = System.Convert.ToInt32(nudRows.Value);

            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 (inFocalStat == "" || inFocalStat == null)
            {
                MessageBox.Show("You must specify an Focal Statistic", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (windowType == "" || windowType == null)
            {
                MessageBox.Show("You must select a widow type from dropdown menu", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (landMetricType == "" || landMetricType == null)
            {
                MessageBox.Show("You must select a metric type from 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;
            }

            IRaster rs1   = rstDic[inRst1Nm];
            IRaster outRs = null;

            rasterUtil.windowType wdType = (rasterUtil.windowType)Enum.Parse(typeof(rasterUtil.windowType), windowType);

            rasterUtil.landscapeType lcType = (rasterUtil.landscapeType)Enum.Parse(typeof(rasterUtil.landscapeType), landMetricType);
            rasterUtil.focalType     fcType = (rasterUtil.focalType)Enum.Parse(typeof(rasterUtil.focalType), inFocalStat);
            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
            {
                if (wdType == rasterUtil.windowType.CIRCLE)
                {
                    outRs = rsUtil.createRaster(rsUtil.calcLandscapeFunction(rs1, clms, fcType, lcType));
                }
                else
                {
                    outRs = rsUtil.createRaster(rsUtil.calcLandscapeFunction(rs1, clms, rws, fcType, lcType));
                }
                outraster     = outRs;
                outrastername = outNmRst;
                if (mp != null && addToMap)
                {
                    rp.addMessage("Estimating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rsLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist
                    rsLyr.CreateFromRaster(outraster);
                    rsLyr.Name    = OutRasterName;
                    rsLyr.Visible = false;
                    mp.AddLayer(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 Landscape Analysis" + t);
                rp.enableClose();
                this.Close();
            }
        }