private void btnCreateSamples_Click(object sender, EventArgs e) { string rst = cmbRst.Text; string oWks = txtOutWorkspace.Text; string sNm = txtSampleName.Text; string mPath = txtSampleSize.Text; int[] numSample = null; double prop = System.Convert.ToDouble(nudProp.Value); double alpha = System.Convert.ToDouble(nudAlpha.Value); if (rsUtil.isNumeric(mPath)) { numSample = new int[] { System.Convert.ToInt32(mPath) }; } else { numSample = esriUtil.Statistics.dataPrepSampleSize.sampleSizeMaxCluster(mPath, prop, alpha); } if (rst == null || rst == "" || oWks == null || oWks == "") { MessageBox.Show("You must specify a raster, an output workspace, and a output file name!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } bool rsCheck = false; if (rstDic.Keys.Contains(rst)) { rsCheck = true; } this.Visible = false; this.Refresh(); RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false); rp.Show(); rp.stepPGBar(20); DateTime ds1 = DateTime.Now; try { IFeatureClass ftrCls = null; if (strata) { if (rsCheck) { IFunctionRasterDataset rs = rstDic[rst]; rp.addMessage("Creating random stratified sample. This could take a while..."); rp.stepPGBar(10); rp.Refresh(); ftrCls = rsUtil.createRandomSampleLocationsByClass(geoUtil.OpenWorkSpace(oWks), rs, numSample, 1, sNm); } else { rp.addMessage("Cannot create stratified random sample for feature class. Use raster instead!"); } } else { rp.addMessage("Creating random sample. This could take a while..."); rp.stepPGBar(10); rp.Refresh(); if (rsCheck) { IFunctionRasterDataset rs = rstDic[rst]; ftrCls = rsUtil.createRandomSampleLocations(geoUtil.OpenWorkSpace(oWks), rs, numSample[0], sNm); } else { IFeatureClass inFtrCls = ftrDic[rst]; ftrCls = frmHlp.FeatureUtility.createRandomSample(inFtrCls, numSample[0], oWks + "\\" + sNm); } } if (mp != null) { rp.addMessage("Adding Samples to the map"); rp.stepPGBar(20); rp.Refresh(); IFeatureLayer fLyer = new FeatureLayerClass(); fLyer.FeatureClass = ftrCls; fLyer.Name = sNm; fLyer.Visible = true; mp.AddLayer(fLyer); } } catch (Exception ex) { rp.addMessage(ex.ToString()); } finally { DateTime ds2 = DateTime.Now; TimeSpan ts = ds2.Subtract(ds1); rp.stepPGBar(100); string tsSpan = "Process took a total of " + ts.TotalMinutes.ToString() + " minutes to finish"; rp.addMessage("Finished creating samples"); rp.addMessage(tsSpan); rp.enableClose(); //rp.TopLevel = false; this.Close(); } }