示例#1
0
        private IRaster rescaleHt()
        {
            IRasterBand       rsBand  = ((IRasterBandCollection)htRs).Item(0);
            IRasterStatistics rsStats = rsBand.Statistics;
            double            min     = rsStats.Minimum;
            double            max     = rsStats.Maximum;
            double            range   = (max - min);
            double            step    = range / HeightLevels;
            IRemapFilter      flt     = new RemapFilterClass();
            double            cnt     = 0;
            double            i       = 0;

            for (i = min; i < max; i += step)
            {
                double nMax = i + step;
                if (nMax == max)
                {
                    nMax = max + 1;
                }
                flt.AddClass(i, nMax, cnt);
                cnt++;
            }
            IRaster rs2 = rsUtil.returnRaster(rsUtil.calcRemapFunction(htRs, flt));

            return(rsUtil.returnRaster(rsUtil.calcArithmaticFunction(rs2, 1000000, esriRasterArithmeticOperation.esriRasterMultiply)));
        }
示例#2
0
        public void convertFeatureToRaster(IFeatureClass InFeatureClass, string fldName)
        {
            ftrCls   = InFeatureClass;
            ftrField = fldName;
            IDataset dSet    = (IDataset)InFeatureClass;
            string   outRsNm = dSet.BrowseName;

            wks = dSet.Workspace;
            if (vRs != null)
            {
                if (!checkProjectionsFtr())
                {
                    if (rd != null)
                    {
                        rd.addMessage("Re-projecting feature class to match value raster's projection");
                    }
                    InFeatureClass = reprojectInFeatureClass(InFeatureClass, vRs.RasterInfo.SpatialReference);
                }
            }
            IWorkspace             wksTemp = geoUtil.OpenRasterWorkspace(tempWksStr);
            IFunctionRasterDataset rs      = rsUtil.createIdentityRaster(rsUtil.convertFeatureClassToRaster(InFeatureClass, rasterUtil.rasterType.IMAGINE, wksTemp, outRsNm, vRs.RasterInfo.CellSize.X, (IRasterDataset)vRs));

            rs = rsUtil.createIdentityRaster(rs, rstPixelType.PT_FLOAT);
            int fieldIndex = InFeatureClass.FindField(fldName);

            if (fieldIndex == -1)
            {
                fieldIndex = InFeatureClass.FindField(fldName + "_1");
            }
            if (fldName.ToLower() == InFeatureClass.OIDFieldName.ToLower() || fieldIndex == -1)
            {
                zRs = rs;
            }
            else
            {
                IRemapFilter   rFilt  = new RemapFilterClass();
                IFeatureCursor ftrCur = InFeatureClass.Search(null, false);
                IFeature       ftr    = ftrCur.NextFeature();

                while (ftr != null)
                {
                    double id  = ftr.OID;
                    double nVl = System.Convert.ToDouble(ftr.get_Value(fieldIndex));
                    if (Double.IsNaN(nVl) || Double.IsInfinity(nVl))
                    {
                        ftr = ftrCur.NextFeature();
                    }
                    else
                    {
                        //Console.WriteLine("adding oid = " + id.ToString() + " and value = " + nVl.ToString());
                        rFilt.AddClass(id, id + 1, nVl);
                        ftr = ftrCur.NextFeature();
                    }
                }
                zRs = rsUtil.calcRemapFunction(rs, rFilt);
            }
        }
示例#3
0
        private IFunctionRasterDataset createArivaltimeZones(IFunctionRasterDataset arrivalTime)
        {
            IRemapFilter      arrivalRemap = new RemapFilterClass();
            IRasterStatistics rsStats      = ((IRasterBandCollection)arrivalTime).Item(0).Statistics;

            if (rsStats == null)
            {
                rsUtil.calcStatsAndHist(arrivalTime);
                rsStats = ((IRasterBandCollection)arrivalTime).Item(0).Statistics;
            }
            else if (!rsStats.IsValid)
            {
                rsStats.SkipFactorX = 1;
                rsStats.SkipFactorY = 1;
                rsStats.Recalculate();
            }
            else
            {
            }
            double max  = rsStats.Maximum;
            double min  = rsStats.Minimum;
            double skip = 1;

            switch (arrCls)
            {
            case ArrivalClasses.Hours:
                skip = 60;
                break;

            case ArrivalClasses.Days:
                skip = 1440;
                break;

            default:
                break;
            }
            for (double i = 0; i <= max; i += skip)
            {
                double nVl = (i + skip) / skip;
                arrivalRemap.AddClass(min, i + skip, nVl);
            }
            IFunctionRasterDataset reRs = rsUtil.calcRemapFunction(arrivalTime, arrivalRemap);

            return(reRs);// reSampleRasterGrid(reRs);
        }
