private void ToolStripMenuItem_RepairGeometry_Click(object sender, EventArgs e) { if (this.lstBox_Files.Items.Count <= 0) { return; } Cursor.Current = Cursors.WaitCursor; this.ChangeStatus(false); try { string path = string.Empty; string logPath = Path.Combine(GlobalVar.LogPath, string.Format("Repair_{0}.txt", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss.ss"))); using (StreamWriter sw = new StreamWriter(logPath, true)) { Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true; RepairGeometry rg = new RepairGeometry(); foreach (var item in this.lstBox_Files.Items) { if (item == null) { continue; } path = item.ToString(); if (!File.Exists(path)) { continue; } rg.in_features = path; IGeoProcessorResult2 result = SpatialAnalysisHelper.RunGeoProcessor(gp, rg, null); string resStr = SpatialAnalysisHelper.GetMessages(result); sw.WriteLine(resStr); sw.Flush(); this.txtbox_log.Text += resStr + "\r\n"; this.txtbox_log.SelectionStart = this.txtbox_log.Text.Length; this.txtbox_log.ScrollToCaret(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.ChangeStatus(true); Cursor.Current = Cursors.Default; } }
private void ClipFeatures(string clipFromLayer, string clipFeatureLayer, string outFeatureClassName) { int numTrys = 0; ESRI.ArcGIS.AnalysisTools.Clip c = new ESRI.ArcGIS.AnalysisTools.Clip(); c.in_features = clipFromLayer; c.clip_features = clipFeatureLayer; c.cluster_tolerance = "0.001 meters"; c.out_feature_class = outFeatureClassName; while (numTrys <= 10) { if (numTrys == 10) { //System.Windows.Forms.MessageBox.Show("Tried clip 10 times and failed"); } else { if (RunProcess(c, null)) { mLog.Debug("Passed clip features after " + (numTrys + 1).ToString() + " trys"); numTrys = 999; } else { numTrys++; mLog.Debug("****************************Failed dissolve " + numTrys + " times"); mLog.Debug("Attempting repair geometry of clipFromLayer"); RepairGeometry r = new RepairGeometry(); r.in_features = clipFromLayer; RunProcess(r, null); mLog.Debug("Attempting repair geometry of clipFeatureLayer"); RepairGeometry r2 = new RepairGeometry(); r2.in_features = clipFeatureLayer; RunProcess(r2, null); mLog.Debug("Reseting geoprocessor"); myProcessor = null; myProcessor = new Geoprocessor(); } } } }
private void DissolveFeatures(string layerName, string outName, string fieldName) { int numTrys = 0; Dissolve d = new Dissolve(); d.in_features = layerName; d.out_feature_class = outName; d.dissolve_field = fieldName as object; d.multi_part = "SINGLE_PART"; while (numTrys <= 10) { if (numTrys == 10) { //System.Windows.Forms.MessageBox.Show("Tried dissolve 10 times and failed"); //Infinite loop } else { if (RunProcess(d, null)) { mLog.Debug("Passed dissolve features after " + (numTrys + 1).ToString() + " trys"); numTrys = 999; } else { numTrys++; mLog.Debug("****************************Failed dissolve " + numTrys + " times"); mLog.Debug("Attempting repair geometry"); RepairGeometry r = new RepairGeometry(); r.in_features = layerName; RunProcess(r, null); mLog.Debug("Reseting geoprocessor"); myProcessor = null; myProcessor = new Geoprocessor(); } } } }
private void ToolStripMenuItem_RepairGeometry_Click(object sender, EventArgs e) { if (this.lstBox_Files.Items.Count <= 0) return; Cursor.Current = Cursors.WaitCursor; this.ChangeStatus(false); try { string path = string.Empty; string logPath = Path.Combine(GlobalVar.LogPath, string.Format("Repair_{0}.txt", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss.ss"))); using (StreamWriter sw = new StreamWriter(logPath, true)) { Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true; RepairGeometry rg = new RepairGeometry(); foreach (var item in this.lstBox_Files.Items) { if (item == null) continue; path = item.ToString(); if (!File.Exists(path)) continue; rg.in_features = path; IGeoProcessorResult2 result = SpatialAnalysisHelper.RunGeoProcessor(gp, rg, null); string resStr = SpatialAnalysisHelper.GetMessages(result); sw.WriteLine(resStr); sw.Flush(); this.txtbox_log.Text += resStr + "\r\n"; this.txtbox_log.SelectionStart = this.txtbox_log.Text.Length; this.txtbox_log.ScrollToCaret(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.ChangeStatus(true); Cursor.Current = Cursors.Default; } }