Example #1
0
 public void Bind(object pArgument)
 {
     if (pArgument is clipFunctionArgument)
     {
         clipFunctionArgument args = (clipFunctionArgument)pArgument;
         inrs        = args.InRaster;
         outrs       = args.OutRaster;
         noDataValue = ((System.Array)((IRasterProps)outrs).NoDataValue).GetValue(0);
         geo         = args.Geometry;
         cType       = args.ClipType;
         myFunctionHelper.Bind(outrs);
         myRasterInfo = myFunctionHelper.RasterInfo;
         myPixeltype  = myRasterInfo.PixelType;
         myValidFlag  = true;
     }
     else
     {
         throw new System.Exception("Incorrect arguments object. Expected: clipFunctonArguments");
     }
 }
 public void Bind(object pArgument)
 {
     if (pArgument is clipFunctionArgument)
     {
         clipFunctionArgument args = (clipFunctionArgument)pArgument;
         inrs = args.InRaster;
         outrs = args.OutRaster;
         noDataValue = ((System.Array)((IRasterProps)outrs).NoDataValue).GetValue(0);
         geo = args.Geometry;
         cType = args.ClipType;
         myFunctionHelper.Bind(outrs);
         myRasterInfo = myFunctionHelper.RasterInfo;
         myPixeltype = myRasterInfo.PixelType;
         myValidFlag = true;
     }
     else
     {
         throw new System.Exception("Incorrect arguments object. Expected: clipFunctonArguments");
     }
 }
Example #3
0
        private void btnClip_Click(object sender, EventArgs e)
        {
            string ftrNm   = cmbSampleFeatureClass.Text;
            string rstNm   = cmbRaster.Text;
            string outNm   = txtOutRasterName.Text;
            bool   chErase = chbErase.Checked;
            esriRasterClippingType clType = esriRasterClippingType.esriRasterClippingOutside;

            if (ftrNm == "" || ftrNm == null || rstNm == "" || rstNm == null)
            {
                MessageBox.Show("You must have a polygon and raster layer selected", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNm == "" || outNm == null)
            {
                MessageBox.Show("You must specify an output raster name", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (chErase)
            {
                clType = esriRasterClippingType.esriRasterClippingInside;
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Clipping Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                IRaster                rst       = rstDic[rstNm];
                IFeatureClass          ftrCls    = ftrDic[ftrNm];
                IGeometry              geo       = geoUtil.createGeometry(ftrCls);
                IFunctionRasterDataset outraster = rsUtil.clipRasterFunction(rst, geo, clType);
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");
                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromDataset((IRasterDataset)outraster);
                    rstLyr.Name    = outNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = outNm;
                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 Clipping Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
 /// <summary>
 /// Clips a raster to the boundary of a polygon
 /// </summary>
 /// <param name="inRaster">IRaster, IRasterDataset, or string</param>
 /// <param name="geo">Polygon Geometry</param>
 /// <param name="clipType">the type of clip either inside or outside</param>
 /// <returns></returns>
 public IFunctionRasterDataset clipRasterFunction(object inRaster, IGeometry geo, esriRasterClippingType clipType)
 {
     IFunctionRasterDataset rRst = createIdentityRaster(inRaster);
     IRaster2 rRst2 = (IRaster2)createRaster(rRst);
     string tempAr = funcDir + "\\" + FuncCnt + ".afr";
     IFunctionRasterDataset frDset = new FunctionRasterDatasetClass();
     IFunctionRasterDatasetName frDsetName = new FunctionRasterDatasetNameClass();
     frDsetName.FullName = tempAr;
     frDset.FullName = (IName)frDsetName;
     IRasterFunction rsFunc = new ClipFunctionClass();
     IEnvelope env = geo.Envelope;
     double hX = rRst.RasterInfo.CellSize.X / 2;
     double hY = rRst.RasterInfo.CellSize.Y / 2;
     double xMin = env.XMin;
     double xMax = env.XMax;
     double yMin = env.YMin;
     double yMax = env.YMax;
     int clm, rw;
     rRst2.MapToPixel(xMin, yMin,out clm,out rw);
     rRst2.PixelToMap(clm, rw, out xMin, out yMin);
     xMin = xMin - hX;
     yMin = yMin - hY;
     rRst2.MapToPixel(xMax, yMax, out clm, out rw);
     rRst2.PixelToMap(clm, rw, out xMax, out yMax);
     xMax = xMax + hX;
     yMax = yMax + hY;
     env.PutCoords(xMin, yMin, xMax, yMax);
     IClipFunctionArguments args = new ClipFunctionArgumentsClass();
     args.Extent = env;
     args.ClippingGeometry = geo;
     args.ClippingType = clipType;
     args.Raster = rRst;
     frDset.Init(rsFunc, args);
     return frDset;
 }