示例#4
0
        private IRaster calcTopo()
        {
            IFunctionRasterDataset rsAspect = rsUtil.calcAspectFunction(demRs);
            IRemapFilter           flt      = new RemapFilterClass();

            if (useAspect)
            {
                flt.AddClass(225, 315, 3);
                flt.AddClass(315, 360, 0);
                flt.AddClass(0, 45, 0);
                flt.AddClass(45, 135, 2);
                flt.AddClass(135, 225, 2);
            }
            else
            {
                flt.AddClass(0, 361, 0);
            }
            IRaster rs2 = rsUtil.returnRaster(rsUtil.calcRemapFunction(rsAspect, flt));

            return(rsUtil.returnRaster(rsUtil.calcArithmaticFunction(rs2, 10000, esriRasterArithmeticOperation.esriRasterMultiply)));
        }
        public void convertFeatureToRaster(IFeatureClass InFeatureClass, string fldName)
        {
            ftrCls = InFeatureClass;
            ftrField = fldName;
            IDataset dSet = (IDataset)InFeatureClass;
            string outRsNm = dSet.BrowseName;
            wks = dSet.Workspace;
            if (vRs != null)
            {
                if (!checkProjectionsFtr())
                {
                    if (rd != null) rd.addMessage("Re-projecting feature class to match value raster's projection");
                    InFeatureClass = reprojectInFeatureClass(InFeatureClass, vRs.RasterInfo.SpatialReference);

                }
            }
            IWorkspace wksTemp = geoUtil.OpenRasterWorkspace(tempWksStr);
            IFunctionRasterDataset rs = rsUtil.createIdentityRaster(rsUtil.convertFeatureClassToRaster(InFeatureClass, rasterUtil.rasterType.IMAGINE, wksTemp, outRsNm, vRs.RasterInfo.CellSize.X, (IRasterDataset)vRs));
            rs = rsUtil.createIdentityRaster(rs, rstPixelType.PT_FLOAT);
            int fieldIndex = InFeatureClass.FindField(fldName);
            if(fieldIndex == -1)
            {
                fieldIndex = InFeatureClass.FindField(fldName + "_1");
            }
            if (fldName.ToLower() == InFeatureClass.OIDFieldName.ToLower()||fieldIndex == -1)
            {
                zRs = rs;
            }
            else
            {
                IRemapFilter rFilt = new RemapFilterClass();
                IFeatureCursor ftrCur = InFeatureClass.Search(null, false);
                IFeature ftr = ftrCur.NextFeature();

                while (ftr != null)
                {
                    double id = ftr.OID;
                    double nVl = System.Convert.ToDouble(ftr.get_Value(fieldIndex));
                    if (Double.IsNaN(nVl) || Double.IsInfinity(nVl))
                    {
                        ftr = ftrCur.NextFeature();
                    }
                    else
                    {
                        //Console.WriteLine("adding oid = " + id.ToString() + " and value = " + nVl.ToString());
                        rFilt.AddClass(id, id + 1, nVl);
                        ftr = ftrCur.NextFeature();
                    }
                }
                zRs = rsUtil.calcRemapFunction(rs, rFilt);
            }
        }
 /// <summary>
 /// Remaps values equal to the compare Raster or value cell values = 1. Values less than or greater than compare raster or value = 0
 /// </summary>
 /// <param name="inRaster">string, IRasterDataset, or IRaster</param>
 /// <param name="vl">value to compare against</param>
 /// <returns>IRaster</returns>
 public IFunctionRasterDataset calcEqualFunction(object inRaster, object compareRaster)
 {
     IFunctionRasterDataset rs = createIdentityRaster(inRaster);
     IFunctionRasterDataset outRs = null;
     if (isNumeric(compareRaster.ToString()))
     {
         double vl = System.Convert.ToDouble(compareRaster);
         IRemapFilter rFilt = new RemapFilterClass();
         rstPixelType pType = rs.RasterInfo.PixelType;
         double max, min;
         max = 0;
         min = 0;
         #region set min max
         getMinMax(pType, ref max, ref min);
         #endregion
         double vlP1 = vl + 0.000001;
         rFilt.AddClass(min, vl, 0);
         rFilt.AddClass(vl, vlP1, 1);
         rFilt.AddClass(vlP1, max, 0);
         outRs = calcRemapFunction(rs, rFilt);
     }
     else
     {
         IFunctionRasterDataset minRst = calcArithmaticFunction(rs, compareRaster, esriRasterArithmeticOperation.esriRasterMinus);
         outRs = calcEqualFunction(minRst, 0);
     }
     IRasterInfo2 rsInfo2 = (IRasterInfo2)outRs.RasterInfo;
     IRasterStatistics rsStats = new RasterStatisticsClass();
     rsStats.Mean = 0.5;
     rsStats.Maximum = 1;
     rsStats.Minimum = 0;
     rsStats.StandardDeviation = 0.25;
     rsStats.SkipFactorX = 1;
     rsStats.SkipFactorY = 1;
     rsStats.IsValid = true;
     for (int i = 0; i < rsInfo2.BandCount; i++)
     {
         rsInfo2.set_Statistics(i, rsStats);
     }
     return outRs;
 }
