diff --git a/ProWindow1.xaml.cs b/ProWindow1.xaml.cs index e423d31..10d2733 100644 --- a/ProWindow1.xaml.cs +++ b/ProWindow1.xaml.cs @@ -21,7 +21,7 @@ using ArcGIS.Desktop.Framework.Threading.Tasks; using ArcGIS.Core.Data; using ArcGIS.Desktop.Core; using ArcGIS.Desktop.Editing; - +using ArcGIS.Desktop.Internal.Layouts.Utilities; namespace PruebaAddIn { @@ -59,54 +59,75 @@ namespace PruebaAddIn return Geoprocessing.MakeValueArray(inlayers, outpath); });*/ + EditOperation op = new EditOperation(); + 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); - + //management.CreateFeatureClass + FeatureClass featureClass_out= fileGeodatabase. + using (FeatureClass featureClass = fileGeodatabase.OpenDataset("prueba")) + { + FeatureClassDefinition facilitySiteDefinition = featureClass.GetDefinition(); + featureClass_out.CopyFrom(featureClass); + featureClass_out.DeleteRows(null); + //int facilityIdIndex = facilitySiteDefinition.FindField("TIPO_ENT"); + string whereClause = "NOM_TIPO_ENTIDAD = 'Aceras'"; + //Selection sel = featureClass.Select(new QueryFilter { WhereClause = whereClause }, SelectionType.ObjectID, SelectionOption.Normal); + //FeatureClass featSel = sel as FeatureClass; + //IReadOnlyList selectedOIDs = sel.GetObjectIDs(); + Row row; + Feature feat; + using (RowCursor rowCursor = featureClass.Search(new QueryFilter { WhereClause = whereClause })) + { + while (rowCursor.MoveNext()) + { + using (row = rowCursor.Current) + { + feat = row as Feature; + featureClass_out + } + } + } + + 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; + } } - - 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; - } } }