Esempio n. 1
0
        private Dictionary <double, object[]> zoneValueDic = null;//value = [count,max,min,sum,sum2,dictionary<int,int>]->dictionary is for unique, entropy, and ASM
        private void calcZoneValues()
        {
            bool   makeDic              = (ZoneClassCount || ZoneTypes.Contains(rasterUtil.zoneType.VARIETY) || ZoneTypes.Contains(rasterUtil.zoneType.ENTROPY) || ZoneTypes.Contains(rasterUtil.zoneType.ASM) || ZoneTypes.Contains(rasterUtil.zoneType.MINORITY) || ZoneTypes.Contains(rasterUtil.zoneType.MODE) || ZoneTypes.Contains(rasterUtil.zoneType.MEDIAN));
            IPnt   zMeanCellSize        = zRs.RasterInfo.CellSize;
            IPnt   vMeanCellSize        = vRs.RasterInfo.CellSize;
            int    intersectWidthCells  = System.Convert.ToInt32(intEnv.Width / zMeanCellSize.X);
            int    intersectHeightCells = System.Convert.ToInt32(intEnv.Height / zMeanCellSize.Y);
            IPoint tl        = intEnv.UpperLeft;
            int    bH        = 512;
            int    bW        = 512;
            int    wCellsMax = intersectWidthCells;
            int    hCellsMax = intersectHeightCells;
            IPnt   zPntLoc   = new PntClass();
            IPnt   vPntLoc   = new PntClass();
            IPnt   zPntSize  = new PntClass();
            IRasterFunctionHelper inZoneHelper = new RasterFunctionHelperClass();

            inZoneHelper.Bind(InZoneRaster);
            IRasterFunctionHelper inValueHelper = new RasterFunctionHelperClass();

            inValueHelper.Bind(InValueRaster);
            IRaster2 zr = (IRaster2)inZoneHelper.Raster;
            IRaster2 vr = (IRaster2)inValueHelper.Raster;
            int      zclm, zrw, vclm, vrw;

            zr.MapToPixel(tl.X + (zMeanCellSize.X / 2), tl.Y - (zMeanCellSize.Y / 2), out zclm, out zrw);
            vr.MapToPixel(tl.X + (zMeanCellSize.X / 2), tl.Y - (zMeanCellSize.Y / 2), out vclm, out vrw);
            int ozclm = zclm;
            int ozrw  = zrw;
            int ovclm = vclm;
            int ovrw  = vrw;

            zPntLoc.SetCoords(zclm, zrw);
            vPntLoc.SetCoords(vclm, vrw);
            for (int brw = 0; brw < hCellsMax; brw += bH)
            {
                int rH = hCellsMax - brw;//Height of block
                if (rH > bH)
                {
                    rH = bH;
                }
                for (int bclm = 0; bclm < wCellsMax; bclm += bW)
                {
                    int cW = wCellsMax - bclm;//Width of block
                    if (cW > bW)
                    {
                        cW = bW;
                    }
                    zPntSize.SetCoords(cW, rH);
                    IPixelBlock zPb = ((IRaster)zr).CreatePixelBlock(zPntSize);
                    IPixelBlock vPb = ((IRaster)vr).CreatePixelBlock(zPntSize);
                    inZoneHelper.Read(zPntLoc, null, (IRaster)zr, zPb);
                    inValueHelper.Read(vPntLoc, null, (IRaster)vr, vPb);
                    for (int i = 0; i < vPb.Planes; i++)
                    {
                        zoneValueDic = zoneValueDicArr[i];
                        //double vNoDataVl = System.Convert.ToDouble(((System.Array)vProps.NoDataValue).GetValue(i));
                        //System.Array vPix = (System.Array)vPb.get_SafeArray(i);
                        for (int r = 0; r < rH; r++)
                        {
                            for (int c = 0; c < cW; c++)
                            {
                                object zObj = zPb.GetVal(0, c, r);
                                if (zObj == null)
                                {
                                    continue;
                                }
                                else
                                {
                                    double z    = System.Convert.ToDouble(zObj);
                                    object vObj = vPb.GetVal(i, c, r);

                                    if (vObj == null)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        double   v = System.Convert.ToDouble(vObj);
                                        object[] zoneValue;
                                        if (zoneValueDic.TryGetValue(z, out zoneValue))
                                        {
                                            double cnt = System.Convert.ToDouble(zoneValue[0]);
                                            zoneValue[0] = cnt += 1;
                                            double maxVl = System.Convert.ToDouble(zoneValue[1]);
                                            if (v > maxVl)
                                            {
                                                maxVl        = v;
                                                zoneValue[1] = maxVl;
                                            }
                                            double minVl = System.Convert.ToDouble(zoneValue[2]);
                                            if (v < minVl)
                                            {
                                                minVl        = v;
                                                zoneValue[2] = minVl;
                                            }
                                            double s = System.Convert.ToDouble(zoneValue[3]);
                                            zoneValue[3] = s + v;
                                            double s2 = System.Convert.ToDouble(zoneValue[4]);
                                            zoneValue[4] = s2 + v * v;
                                            if (makeDic)
                                            {
                                                Dictionary <double, int> uDic = (Dictionary <double, int>)zoneValue[5];
                                                int cntVl = 0;
                                                if (uDic.TryGetValue(v, out cntVl))
                                                {
                                                    uDic[v] = cntVl += 1;
                                                }
                                                else
                                                {
                                                    uDic.Add(v, 1);
                                                }
                                                zoneValue[5] = uDic;
                                            }
                                            zoneValueDic[z] = zoneValue;
                                        }
                                        else
                                        {
                                            zoneValue    = new object[6];
                                            zoneValue[0] = 1d;
                                            zoneValue[1] = v;
                                            zoneValue[2] = v;
                                            zoneValue[3] = v;
                                            zoneValue[4] = v * v;
                                            if (makeDic)
                                            {
                                                Dictionary <double, int> uDic = new Dictionary <double, int>();
                                                uDic.Add(v, 1);
                                                zoneValue[5] = uDic;
                                            }
                                            zoneValueDic.Add(z, zoneValue);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //do this at the end
                    zclm = zclm + cW;
                    vclm = vclm + cW;
                    zPntLoc.SetCoords(zclm, zrw);
                    vPntLoc.SetCoords(vclm, vrw);
                }
                zrw = zrw + rH;
                vrw = vrw + rH;
                //reset PixelBlock columns
                zclm = ozclm;
                vclm = ovclm;
                zPntLoc.SetCoords(zclm, zrw);
                vPntLoc.SetCoords(vclm, vrw);
            }
        }
        private void calcZoneValuesFtr()
        {
            //Console.WriteLine("made it to the feature calculations");
            bool makeDic = (ZoneClassCount || ZoneTypes.Contains(rasterUtil.zoneType.VARIETY) || ZoneTypes.Contains(rasterUtil.zoneType.ENTROPY) || ZoneTypes.Contains(rasterUtil.zoneType.ASM) || ZoneTypes.Contains(rasterUtil.zoneType.MINORITY) || ZoneTypes.Contains(rasterUtil.zoneType.MODE) || ZoneTypes.Contains(rasterUtil.zoneType.MEDIAN));
            //
            //HashSet<byte> hByt = new HashSet<byte>();
            //
            ISpatialReference sr = vRs.RasterInfo.SpatialReference;
            IEnvelope vrsEnv = vRs.RasterInfo.Extent;
            ISpatialFilter spFilt = new SpatialFilterClass();
            spFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            spFilt.Geometry = vrsEnv;
            spFilt.GeometryField = ftrCls.ShapeFieldName;
            IFeatureCursor fCur = ftrCls.Search(spFilt, true);
            int zoneIndex = fCur.FindField(InZoneField);
            IFeature ftr = fCur.NextFeature();
            while (ftr != null)
            {
                IGeometry geo = ftr.Shape;
                double z = System.Convert.ToDouble(ftr.get_Value(zoneIndex));
                IPolygon4 poly = (IPolygon4)geo;
                if (needToProject)
                {
                    poly.Project(sr);
                }
                IGeometryBag geoBag = poly.ExteriorRingBag;
                IGeometryCollection geoColl = (IGeometryCollection)geoBag;
                for (int g = 0; g < geoColl.GeometryCount; g++)
                {
                    IGeometry geo2 = geoColl.Geometry[g];
                    IFunctionRasterDataset rs = rsUtil.clipRasterFunction(vRs, geo2, esriRasterClippingType.esriRasterClippingOutside);
                    IEnvelope rsEnv = rs.RasterInfo.Extent;
                    IRasterFunctionHelper rsFHelper = new RasterFunctionHelperClass();
                    rsFHelper.Bind(rs);
                    //Console.WriteLine((rsEnv.Width / 30).ToString() + ", " + (rsEnv.Height / 30).ToString());
                    IRasterCursor rsCur = ((IRaster2)rsFHelper.Raster).CreateCursorEx(null);
                    do
                    {
                        IPixelBlock pb = rsCur.PixelBlock;
                        for (int p = 0; p < pb.Planes; p++)
                        {
                            zoneValueDic = zoneValueDicArr[p];
                            object[] zoneValue;
                            double cnt = 0;
                            double maxVl = Double.MinValue;
                            double minVl = Double.MaxValue;
                            double s = 0;
                            double s2 = 0;
                            Dictionary<double, int> uDic = null;
                            if (zoneValueDic.TryGetValue(z, out zoneValue))
                            {
                                cnt = System.Convert.ToDouble(zoneValue[0]);
                                maxVl = System.Convert.ToDouble(zoneValue[1]);
                                minVl = System.Convert.ToDouble(zoneValue[2]);
                                s = System.Convert.ToDouble(zoneValue[3]);
                                s2 = System.Convert.ToDouble(zoneValue[4]);
                                uDic = (Dictionary<double, int>)zoneValue[5];
                            }
                            else
                            {
                                zoneValue = new object[6];
                                zoneValue[0] = cnt;
                                zoneValue[1] = maxVl;
                                zoneValue[2] = minVl;
                                zoneValue[3] = s;
                                zoneValue[4] = s2;
                                uDic = null;
                                if (makeDic)
                                {
                                    uDic = new Dictionary<double, int>();
                                }
                                zoneValue[5] = uDic;
                            }
                            for (int r = 0; r < pb.Height; r++)
                            {
                                for (int c = 0; c < pb.Width; c++)
                                {
                                    object vlo = pb.GetVal(p, c, r);
                                    if (vlo == null)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        double vl = System.Convert.ToDouble(vlo);
                                        cnt++;
                                        if (vl > maxVl) maxVl = vl;
                                        if (vl < minVl) minVl = vl;
                                        s += vl;
                                        s2 += vl * vl;
                                        if (makeDic)
                                        {
                                            int cntVl = 0;
                                            if (uDic.TryGetValue(vl, out cntVl))
                                            {
                                                uDic[vl] = cntVl += 1;
                                            }
                                            else
                                            {
                                                uDic.Add(vl, 1);
                                            }

                                        }
                                    }

                                }

                            }
                            zoneValue[0] = cnt;
                            zoneValue[1] = maxVl;
                            zoneValue[2] = minVl;
                            zoneValue[3] = s;
                            zoneValue[4] = s2;
                            zoneValue[5] = uDic;
                            zoneValueDic[z] = zoneValue;

                        }
                    } while (rsCur.Next());
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur);
                }
                ftr = fCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(fCur);
        }
Esempio n. 3
0
        private void calcZoneValuesFtr()
        {
            //Console.WriteLine("made it to the feature calculations");
            bool makeDic = (ZoneClassCount || ZoneTypes.Contains(rasterUtil.zoneType.VARIETY) || ZoneTypes.Contains(rasterUtil.zoneType.ENTROPY) || ZoneTypes.Contains(rasterUtil.zoneType.ASM) || ZoneTypes.Contains(rasterUtil.zoneType.MINORITY) || ZoneTypes.Contains(rasterUtil.zoneType.MODE) || ZoneTypes.Contains(rasterUtil.zoneType.MEDIAN));
            //
            //HashSet<byte> hByt = new HashSet<byte>();
            //
            ISpatialReference sr     = vRs.RasterInfo.SpatialReference;
            IEnvelope         vrsEnv = vRs.RasterInfo.Extent;
            ISpatialFilter    spFilt = new SpatialFilterClass();

            spFilt.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
            spFilt.Geometry      = vrsEnv;
            spFilt.GeometryField = ftrCls.ShapeFieldName;
            IFeatureCursor fCur      = ftrCls.Search(spFilt, true);
            int            zoneIndex = fCur.FindField(InZoneField);
            IFeature       ftr       = fCur.NextFeature();

            while (ftr != null)
            {
                IGeometry geo  = ftr.Shape;
                double    z    = System.Convert.ToDouble(ftr.get_Value(zoneIndex));
                IPolygon4 poly = (IPolygon4)geo;
                if (needToProject)
                {
                    poly.Project(sr);
                }
                IGeometryBag        geoBag  = poly.ExteriorRingBag;
                IGeometryCollection geoColl = (IGeometryCollection)geoBag;
                for (int g = 0; g < geoColl.GeometryCount; g++)
                {
                    IGeometry geo2                  = geoColl.Geometry[g];
                    IFunctionRasterDataset rs       = rsUtil.clipRasterFunction(vRs, geo2, esriRasterClippingType.esriRasterClippingOutside);
                    IEnvelope             rsEnv     = rs.RasterInfo.Extent;
                    IRasterFunctionHelper rsFHelper = new RasterFunctionHelperClass();
                    rsFHelper.Bind(rs);
                    //Console.WriteLine((rsEnv.Width / 30).ToString() + ", " + (rsEnv.Height / 30).ToString());
                    IRasterCursor rsCur = ((IRaster2)rsFHelper.Raster).CreateCursorEx(null);
                    do
                    {
                        IPixelBlock pb = rsCur.PixelBlock;
                        for (int p = 0; p < pb.Planes; p++)
                        {
                            zoneValueDic = zoneValueDicArr[p];
                            object[] zoneValue;
                            double   cnt   = 0;
                            double   maxVl = Double.MinValue;
                            double   minVl = Double.MaxValue;
                            double   s     = 0;
                            double   s2    = 0;
                            Dictionary <double, int> uDic = null;
                            if (zoneValueDic.TryGetValue(z, out zoneValue))
                            {
                                cnt   = System.Convert.ToDouble(zoneValue[0]);
                                maxVl = System.Convert.ToDouble(zoneValue[1]);
                                minVl = System.Convert.ToDouble(zoneValue[2]);
                                s     = System.Convert.ToDouble(zoneValue[3]);
                                s2    = System.Convert.ToDouble(zoneValue[4]);
                                uDic  = (Dictionary <double, int>)zoneValue[5];
                            }
                            else
                            {
                                zoneValue    = new object[6];
                                zoneValue[0] = cnt;
                                zoneValue[1] = maxVl;
                                zoneValue[2] = minVl;
                                zoneValue[3] = s;
                                zoneValue[4] = s2;
                                uDic         = null;
                                if (makeDic)
                                {
                                    uDic = new Dictionary <double, int>();
                                }
                                zoneValue[5] = uDic;
                            }
                            for (int r = 0; r < pb.Height; r++)
                            {
                                for (int c = 0; c < pb.Width; c++)
                                {
                                    object vlo = pb.GetVal(p, c, r);
                                    if (vlo == null)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        double vl = System.Convert.ToDouble(vlo);
                                        cnt++;
                                        if (vl > maxVl)
                                        {
                                            maxVl = vl;
                                        }
                                        if (vl < minVl)
                                        {
                                            minVl = vl;
                                        }
                                        s  += vl;
                                        s2 += vl * vl;
                                        if (makeDic)
                                        {
                                            int cntVl = 0;
                                            if (uDic.TryGetValue(vl, out cntVl))
                                            {
                                                uDic[vl] = cntVl += 1;
                                            }
                                            else
                                            {
                                                uDic.Add(vl, 1);
                                            }
                                        }
                                    }
                                }
                            }
                            zoneValue[0]    = cnt;
                            zoneValue[1]    = maxVl;
                            zoneValue[2]    = minVl;
                            zoneValue[3]    = s;
                            zoneValue[4]    = s2;
                            zoneValue[5]    = uDic;
                            zoneValueDic[z] = zoneValue;
                        }
                    } while (rsCur.Next());
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur);
                }
                ftr = fCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(fCur);
        }
        private void calcZoneValues()
        {
            bool makeDic = (ZoneClassCount||ZoneTypes.Contains(rasterUtil.zoneType.VARIETY)||ZoneTypes.Contains(rasterUtil.zoneType.ENTROPY)||ZoneTypes.Contains(rasterUtil.zoneType.ASM)||ZoneTypes.Contains(rasterUtil.zoneType.MINORITY)||ZoneTypes.Contains(rasterUtil.zoneType.MODE)||ZoneTypes.Contains(rasterUtil.zoneType.MEDIAN));
            IPnt zMeanCellSize = zRs.RasterInfo.CellSize;
            IPnt vMeanCellSize = vRs.RasterInfo.CellSize;
            int intersectWidthCells = System.Convert.ToInt32(intEnv.Width / zMeanCellSize.X);
            int intersectHeightCells = System.Convert.ToInt32(intEnv.Height / zMeanCellSize.Y);
            IPoint tl = intEnv.UpperLeft;
            int bH = 512;
            int bW = 512;
            int wCellsMax = intersectWidthCells;
            int hCellsMax = intersectHeightCells;
            IPnt zPntLoc = new PntClass();
            IPnt vPntLoc = new PntClass();
            IPnt zPntSize = new PntClass();
            IRasterFunctionHelper inZoneHelper = new RasterFunctionHelperClass();
            inZoneHelper.Bind(InZoneRaster);
            IRasterFunctionHelper inValueHelper = new RasterFunctionHelperClass();
            inValueHelper.Bind(InValueRaster);
            IRaster2 zr = (IRaster2)inZoneHelper.Raster;
            IRaster2 vr = (IRaster2)inValueHelper.Raster;
            int zclm, zrw, vclm, vrw;
            zr.MapToPixel(tl.X+(zMeanCellSize.X/2), tl.Y-(zMeanCellSize.Y/2), out zclm, out zrw);
            vr.MapToPixel(tl.X + (zMeanCellSize.X / 2), tl.Y - (zMeanCellSize.Y / 2), out vclm, out vrw);
            int ozclm = zclm;
            int ozrw = zrw;
            int ovclm = vclm;
            int ovrw = vrw;
            zPntLoc.SetCoords(zclm, zrw);
            vPntLoc.SetCoords(vclm, vrw);
            for (int brw = 0; brw < hCellsMax; brw += bH)
            {
                int rH = hCellsMax-brw;//Height of block
                if (rH > bH) rH = bH;
                for (int bclm = 0; bclm < wCellsMax; bclm += bW)
                {
                    int cW = wCellsMax - bclm;//Width of block
                    if (cW > bW) cW = bW;
                    zPntSize.SetCoords(cW, rH);
                    IPixelBlock zPb = ((IRaster)zr).CreatePixelBlock(zPntSize);
                    IPixelBlock vPb = ((IRaster)vr).CreatePixelBlock(zPntSize);
                    inZoneHelper.Read(zPntLoc, null, (IRaster)zr, zPb);
                    inValueHelper.Read(vPntLoc, null, (IRaster)vr, vPb);
                    for (int i = 0; i < vPb.Planes; i++)
                    {
                        zoneValueDic = zoneValueDicArr[i];
                        //double vNoDataVl = System.Convert.ToDouble(((System.Array)vProps.NoDataValue).GetValue(i));
                        //System.Array vPix = (System.Array)vPb.get_SafeArray(i);
                        for (int r = 0; r < rH; r++)
                        {
                            for (int c = 0; c < cW; c++)
                            {
                                object zObj = zPb.GetVal(0, c, r);
                                if (zObj==null)
                                {
                                    continue;
                                }
                                else
                                {
                                    double z = System.Convert.ToDouble(zObj);
                                    object vObj = vPb.GetVal(i, c, r);

                                    if (vObj==null)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        double v = System.Convert.ToDouble(vObj);
                                        object[] zoneValue;
                                        if (zoneValueDic.TryGetValue(z, out zoneValue))
                                        {
                                            double cnt = System.Convert.ToDouble(zoneValue[0]);
                                            zoneValue[0] = cnt += 1;
                                            double maxVl = System.Convert.ToDouble(zoneValue[1]);
                                            if (v > maxVl)
                                            {
                                                maxVl = v;
                                                zoneValue[1] = maxVl;
                                            }
                                            double minVl = System.Convert.ToDouble(zoneValue[2]);
                                            if (v < minVl)
                                            {
                                                minVl = v;
                                                zoneValue[2] = minVl;
                                            }
                                            double s = System.Convert.ToDouble(zoneValue[3]);
                                            zoneValue[3] = s + v;
                                            double s2 = System.Convert.ToDouble(zoneValue[4]);
                                            zoneValue[4] = s2 + v * v;
                                            if (makeDic)
                                            {
                                                Dictionary<double, int> uDic = (Dictionary<double, int>)zoneValue[5];
                                                int cntVl = 0;
                                                if (uDic.TryGetValue(v, out cntVl))
                                                {
                                                    uDic[v] = cntVl += 1;
                                                }
                                                else
                                                {
                                                    uDic.Add(v, 1);
                                                }
                                                zoneValue[5] = uDic;
                                            }
                                            zoneValueDic[z] = zoneValue;
                                        }
                                        else
                                        {
                                            zoneValue = new object[6];
                                            zoneValue[0] = 1d;
                                            zoneValue[1] = v;
                                            zoneValue[2] = v;
                                            zoneValue[3] = v;
                                            zoneValue[4] = v * v;
                                            if (makeDic)
                                            {
                                                Dictionary<double, int> uDic = new Dictionary<double, int>();
                                                uDic.Add(v, 1);
                                                zoneValue[5] = uDic;
                                            }
                                            zoneValueDic.Add(z, zoneValue);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //do this at the end
                    zclm = zclm + cW;
                    vclm = vclm + cW;
                    zPntLoc.SetCoords(zclm, zrw);
                    vPntLoc.SetCoords(vclm, vrw);
                }
                zrw = zrw + rH;
                vrw = vrw + rH;
                //reset PixelBlock columns
                zclm = ozclm;
                vclm = ovclm;
                zPntLoc.SetCoords(zclm, zrw);
                vPntLoc.SetCoords(vclm, vrw);
            }
        }
Esempio n. 5
0
        private string getSummaryValue(string iteration, int fire, int Period, IFunctionRasterDataset final10, IFunctionRasterDataset final50, IFunctionRasterDataset arivZones)
        {
            IRasterFunctionHelper arFH  = new RasterFunctionHelperClass();
            IRasterFunctionHelper f10FH = new RasterFunctionHelperClass();
            IRasterFunctionHelper f50FH = new RasterFunctionHelperClass();

            arFH.Bind(arivZones);
            f10FH.Bind(final10);
            f50FH.Bind(final50);
            Dictionary <int, double[]> vlDic = new Dictionary <int, double[]>();
            IRasterCursor rsCur = ((IRaster2)arFH.Raster).CreateCursorEx(null);
            IPnt          pnt   = new PntClass();

            pnt.X = rsCur.PixelBlock.Width;
            pnt.Y = rsCur.PixelBlock.Height;
            IRasterCursor rsCur2 = ((IRaster2)f10FH.Raster).CreateCursorEx(null);
            IRasterCursor rsCur3 = ((IRaster2)f50FH.Raster).CreateCursorEx(null);
            IPixelBlock3  pb     = null;
            IPixelBlock3  pb2    = null;
            IPixelBlock3  pb3    = null;

            while (rsCur.Next() && rsCur2.Next() && rsCur3.Next())
            {
                pb  = (IPixelBlock3)rsCur.PixelBlock;
                pb2 = (IPixelBlock3)rsCur2.PixelBlock;
                pb3 = (IPixelBlock3)rsCur3.PixelBlock;
                int ht = pb.Height;
                int wd = pb.Width;
                for (int h = 0; h < ht; h++)
                {
                    for (int w = 0; w < wd; w++)
                    {
                        object atobj  = pb.GetVal(0, w, h);
                        object f10obj = pb2.GetVal(0, w, h);
                        object f50obj = pb3.GetVal(0, w, h);
                        if (atobj == null || f10obj == null || f50obj == null)
                        {
                            continue;
                        }
                        else
                        {
                            int      at   = System.Convert.ToInt32(atobj);
                            double   f10  = System.Convert.ToDouble(f10obj);
                            double   f50  = System.Convert.ToDouble(f50obj);
                            double[] fArr = { 0, 0, 0 };
                            if (vlDic.TryGetValue(at, out fArr))
                            {
                                fArr[0]   = fArr[0] + f10;
                                fArr[1]   = fArr[1] + f50;
                                fArr[2]   = fArr[2] + 1;
                                vlDic[at] = fArr;
                            }
                            else
                            {
                                fArr = new double[] { f10, f50, 1 };
                                vlDic.Add(at, fArr);
                            }
                        }
                    }
                }
            }
            StringBuilder sb = new StringBuilder();
            //need to sort to do accumulative;
            List <int> keySortLst = vlDic.Keys.ToList();

            keySortLst.Sort();
            double ac10 = 0;
            double ac50 = 0;

            foreach (int ky in keySortLst)
            {
                double[] vlArr = vlDic[ky];
                double   s10   = vlArr[0];
                double   s50   = vlArr[1];
                ac10 += s10;
                ac50 += s50;
                double cellCnt = vlArr[2];
                string newStr  = iteration + "," + fire.ToString() + "," + Period.ToString() + "," + s10.ToString() + "," + s50.ToString() + "," + ac10.ToString() + "," + ac50.ToString() + "," + ky.ToString() + "," + cellCnt.ToString();
                //Console.WriteLine(newStr);
                sb.AppendLine(newStr);
            }
            return(sb.ToString());
        }
        private string getSummaryValue(string iteration,int fire,int Period, IFunctionRasterDataset final10, IFunctionRasterDataset final50, IFunctionRasterDataset arivZones)
        {
            IRasterFunctionHelper arFH = new RasterFunctionHelperClass();
            IRasterFunctionHelper f10FH = new RasterFunctionHelperClass();
            IRasterFunctionHelper f50FH = new RasterFunctionHelperClass();
            arFH.Bind(arivZones);
            f10FH.Bind(final10);
            f50FH.Bind(final50);
            Dictionary<int, double[]> vlDic = new Dictionary<int, double[]>();
            IRasterCursor rsCur = ((IRaster2)arFH.Raster).CreateCursorEx(null);
            IPnt pnt = new PntClass();
            pnt.X = rsCur.PixelBlock.Width;
            pnt.Y = rsCur.PixelBlock.Height;
            IRasterCursor rsCur2 = ((IRaster2)f10FH.Raster).CreateCursorEx(null);
            IRasterCursor rsCur3 = ((IRaster2)f50FH.Raster).CreateCursorEx(null);
            IPixelBlock3 pb = null;
            IPixelBlock3 pb2 = null;
            IPixelBlock3 pb3 = null;
            while (rsCur.Next() && rsCur2.Next() && rsCur3.Next())
            {
                pb = (IPixelBlock3)rsCur.PixelBlock;
                pb2 = (IPixelBlock3)rsCur2.PixelBlock;
                pb3 = (IPixelBlock3)rsCur3.PixelBlock;
                int ht = pb.Height;
                int wd = pb.Width;
                for (int h = 0; h < ht; h++)
                {
                    for (int w = 0; w < wd; w++)
                    {
                        object atobj = pb.GetVal(0, w, h);
                        object f10obj = pb2.GetVal(0, w, h);
                        object f50obj = pb3.GetVal(0, w, h);
                        if (atobj == null || f10obj == null || f50obj == null)
                        {
                            continue;
                        }
                        else
                        {
                            int at = System.Convert.ToInt32(atobj);
                            double f10 = System.Convert.ToDouble(f10obj);
                            double f50 = System.Convert.ToDouble(f50obj);
                            double[] fArr = { 0, 0, 0 };
                            if (vlDic.TryGetValue(at, out fArr))
                            {
                                fArr[0] = fArr[0] + f10;
                                fArr[1] = fArr[1] + f50;
                                fArr[2] = fArr[2] + 1;
                                vlDic[at] = fArr;
                            }
                            else
                            {
                                fArr = new double[] { f10, f50, 1 };
                                vlDic.Add(at, fArr);
                            }
                        }

                    }
                }
            }
            StringBuilder sb = new StringBuilder();
            //need to sort to do accumulative;
            List<int> keySortLst = vlDic.Keys.ToList();
            keySortLst.Sort();
            double ac10 = 0;
            double ac50 = 0;
            foreach (int ky in keySortLst)
            {
                double[] vlArr = vlDic[ky];
                double s10 = vlArr[0];
                double s50 = vlArr[1];
                ac10 += s10;
                ac50 += s50;
                double cellCnt = vlArr[2];
                string newStr = iteration + "," + fire.ToString() + "," + Period.ToString() + "," + s10.ToString() + "," + s50.ToString() + "," + ac10.ToString() + "," + ac50.ToString() + "," + ky.ToString() + "," + cellCnt.ToString();
                //Console.WriteLine(newStr);
                sb.AppendLine(newStr);
            }
            return sb.ToString();
        }
 private Dictionary<int, int> BuildVatFromScratch(IFunctionRasterDataset fRs)
 {
     Dictionary<int, int> dicVl = new Dictionary<int, int>();
     IRasterFunctionHelper rsHelp = new RasterFunctionHelperClass();
     rsHelp.Bind(fRs);
     IRasterCursor rsCur = rsHelp.Raster.CreateCursor();
     do
     {
         IPixelBlock pb = rsCur.PixelBlock;
         for (int r = 0; r < pb.Height; r++)
         {
             for (int c = 0; c < pb.Width; c++)
             {
                 object objVl = pb.GetVal(0, c, r);
                 if (objVl != null)
                 {
                     int vl = System.Convert.ToInt32(objVl);
                     int cnt = 0;
                     if (dicVl.TryGetValue(vl, out cnt))
                     {
                         dicVl[vl] = cnt + 1;
                     }
                     else
                     {
                         dicVl.Add(vl, 1);
                     }
                 }
             }
         }
     } while (rsCur.Next());
     return dicVl;
 }
        public IRasterDataset saveRasterToDatasetM(object inRaster, string outName, IWorkspace wks, rasterType rastertype, object noDataVl=null, int IntBlockWidth= 512, int IntBlockHeight=512)
        {
            IFunctionRasterDataset fDset = null;
            if ((rastertype == rasterType.GRID) && (((IRasterProps)inRaster).PixelType == rstPixelType.PT_DOUBLE))
            {
                fDset = createIdentityRaster(inRaster, rstPixelType.PT_FLOAT);
            }
            else
            {
                fDset = createIdentityRaster(inRaster);
            }
            IRasterDataset newRasterDataset = createNewRaster(inRaster, wks, outName,rastertype);
            IRasterBandCollection rsbc = (IRasterBandCollection)newRasterDataset;
            int bndCnt = rsbc.Count;
            IRasterFunctionHelper fHelp = new RasterFunctionHelperClass();
            fHelp.Bind(fDset);
            IRaster nRs = ((IRasterDataset3)newRasterDataset).CreateFullRaster();
            int tRasterWidth = fDset.RasterInfo.Width;
            int tRasterHeight = fDset.RasterInfo.Height;
            IPnt pntSize = new PntClass();
            IPnt topLeft = new PntClass();
            int intW = IntBlockWidth;
            int intH = IntBlockHeight;
            int nw = intW;
            int nh = intH;
            IRasterEdit nRsE = (IRasterEdit)nRs;
            if (rastertype == rasterType.GDB)
            {
                IRasterProps rsPropOut = (IRasterProps)nRs;
                IEnvelope env = fDset.RasterInfo.Extent;
                IPnt mcellSize = fDset.RasterInfo.CellSize;
                rsPropOut.Extent = env;
                rsPropOut.Width = (int)(env.Width / mcellSize.X);
                rsPropOut.Height = (int)(env.Height / mcellSize.Y);
                for (int pbh = 0; pbh < tRasterHeight; pbh += intW)
                {

                    for (int pbw = 0; pbw < tRasterWidth; pbw += intH)
                    {
                        topLeft.SetCoords(pbw, pbh);
                        getPbWidthHeight(tRasterWidth, tRasterHeight, topLeft, intW, intH, out nw, out nh);
                        //Console.WriteLine("PBTL = " + pbh.ToString() + ", " + pbw.ToString() + ", PBH = " + nh.ToString() + ", PBW = " + nw.ToString());
                        pntSize.SetCoords(nw, nh);
                        IPixelBlock3 inPb = (IPixelBlock3)fHelp.Raster.CreatePixelBlock(pntSize);
                        fHelp.Raster.Read(topLeft, (IPixelBlock)inPb);
                        IPixelBlock3 outPb = (IPixelBlock3)nRs.CreatePixelBlock(pntSize);
                        for (int b = 0; b < bndCnt; b++)
                        {
                            outPb.set_PixelData(b, inPb.get_PixelDataByRef(b));
                            outPb.set_NoDataMask(b, inPb.get_NoDataMaskByRef(b));
                        }
                        nRsE.Write(topLeft, (IPixelBlock)outPb);
                    }
                }
            }
            else
            {
                object uNoDataVl = convertToActualNoDataVl(noDataVl,fDset.RasterInfo.PixelType);
                try
                {
                    double nDv;
                    if (!(Double.TryParse(noDataVl.ToString(), out nDv)))
                    {
                        uNoDataVl=nDv;

                    }
                }
                catch(Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
                try
                {
                    for (int b = 0; b < bndCnt; b++)
                    {
                        IRasterProps rsPropsOut = (IRasterProps)rsbc.Item(b);
                        rsPropsOut.NoDataValue = uNoDataVl;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
                for (int pbh = 0; pbh < tRasterHeight; pbh += intH)
                {
                    for (int pbw = 0; pbw < tRasterWidth; pbw += intW)
                    {
                        topLeft.SetCoords(pbw, pbh);
                        getPbWidthHeight(tRasterWidth, tRasterHeight, topLeft, intW, intH, out nw, out nh);
                        Console.WriteLine("PBTL = " + pbh.ToString() + ", " + pbw.ToString() + ", PBH = " + nh.ToString() + ", PBW = " + nw.ToString());
                        pntSize.SetCoords(nw, nh);
                        IPixelBlock3 inPb = (IPixelBlock3)fHelp.Raster.CreatePixelBlock(pntSize);
                        fHelp.Raster.Read(topLeft, (IPixelBlock)inPb);
                        IPixelBlock3 outPb = (IPixelBlock3)nRs.CreatePixelBlock(pntSize);
                        for (int b = 0; b < bndCnt; b++)
                        {
                            System.Array outSArr = (System.Array)outPb.get_PixelData(b);
                            for (int r = 0; r < nh; r++)
                            {
                                for (int c = 0; c < nw; c++)
                                {
                                    object objVl = inPb.GetVal(b, c, r);
                                    if (objVl == null)
                                    {
                                        objVl = uNoDataVl;
                                    }
                                    outSArr.SetValue(objVl, c, r);
                                }
                            }
                            outPb.set_PixelData(b, outSArr);
                        }
                        nRsE.Write(topLeft, (IPixelBlock)outPb);
                    }
                }
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(nRsE);
            return newRasterDataset;
        }