示例#7
0
        private void createSedimentSurfaces()
        {
            IWorkspace sedWks = geoUtil.OpenRasterWorkspace(sedDir);

            sedRaster = rsUtil.createIdentityRaster(sedRaster, rstPixelType.PT_FLOAT);
            IFeatureCursor ftrCur        = ftrCls.Search(null, false);
            IFeature       ftr           = ftrCur.NextFeature();
            IRemapFilter   fine10        = new RemapFilterClass();
            IRemapFilter   fine50        = new RemapFilterClass();
            IRemapFilter   t1fine10      = new RemapFilterClass();
            IRemapFilter   t1fine50      = new RemapFilterClass();
            IRemapFilter   hsf10         = new RemapFilterClass();
            IRemapFilter   hsf50         = new RemapFilterClass();
            int            fine10Index   = ftrCls.FindField(f10fld);
            int            fine50Index   = ftrCls.FindField(f50fld);
            int            t1fine10Index = ftrCls.FindField(t10fld);
            int            t1fine50Index = ftrCls.FindField(t50fld);
            int            hsf10Index    = ftrCls.FindField(hsf10fld);
            int            hsf50Index    = ftrCls.FindField(hsf50fld);

            IRemapFilter[] remapArr = { fine10, fine50, t1fine10, t1fine50, hsf10, hsf50 };
            int[]          fldArr   = { fine10Index, fine50Index, t1fine10Index, t1fine50Index, hsf10Index, hsf50Index };
            int            cnt      = 0;
            int            numCells = System.Convert.ToInt32(treatCellSize.X / cellSize);

            while (ftr != null)
            {
                //need to set up remap filters for each raster and create a new raster for each sediment value
                double oid = System.Convert.ToInt32(ftr.OID);
                cnt = 0;
                foreach (IRemapFilter remap in remapArr)
                {
                    int    indexVl = fldArr[cnt];
                    double vl      = System.Convert.ToDouble(ftr.get_Value(indexVl)) * (Math.Pow((cellSize * 3.2808399), 2) / 43560);
                    remap.AddClass(oid, oid + 0.00001, vl);
                    // Console.WriteLine("Converting oid " + oid.ToString() + " to " + vl.ToString() );
                    cnt++;
                }
                ftr = ftrCur.NextFeature();
            }
            cnt = 1;
            IFunctionRasterDataset[] rsArr = { rsfine10, rsfine50, rst1Fine10, rst1Fine50, rshsf10, rshsf50 };
            foreach (IRemapFilter remap in remapArr)
            {
                string rsNm = "";
                IFunctionRasterDataset rs = null;
                IFunctionRasterDataset rr = rsUtil.calcRemapFunction(sedRaster, remap);
                //IRaster xx = rsUtil.setnullToValueFunction(rr, 0);
                //IRaster rRs = rsUtil.returnRaster(rsUtil.saveRasterToDataset(xx, "xxx"+cnt.ToString(), tWks, rasterUtil.rasterType.IMAGINE));
                //IRaster rs = calcAgFunction(rr, numCells, rasterUtil.focalType.SUM);
                switch (cnt)
                {
                case 1:
                    rsfine10 = calcAgFunction(rr, "n10", numCells);
                    rs       = rsfine10;
                    rsNm     = "n10";
                    break;

                case 2:
                    rsfine50 = calcAgFunction(rr, "n50", numCells);
                    rs       = rsfine50;
                    rsNm     = "n50";
                    break;

                case 3:
                    rst1Fine10 = calcAgFunction(rr, "t10", numCells);
                    rs         = rst1Fine10;
                    rsNm       = "t10";
                    break;

                case 4:
                    rst1Fine50 = calcAgFunction(rr, "t50", numCells);
                    rs         = rst1Fine50;
                    rsNm       = "t50";
                    break;

                case 5:
                    rshsf10 = calcAgFunction(rr, "h10", numCells);
                    rs      = rshsf10;
                    rsNm    = "h10";
                    break;

                case 6:
                    rshsf50 = calcAgFunction(rr, "h50", numCells);
                    rs      = rshsf50;
                    rsNm    = "h50";
                    break;

                default:
                    break;
                }
                cnt++;
                if (createinter && rsNm != "" && rs != null)
                {
                    rsUtil.saveRasterToDataset(rsUtil.createRaster(rs), rsNm, wks, rasterUtil.rasterType.IMAGINE);
                }
            }
        }
 private IRaster calcTopo()
 {
     IFunctionRasterDataset rsAspect = rsUtil.calcAspectFunction(demRs);
     IRemapFilter flt = new RemapFilterClass();
     if (useAspect)
     {
         flt.AddClass(225, 315, 3);
         flt.AddClass(315, 360, 0);
         flt.AddClass(0, 45, 0);
         flt.AddClass(45, 135, 2);
         flt.AddClass(135, 225, 2);
     }
     else
     {
         flt.AddClass(0, 361, 0);
     }
     IRaster rs2 = rsUtil.returnRaster(rsUtil.calcRemapFunction(rsAspect, flt));
     return rsUtil.returnRaster(rsUtil.calcArithmaticFunction(rs2, 10000, esriRasterArithmeticOperation.esriRasterMultiply));
 }
 private void btnExecute_Click(object sender, EventArgs e)
 {
     string rstNm = txtOutNm.Text;
     string rstIn = cmbInRaster1.Text;
     if (rstNm == null || rstNm == ""||rstIn==null||rstIn=="")
     {
         MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (dgvRanges.Rows.Count < 1)
     {
         MessageBox.Show("You must have at least on range of values selected", "No Ranges", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     IRemapFilter rfilt = new RemapFilterClass();
     for (int i = 0; i < dgvRanges.Rows.Count; i++)
     {
         object obj1 = dgvRanges[0, i].Value;
         object obj2 = dgvRanges[1, i].Value;
         object obj3 = dgvRanges[2, i].Value;
         if ( Convert.IsDBNull(obj1)) obj1 = 0;
         if (Convert.IsDBNull(obj2)) obj2 = 0;
         if (Convert.IsDBNull(obj3)) obj3 = 0;
         double min = System.Convert.ToDouble(obj1);
         double max = System.Convert.ToDouble(obj2);
         double vl = System.Convert.ToDouble(obj3);
         rfilt.AddClass(min,max,vl);
     }
     this.Visible = false;
     esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
     DateTime dt = DateTime.Now;
     rp.addMessage("Remapping Rasters. This may take a while...");
     rp.stepPGBar(10);
     rp.TopMost = true;
     try
     {
         outraster = rsUtil.returnRaster(rsUtil.calcRemapFunction(rstDic[rstIn],rfilt));
         if (mp != null && addToMap)
         {
             rp.addMessage("Calculating Statistics...");
             rp.Show();
             rp.Refresh();
             IRasterLayer rstLyr = new RasterLayerClass();
             //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
             rstLyr.CreateFromRaster(outraster);
             rstLyr.Name = rstNm;
             rstLyr.Visible = false;
             mp.AddLayer(rstLyr);
         }
         outrastername = rstNm;
         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 Remapping Rasters" + t);
         rp.enableClose();
         this.Close();
     }
 }
示例#10
0
        private void createPeriodRasters(int iterationNumber)
        {
            string rpFile = resultsDir + "\\Out_Int_RP_" + iterationNumber.ToString() + ".txt";
            List <HashSet <int> > pLst         = new List <HashSet <int> >();
            List <IRemapFilter>   remapFiltLst = new List <IRemapFilter>();

            for (int i = 1; i <= numPer; i++)
            {
                pLst.Add(new HashSet <int>());
                IRemapFilter flt = new RemapFilterClass();
                remapFiltLst.Add(flt);
            }
            using (System.IO.StreamReader sr = new System.IO.StreamReader(rpFile))
            {
                string ln = sr.ReadLine();
                while ((ln = sr.ReadLine()) != null)
                {
                    string[] lnArr = ln.Split(new char[] { '\t' });
                    if ((lnArr.Length) < 6)
                    {
                        break;
                    }
                    int period = System.Convert.ToInt32(lnArr[3]);
                    int id     = System.Convert.ToInt32(lnArr[0]);
                    if (period > 0)
                    {
                        HashSet <int> oLst = pLst[period - 1];
                        oLst.Add(id);
                        pLst[period - 1] = oLst;
                    }
                }
                sr.Close();
            }
            Dictionary <int, int> vlDic = rsUtil.buildVat(treatGrid);

            //IRasterInfo2 rsInfo2 = (IRasterInfo2)treatGrid.RasterInfo;
            //ITable rsVat = rsInfo2.AttributeTable;
            //if (rsVat == null)
            //{

            //}
            //ICursor cur = null;
            //cur = rsVat.Search(null, false);
            //int valueIndex = cur.FindField("Value");
            //IRow rw = cur.NextRow();
            //while (rw != null)
            foreach (int vl in vlDic.Keys)
            {
                for (int i = 1; i <= numPer; i++)
                {
                    IRemapFilter  fl  = remapFiltLst[i - 1];
                    HashSet <int> lst = pLst[i - 1];
                    int           nVl = 0;
                    if (lst.Contains(vl))
                    {
                        nVl = 1;
                        //Console.WriteLine("Add Value Remap Class = " + vl.ToString() + " to " + nVl.ToString());
                    }

                    fl.AddClass(vl, vl + 0.000001, nVl);
                }
            }
            periodRasterLst.Clear();
            for (int i = 1; i <= numPer; i++)
            {
                IRemapFilter flt = remapFiltLst[i - 1];

                IFunctionRasterDataset oRs = rsUtil.calcRemapFunction(treatGrid, flt);// reSampleRasterGrid(rsUtil.calcRemapFunction(treatGrid, flt));
                if (createinter)
                {
                    rsUtil.saveRasterToDataset(rsUtil.createRaster(oRs), "Treat_" + iterationNumber.ToString() + i.ToString(), wks, rasterUtil.rasterType.IMAGINE);
                }
                periodRasterLst.Add(oRs);
            }
        }
 private void calcRemap(string[] prmArr, out string name, out IRaster raster)
 {
     name = prmArr[0].Split(new char[] { '@' })[1];
     string inRaster1 = prmArr[2].Split(new char[] { '@' })[1];
     string remapVls = prmArr[1].Split(new char[] { '@' })[1];
     IRemapFilter flt = new RemapFilterClass();
     foreach(string s in remapVls.Split(new char[]{','}))
     {
         string[] sArr = s.Split(new char[] { '`' });
         double min = System.Convert.ToDouble(sArr[0]);
         double max = System.Convert.ToDouble(sArr[1]);
         double vl = System.Convert.ToDouble(sArr[2]);
         flt.AddClass(min, max, vl);
     }
     object rs1 = null;
     if (rsUtil.isNumeric(inRaster1))
     {
         rs1 = System.Convert.ToDouble(inRaster1);
     }
     else if (rstDic.ContainsKey(inRaster1))
     {
         rs1 = rstDic[inRaster1];
     }
     else
     {
         rs1 = inRaster1;
     }
     raster = rsUtil.createRaster(rsUtil.calcRemapFunction(rs1, flt));
 }
 private IFunctionRasterDataset createRemapFunction(string[] paramArr)
 {
     IFunctionRasterDataset inRaster = getRaster(paramArr[0]);
     IRemapFilter flt = new RemapFilterClass();
     foreach (string s in paramArr[1].Split(new char[] { ',' }))
     {
         double[] rVls = (from string s2 in (s.Split(new char[]{':'})) select System.Convert.ToDouble(s2)).ToArray();
         flt.AddClass(rVls[0], rVls[1], rVls[2]);
     }
     return rsUtil.calcRemapFunction(inRaster,flt);
 }
示例#13
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string rstNm = txtOutNm.Text;
            string rstIn = cmbInRaster1.Text;

            if (rstNm == null || rstNm == "" || rstIn == null || rstIn == "")
            {
                MessageBox.Show("You must specify a output name", "No Output", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (dgvRanges.Rows.Count < 1)
            {
                MessageBox.Show("You must have at least on range of values selected", "No Ranges", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRemapFilter rfilt = new RemapFilterClass();

            for (int i = 0; i < dgvRanges.Rows.Count; i++)
            {
                object obj1 = dgvRanges[0, i].Value;
                object obj2 = dgvRanges[1, i].Value;
                object obj3 = dgvRanges[2, i].Value;
                if (Convert.IsDBNull(obj1))
                {
                    obj1 = 0;
                }
                if (Convert.IsDBNull(obj2))
                {
                    obj2 = 0;
                }
                if (Convert.IsDBNull(obj3))
                {
                    obj3 = 0;
                }
                double min = System.Convert.ToDouble(obj1);
                double max = System.Convert.ToDouble(obj2);
                double vl  = System.Convert.ToDouble(obj3);
                rfilt.AddClass(min, max, vl);
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Remapping Rasters. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            try
            {
                outraster = rsUtil.returnRaster(rsUtil.calcRemapFunction(rstDic[rstIn], rfilt));
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Show();
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = rstNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = rstNm;
                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 Remapping Rasters" + t);
                rp.enableClose();
                this.Close();
            }
        }
 private IRaster rescaleHt()
 {
     IRasterBand rsBand = ((IRasterBandCollection)htRs).Item(0);
     IRasterStatistics rsStats = rsBand.Statistics;
     double min = rsStats.Minimum;
     double max = rsStats.Maximum;
     double range = (max - min);
     double step = range / HeightLevels;
     IRemapFilter flt = new RemapFilterClass();
     double cnt = 0;
     double i = 0;
     for (i = min; i < max; i += step)
     {
         double nMax = i + step;
         if (nMax == max)
         {
             nMax = max + 1;
         }
         flt.AddClass(i, nMax, cnt);
         cnt++;
     }
     IRaster rs2 = rsUtil.returnRaster(rsUtil.calcRemapFunction(htRs, flt));
     return rsUtil.returnRaster(rsUtil.calcArithmaticFunction(rs2, 1000000, esriRasterArithmeticOperation.esriRasterMultiply));
 }
        private void createSedimentSurfaces()
        {
            IWorkspace sedWks = geoUtil.OpenRasterWorkspace(sedDir);
            sedRaster = rsUtil.createIdentityRaster(sedRaster, rstPixelType.PT_FLOAT);
            IFeatureCursor ftrCur = ftrCls.Search(null, false);
            IFeature ftr = ftrCur.NextFeature();
            IRemapFilter fine10 = new RemapFilterClass();
            IRemapFilter fine50 = new RemapFilterClass();
            IRemapFilter t1fine10 = new RemapFilterClass();
            IRemapFilter t1fine50 = new RemapFilterClass();
            IRemapFilter hsf10 = new RemapFilterClass();
            IRemapFilter hsf50 = new RemapFilterClass();
            int fine10Index = ftrCls.FindField(f10fld);
            int fine50Index = ftrCls.FindField(f50fld);
            int t1fine10Index = ftrCls.FindField(t10fld);
            int t1fine50Index = ftrCls.FindField(t50fld);
            int hsf10Index = ftrCls.FindField(hsf10fld);
            int hsf50Index = ftrCls.FindField(hsf50fld);
            IRemapFilter[] remapArr = { fine10, fine50, t1fine10, t1fine50, hsf10, hsf50 };
            int[] fldArr = { fine10Index, fine50Index, t1fine10Index, t1fine50Index, hsf10Index, hsf50Index };
            int cnt = 0;
            int numCells = System.Convert.ToInt32(treatCellSize.X / cellSize);
            while (ftr != null)
            {
                //need to set up remap filters for each raster and create a new raster for each sediment value
                double oid = System.Convert.ToInt32(ftr.OID);
                cnt = 0;
                foreach (IRemapFilter remap in remapArr)
                {
                    int indexVl = fldArr[cnt];
                    double vl = System.Convert.ToDouble(ftr.get_Value(indexVl)) * (Math.Pow((cellSize * 3.2808399), 2) / 43560);
                    remap.AddClass(oid, oid + 0.00001, vl);
                    // Console.WriteLine("Converting oid " + oid.ToString() + " to " + vl.ToString() );
                    cnt++;
                }
                ftr = ftrCur.NextFeature();
            }
            cnt = 1;
            IFunctionRasterDataset[] rsArr = { rsfine10, rsfine50, rst1Fine10, rst1Fine50, rshsf10, rshsf50 };
            foreach (IRemapFilter remap in remapArr)
            {
                string rsNm = "";
                IFunctionRasterDataset rs = null;
                IFunctionRasterDataset rr = rsUtil.calcRemapFunction(sedRaster, remap);
                //IRaster xx = rsUtil.setnullToValueFunction(rr, 0);
                //IRaster rRs = rsUtil.returnRaster(rsUtil.saveRasterToDataset(xx, "xxx"+cnt.ToString(), tWks, rasterUtil.rasterType.IMAGINE));
                //IRaster rs = calcAgFunction(rr, numCells, rasterUtil.focalType.SUM);
                switch (cnt)
                {
                    case 1:
                        rsfine10 = calcAgFunction(rr, "n10", numCells);
                        rs = rsfine10;
                        rsNm = "n10";
                        break;
                    case 2:
                        rsfine50 = calcAgFunction(rr, "n50", numCells);
                        rs = rsfine50;
                        rsNm = "n50";
                        break;
                    case 3:
                        rst1Fine10 = calcAgFunction(rr,"t10", numCells);
                        rs = rst1Fine10;
                        rsNm = "t10";
                        break;
                    case 4:
                        rst1Fine50 = calcAgFunction(rr, "t50", numCells);
                        rs = rst1Fine50;
                        rsNm = "t50";
                        break;
                    case 5:
                        rshsf10 = calcAgFunction(rr, "h10", numCells);
                        rs = rshsf10;
                        rsNm = "h10";
                        break;
                    case 6:
                        rshsf50 = calcAgFunction(rr, "h50", numCells);
                        rs = rshsf50;
                        rsNm = "h50";
                        break;
                    default:
                        break;
                }
                cnt++;
                if (createinter && rsNm != "" && rs != null)
                {
                    rsUtil.saveRasterToDataset(rsUtil.createRaster(rs), rsNm, wks,rasterUtil.rasterType.IMAGINE);
                }

            }
        }
        private void createPeriodRasters(int iterationNumber)
        {
            string rpFile = resultsDir + "\\Out_Int_RP_" + iterationNumber.ToString() + ".txt";
            List<HashSet<int>> pLst = new List<HashSet<int>>();
            List<IRemapFilter> remapFiltLst = new List<IRemapFilter>();
            for (int i = 1; i <= numPer; i++)
            {
                pLst.Add(new HashSet<int>());
                IRemapFilter flt = new RemapFilterClass();
                remapFiltLst.Add(flt);
            }
            using(System.IO.StreamReader sr = new System.IO.StreamReader(rpFile))
            {
                string ln = sr.ReadLine();
                while((ln=sr.ReadLine())!=null)
                {
                    string[] lnArr = ln.Split(new char[]{'\t'});
                    if ((lnArr.Length) < 6) break;
                    int period = System.Convert.ToInt32(lnArr[3]);
                    int id = System.Convert.ToInt32(lnArr[0]);
                    if (period > 0)
                    {
                        HashSet<int> oLst = pLst[period-1];
                        oLst.Add(id);
                        pLst[period-1] = oLst;
                    }
                }
                sr.Close();
            }
            Dictionary<int, int> vlDic = rsUtil.buildVat(treatGrid);
            //IRasterInfo2 rsInfo2 = (IRasterInfo2)treatGrid.RasterInfo;
            //ITable rsVat = rsInfo2.AttributeTable;
            //if (rsVat == null)
            //{

            //}
            //ICursor cur = null;
            //cur = rsVat.Search(null, false);
            //int valueIndex = cur.FindField("Value");
            //IRow rw = cur.NextRow();
            //while (rw != null)
            foreach (int vl in vlDic.Keys)
            {
                for (int i = 1; i <= numPer; i++)
                {
                    IRemapFilter fl = remapFiltLst[i-1];
                    HashSet<int> lst = pLst[i-1];
                    int nVl = 0;
                    if (lst.Contains(vl))
                    {
                        nVl = 1;
                        //Console.WriteLine("Add Value Remap Class = " + vl.ToString() + " to " + nVl.ToString());
                    }

                    fl.AddClass(vl, vl + 0.000001, nVl);
                }
            }
            periodRasterLst.Clear();
            for (int i = 1; i <= numPer; i++)
            {
                IRemapFilter flt = remapFiltLst[i-1];

                IFunctionRasterDataset oRs = rsUtil.calcRemapFunction(treatGrid, flt);// reSampleRasterGrid(rsUtil.calcRemapFunction(treatGrid, flt));
                if (createinter)
                {
                    rsUtil.saveRasterToDataset(rsUtil.createRaster(oRs), "Treat_" + iterationNumber.ToString() + i.ToString(), wks,rasterUtil.rasterType.IMAGINE);
                }
                periodRasterLst.Add(oRs);
            }
        }
 private IFunctionRasterDataset createArivaltimeZones(IFunctionRasterDataset arrivalTime)
 {
     IRemapFilter arrivalRemap = new RemapFilterClass();
     IRasterStatistics rsStats = ((IRasterBandCollection)arrivalTime).Item(0).Statistics;
     if (rsStats == null)
     {
         rsUtil.calcStatsAndHist(arrivalTime);
         rsStats = ((IRasterBandCollection)arrivalTime).Item(0).Statistics;
     }
     else if (!rsStats.IsValid)
     {
         rsStats.SkipFactorX = 1;
         rsStats.SkipFactorY = 1;
         rsStats.Recalculate();
     }
     else
     {
     }
     double max = rsStats.Maximum;
     double min = rsStats.Minimum;
     double skip = 1;
     switch (arrCls)
     {
         case ArrivalClasses.Hours:
             skip = 60;
             break;
         case ArrivalClasses.Days:
             skip = 1440;
             break;
         default:
             break;
     }
     for (double i = 0; i <= max; i+= skip)
     {
         double nVl = (i + skip)/skip;
         arrivalRemap.AddClass(min, i + skip, nVl);
     }
     IFunctionRasterDataset reRs = rsUtil.calcRemapFunction(arrivalTime, arrivalRemap);
     return reRs;// reSampleRasterGrid(reRs);
 }