Multi Ring Buffer

2189
2
02-02-2018 03:50 AM
SamanthaHughes
New Contributor

Hi all,

Creating a multi ring buffer tool - it doesn't seem to be presenting with the layer at the end?

Has anyone else had this? Does anyone have a working example they can share?

I have even gone back to the basic buffer example in the samples and amended the two lines of code and I still get no layer:

 protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
 {
 var valueArray = await QueuedTask.Run(() =>
 {
 var g = new List<object>() { geometry, }; 
 return Geoprocessing.MakeValueArray(g,"C:\ArcGIS\Projects\MyProject1\MyProject1.gdb\Annotation",@"500,1000,2000","Meters","Distance","All","None");
 });
await Geoprocessing.ExecuteToolAsync("Analysis.MultipleRingBuffer", valueArray); 
return true;
 }

I have tried this in the new 2.1 SDK also to no avail.

I have a sneaky suspicion it has something to do with the buffer value syntax. Annotation is a feature class for polygons. 

Buffer works absolutely fine and I have got it working in arcpy. However I want the user to be able to use the cursor to pick a point on the screen rather than have a feature class with points in to "multibuffer".

TIA

0 Kudos
2 Replies
NarelleChedzey
Esri Contributor

Hi Samantha, 

As you guessed, your syntax for the MultipleRingBuffer tool is not completely correct.   Here's a quick way to work out the correct syntax when you get stuck.    

Run the tool in Pro over a sample dataset with the required parameters.  Then go to the History tab in the Catalog window and hover over the GP tool that you submitted. 

You can see that the Distances are separated by semi-colons rather than commas.  And the final parameter should be OUTSIDE_ONLY or FULL.    You can also see a lot of this information by looking at the syntax section of help page for the tool   (Multiple Ring Buffer—Help | ArcGIS Desktop).  

Thus your example should look something like this. 

protected override async void OnClick()

{

  var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();

  var valueArray = await QueuedTask.Run(() =>

  {

     return Geoprocessing.MakeValueArray(featureLayer, @"D:\Data\Anno\SampleAnno.gdb\SampleAnno_MultipleRingBuffer3", @"50;100;150", "Meters", "distance", "All", "FULL");

  });

  await Geoprocessing.ExecuteToolAsync("Analysis.MultipleRingBuffer", valueArray);

}

With regards to your last statement about wanting the user to be able to pick a point on the screen rather than a feature class with points, that is not possible.   Again looking at the syntax section on the help page for the tool you can see that the first parameter must be of type FeatureLayer;  meaning that the tool will only accept existing features in a featurelayer or a selection set of features in a featurelayer.   You can use the sketch geometry to select existing features in the appropriate layer before calling the tool but you cannot pass a geometry itself. 

Hope this helps. 

Narelle

Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Samantha,

 I tried this as well and came up with a solution that works.  The problem was in the parameters that the tool supports.  In essence the first parameter turns out to be a 'map member'.  In essence Mapmember is a feature layer in your active map.  In my sample I am still using the construction tool to add a point (line or polygon).  I am using the 'CurrentTemplate' property of the MapTool base class to get the MapMember for which I just added my point (adding a new construction tool gives you the code for adding a new feature out-of-box for that).  After the point has been added to the feature class (make sure it's an empty feature class) I call the code snippet below to add the rings.  If you run the Multiple Ring Buffer tool manually and you add a simple point, you will see (via the content pane) that the GP tool create and then added a new Mapmember to you map's content.

  

It then uses the scratch feature class that as the input for the tool.  Also some of your other parameters needed some adjustment as well.  The sample below also shows how to view the result message (or errors).

protected async Task<string> CreateRings(EditingTemplate currentTemplate)
{
     var valueArray = await QueuedTask.Run(() =>
     {
          return Geoprocessing.MakeValueArray(currentTemplate.MapMember.Name, 
               @"C:\Data\FeatureTest\FeatureTest.gdb\Points_MultipleRingBuffer",
               new List<string> { "1000", "2000" }, "Meters", "Distance", 
               "ALL", "FULL");
     });
     IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("Analysis.MultipleRingBuffer", valueArray);
     return string.IsNullOrEmpty(gpResult.ReturnValue)
          ? $@"Error in gp tool: {gpResult.ErrorMessages}" 
          : $@"Ok: {gpResult.ReturnValue}";
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I used the sample snippet on the sample data 'FeatureTest' and got this result:

0 Kudos