private void btnUygula_Click(object sender, EventArgs e) { if (cmbXColumn.SelectedIndex < 0) { MessageBox.Show("X değeri belirlenmeden işlem yapılamaz."); return; } if (cmbYColumn.SelectedIndex < 0) { MessageBox.Show("Y değeri belirlenmeden işlem yapılamaz."); return; } AppSingleton.Instance().CreateWorkspacePath(); var name = Path.GetFileNameWithoutExtension(txtExcel.Text); ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); ESRI.ArcGIS.ConversionTools.ExcelToTable excelToTable = new ESRI.ArcGIS.ConversionTools.ExcelToTable(); excelToTable.Input_Excel_File = txtExcel.Text; excelToTable.Output_Table = AppSingleton.Instance().WorkspacePath + "\\" + name; gp.AddOutputsToMap = AppSingleton.Instance().AralariEkle; gp.OverwriteOutput = true; gp.Execute(excelToTable, null); ESRI.ArcGIS.DataManagementTools.MakeXYEventLayer makeLayer = new ESRI.ArcGIS.DataManagementTools.MakeXYEventLayer(); makeLayer.table = excelToTable.Output_Table; makeLayer.in_x_field = cmbXColumn.SelectedItem.ToString(); makeLayer.in_y_field = cmbYColumn.SelectedItem.ToString(); makeLayer.out_layer = excelToTable.Output_Table + "_layer"; makeLayer.spatial_reference = "WGS 1984"; gp.AddOutputsToMap = true; gp.OverwriteOutput = true; gp.Execute(makeLayer, null); }
private void TransForm(string Inputfile, string Output, string outputPath) { //构造Geoprocessor Geoprocessor gp = new Geoprocessor(); string path = Path.GetDirectoryName(Output); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } try { ESRI.ArcGIS.DataManagementTools.MakeXYEventLayer step1 = new ESRI.ArcGIS.DataManagementTools.MakeXYEventLayer(); step1.table = Inputfile + "\\Sheet1$";//textBox1.Text.ToString() + "\\xy.xls\\Sheet1$"; step1.in_x_field = txbX.Text.ToString(); step1.in_y_field = txbY.Text.ToString(); RunTool(gp, step1, null); Console.WriteLine(Inputfile); //Console.WriteLine("MakeXYEventLayer:添加点数据"); ESRI.ArcGIS.DataManagementTools.PointsToLine step2 = new ESRI.ArcGIS.DataManagementTools.PointsToLine(); step2.Input_Features = step1.out_layer; step2.Output_Feature_Class = outputPath + "\\temp.shp";//@"C:\Users\Yayu.Jiang\Desktop\output\temp.shp"; RunTool(gp, step2, null); //Console.WriteLine("PointsToLine:点转线"); ESRI.ArcGIS.DataManagementTools.FeatureToPolygon step3 = new ESRI.ArcGIS.DataManagementTools.FeatureToPolygon(); step3.in_features = step2.Output_Feature_Class; step3.out_feature_class = Output;//@"C:\Users\Yayu.Jiang\Desktop\output\xy.shp"; RunTool(gp, step3, null); //Console.WriteLine("FeatureToPolygon:要素转面"); ESRI.ArcGIS.DataManagementTools.CalculateField calculateField = new ESRI.ArcGIS.DataManagementTools.CalculateField(); calculateField.in_table = Output; calculateField.field = "ID"; //calculateField.expression = "5"; calculateField.expression = Path.GetFileNameWithoutExtension(Output); calculateField.expression_type = "VB"; RunTool(gp, calculateField, null); //Console.WriteLine("CalculateField:填充ID字段"); ESRI.ArcGIS.DataManagementTools.AddField addField = new ESRI.ArcGIS.DataManagementTools.AddField(); addField.in_table = Output; addField.field_name = "YSBH"; addField.field_type = "TEXT"; addField.field_length = 50; RunTool(gp, addField, null); //Console.WriteLine("AddField:添加字段YSBH"); string[] foldName = Inputfile.Split('\\'); calculateField.in_table = addField.out_table; calculateField.field = "YSBH"; calculateField.expression_type = "VB"; calculateField.expression = "\"" + foldName[foldName.Length - 2] + "\""; //calculateField.expression = "\"aaa\""; RunTool(gp, calculateField, null); //Console.WriteLine("CalculateField:填充字段YSBH"); #region 添加字段 for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; string[] fields = { dr["fields"].ToString(), dr["types"].ToString(), dr["length"].ToString() }; addField.field_name = fields[0]; addField.field_type = fields[1]; if (fields[1] == "TEXT") { addField.field_length = Convert.ToInt32(fields[2]); } RunTool(gp, addField, null); //Console.WriteLine("AddField:添加字段" + dr["fields"].ToString()); } #endregion } catch (Exception ex) { throw ex; } }