using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using ArcGIS.Core.Geometry; using ArcGIS.Desktop.Core.Geoprocessing; using ArcGIS.Desktop.Mapping; using ArcGIS.Desktop.Framework.Threading.Tasks; using ArcGIS.Core.Data; using ArcGIS.Desktop.Core; using ArcGIS.Desktop.Editing; namespace PruebaAddIn { /// /// Interaction logic for ProWindow1.xaml /// public partial class ProWindow1 : ArcGIS.Desktop.Framework.Controls.ProWindow { public ProWindow1() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { string layerpath, outpath; layerpath = "D:\\Proyectos\\Olivia\\Datos\\gdbs\\Soria.gdb\\prueba"; outpath = "D:\\Proyectos\\Olivia\\Pruebas"; //layerpath = @"Z:\Europe.gdb\Streets"; //layerpath = @"C:\Users\narvaling_epareja\Documents\ArcGIS\Projects\MyProject\MyProject.gdb\SanLorenzo"; //outpath = @"C:\Users\narvaling_epareja\Documents\PruebasOlivia"; ConvertShp(layerpath, outpath); } protected async Task ConvertShp(string layerpath, string outpath) { if (!System.IO.Directory.Exists(outpath)) System.IO.Directory.CreateDirectory(outpath); /*var valueArray = await QueuedTask.Run(() => { //input layers list should contain the path of each layer name, i.e. if the root node is "Mapping" and the layer name is "gs_points", path is "Mapping\\gs_points". List inlayers = new List(); inlayers.Add(layerpath); //outpath is just the folder to save the shapefiles in return Geoprocessing.MakeValueArray(inlayers, outpath); });*/ using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("D:\\Proyectos\\Olivia\\Datos\\gdbs\\Soria.gdb")))) using (FeatureClass featureClass = fileGeodatabase.OpenDataset("prueba")) { //FeatureClassDefinition facilitySiteDefinition = featureClass.GetDefinition(); //int facilityIdIndex = facilitySiteDefinition.FindField("TIPO_ENT"); string whereClause = "NOM_TIPO_ENTIDAD = 'Aceras'"; Selection sel = featureClass.Select(new QueryFilter { WhereClause = whereClause }, SelectionType.ObjectID, SelectionOption.Normal); } var progDlg = new ProgressDialog("Running Geoprocessing Tool", "Cancel", 100, true); progDlg.Show(); var progSrc = new CancelableProgressorSource(progDlg); // prepare input parameter values to CopyFeatures tool string input_data = layerpath; //string out_workspace = ArcGIS.Desktop.Core.Project.Current.DefaultGeodatabasePath; string out_data = outpath; // make a value array of strings to be passed to ExecuteToolAsync var parameters = Geoprocessing.MakeValueArray(input_data, out_data); // execute the tool IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("FeatureClassToShapefile_conversion", parameters, null, new CancelableProgressorSource(progDlg).Progressor, GPExecuteToolFlags.Default); // dialog hides itself once the execution is complete //progDlg.Hide(); /*//input layers list should contain the path of each layer name, i.e. if the root node is "Mapping" and the layer name is "gs_points", path is "Mapping\\gs_points". List inlayers = new List(); inlayers.Add(layerpath); //outpath is just the folder to save the shapefiles in var valueArray = Geoprocessing.MakeValueArray(inlayers, outpath); // to let the GP tool run asynchronously without blocking the main thread // use the GPThread option of GPExecuteToolFlasgs // GPExecuteToolFlags flags = GPExecuteToolFlags.GPThread; // instruct the tool run non-blocking GPThread IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("FeatureClassToShapefile_conversion", valueArray, null, null, null, flags);*/ string res = string.IsNullOrEmpty(gpResult.ReturnValue) ? $@"Error in gp tool: {gpResult.ErrorMessages}" : $@"Ok: {gpResult.ReturnValue}"; return res; } } }