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(); } }