Example #1
0
        private void btnClip_Click(object sender, EventArgs e)
        {
            string rstNm = cmbInRaster1.Text;
            int    sk    = System.Convert.ToInt32(nudSkip.Value);

            if (rstNm == "" || rstNm == null)
            {
                MessageBox.Show("You must have a raster layer selected and a pixel type selected", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Calculating Statistics. This may take a while...");
            rp.Show();
            rp.stepPGBar(10);
            rp.TopMost = true;
            try
            {
                IRaster rst = rstDic[rstNm];
                outraster = rsUtil.calcStatsAndHist(rst, sk);
                if (mp != null && addToMap)
                {
                    rp.Refresh();
                    for (int i = 0; i < mp.LayerCount; i++)
                    {
                        ILayer ly = mp.get_Layer(i);
                        if (ly.Name == rstNm)
                        {
                            mp.DeleteLayer(ly);
                        }
                    }
                    IRasterLayer rstLyr = new RasterLayerClass();
                    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 Calculating Statistics" + t);
                rp.enableClose();
                this.Close();
            }
        }
Example #2
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);
        }