protected async Task DefineProjectionAsync(string CadFileName, SpatialReference SpatialRef, CancelableProgressorSource cps) { //GP Define Projection GPExecuteToolFlags flags = GPExecuteToolFlags.Default; // | GPExecuteToolFlags.GPThread; var parameters = Geoprocessing.MakeValueArray(CadFileName, SpatialRef.Wkt); await Geoprocessing.ExecuteToolAsync("management.DefineProjection", parameters, null, cps.Progressor, flags); }
public async Task <IGPResult> Execute_ApplySymbologyFromFeatureLayer() { var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true); var prj = Project.Current; var map = MapView.Active; var featLayers = map.Map.Layers.OfType <FeatureLayer>().Where(l => l.Name.StartsWith("Crimes", StringComparison.OrdinalIgnoreCase)); if (featLayers.Count() < 1) { MessageBox.Show("Unable to find Crimes layer: the topmost Crime layer is the target layer for the symbology, the symbology source is a lyrx file"); return(null); } // the first layer in TOC is without any symbology FeatureLayer targetLayer = featLayers.ElementAt(0); // the second layer has the symbology // symbology from the 2nd layer will be applied to the first layer //Create instance of BrowseProjectFilter using the id for Pro's Lyrx files filter BrowseProjectFilter bf = new BrowseProjectFilter("esri_browseDialogFilters_layers_lyrx"); //Display the filter in an Open Item dialog OpenItemDialog lyrxOpenDlg = new OpenItemDialog { Title = "Symbology Input Layer", MultiSelect = false, BrowseFilter = bf }; bool?ok = lyrxOpenDlg.ShowDialog(); if (!ok.HasValue || !ok.Value) { return(null); } // Full path for the lyrx file var lryxItem = lyrxOpenDlg.Items.FirstOrDefault().Path; var sourceField = "Major_Offense_Type"; var targetField = "Major_Offense_Type"; var fieldType = "VALUE_FIELD"; String fieldInfo = String.Format("{0} {1} {2}", fieldType, sourceField, targetField); // VALUE_FIELD NAME NAME") MessageBox.Show("Field Info for symbology: " + fieldInfo); var parameters = Geoprocessing.MakeValueArray(targetLayer, lryxItem, fieldInfo); //, symbologyFields, updateSymbology); // Does not Add outputs to Map as GPExecuteToolFlags.AddOutputsToMap is not used GPExecuteToolFlags executeFlags = GPExecuteToolFlags.RefreshProjectItems | GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory; IGPResult result = await Geoprocessing.ExecuteToolAsync("ApplySymbologyFromLayer_management", parameters, null, null, null, executeFlags); return(result); }
//The data referenced in this snippet can be downloaded from the arcgis-pro-sdk-community-samples repo //https://github.com/Esri/arcgis-pro-sdk-community-samples protected async Task <string> NonBlockingExecuteGP(EditingTemplate currentTemplate) { var valueArray = await QueuedTask.Run(() => { string in_data = @"C:\tools\data.gdb\cities"; string cities_buff = @"E:\data\data.gdb\cities_2km"; return(Geoprocessing.MakeValueArray(in_data, cities_buff, "2000 Meters")); }); // 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("Analysis.Buffer", valueArray, null, null, null, flags); return(string.IsNullOrEmpty(gpResult.ReturnValue) ? $@"Error in gp tool: {gpResult.ErrorMessages}" : $@"Ok: {gpResult.ReturnValue}"); }
// Snap Environment // Snap a line to polygon EDGE, END of another line and to points VERTEX // protected override async void OnClick() { GPExecuteToolFlags executeFlags = GPExecuteToolFlags.AddOutputsToMap | GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory; string toolName = "edit.Snap"; var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true); // make a copy of the input data - this data will be snapped to data specified in snap environment var inputFeatures = @"C:\\data\Snapping.gdb\otherline"; // snapEnvironment parameter is of ValueTable type var snapEnvironments = @"C:\\data\Snapping.gdb\poly EDGE '15 Meters';C:\\data\Snapping.gdb\line END '15 Meters';C:\\data\Snapping.gdb\points VERTEX '18 Meters'"; var parameters2 = Geoprocessing.MakeValueArray(inputFeatures, snapEnvironments); var gpResult = await Geoprocessing.ExecuteToolAsync(toolName, parameters2, environments, null, null, executeFlags); Geoprocessing.ShowMessageBox(gpResult.Messages, "GP Messages", gpResult.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default); }
public async Task <ProSuiteQAResponse> StartQAAsync(ProSuiteQARequest parameters) { var cts = new CancellationTokenSource(); var args = PrepareGPToolParameters(parameters, ProSuiteQAToolType.Xml); if (args == null) { return(new ProSuiteQAResponse() { Error = ProSuiteQAError.ServiceFailed }); } // background thread GPExecuteToolFlags flags = GPExecuteToolFlags.GPThread; // silent call of GP Server Toolbox var result = await Geoprocessing.ExecuteToolAsync(_toolpath, args, null, cts.Token, GPEventHandler, flags); return(FormatProSuiteResponse(result)); }
public async Task <IGPResult> ExecuteSnap() { var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true); string toolName = @"Snap_edit"; // Snap tool takes multiple inputs each of which has // Three (3) parts: a feature class or layer, a string value and a distance // Each part is separated by a semicolon - you can get example of sytax from the tool documentation page var snapEnv = @"'C:/SnapProject/fgdb.gdb/line_1' END '2 Meters';'C:/SnapProject/fgdb.gdb/points_1' VERTEX '1 Meters';'C:/SnapProject/fgdb.gdb/otherline_1' END '20 Meters'"; var parameters = await QueuedTask.Run(() => { var infc = @"C:/SnapProject/fgdb.gdb/poly_1"; return(Geoprocessing.MakeValueArray(infc, snapEnv)); }); GPExecuteToolFlags tokens = GPExecuteToolFlags.RefreshProjectItems | GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory; var gpResult = await Geoprocessing.ExecuteToolAsync(toolName, parameters, environments, null, null, flags : tokens); return(gpResult); }
public async Task <IGPResult> Execute_ApplySymbologyFromFeatureLayer() { var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true); var prj = Project.Current; var map = MapView.Active; if (map == null) { throw new Exception("No active map found!"); } var featLayers = map.Map.Layers.OfType <FeatureLayer>(); // the first layer in TOC is WITHOUT any symbology FeatureLayer targetLayer = featLayers.ElementAt(0); // the second layer HAS the symbology // symbology from the 2nd layer will be applied to the first layer FeatureLayer symbologyLayer = featLayers.ElementAt(1); // Make sure you have fields with the POP2000 name. var sourceField = "POP2000"; var targetField = "POP2000"; var fieldType = "VALUE_FIELD"; String fieldInfo = String.Format("{0} {1} {2}", fieldType, sourceField, targetField); // VALUE_FIELD NAME NAME") MessageBox.Show(fieldInfo); var parameters = Geoprocessing.MakeValueArray(targetLayer, symbologyLayer, fieldInfo); //, symbologyFields, updateSymbology); // Does not Add outputs to Map as GPExecuteToolFlags.AddOutputsToMap is not used GPExecuteToolFlags executeFlags = GPExecuteToolFlags.RefreshProjectItems | GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory; IGPResult result = await Geoprocessing.ExecuteToolAsync("ApplySymbologyFromLayer_management", parameters, null, null, null, executeFlags); return(result); }