I am trying to create a simple Add-In tool that will allow users to select features from a feature layer, clip the selected features and merge them together. For example, if there is a shapefile of all the counties in California and the user wants to clip and merge their study area from this county shapefile by selecting two counties as their study area. I am relatively new to ArcGIS Pro SDK and add-in. I am not sure if I am declaring the intermediate, clipped feature layer, clipArea and new, merged feature layer, new_fc correctly. Just curious, when would you use "//await mergeFeatures.ExecuteAsync()"? The indentation is not correctly shown below. Thanks for your help!
namespace ArcGISPro_Mapping_Apps
{
internal class SelectFeature : MapTool
{
public SelectFeature()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Polygon;
SketchOutputMode = SketchOutputMode.Screen;
}
protected override Task OnToolActivateAsync(bool active)
{
return base.OnToolActivateAsync(active);
}
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
QueuedTask.Run(() => {
var selection = MapView.Active.SelectFeatures(geometry);
var editOp = new EditOperation();
var clipArea = MapView.Active.Map.GetLayerAsFlattenedList().First(1 => 1.Name == "Area_clip");
var new_fc = MapView.Active.Map.GetLayerAsFlattenedList().First(1 => 1.Name == "StudyArea_merge");
var oid = -1;
Geometry clippedGeometry = GeometryEngine.Instance.Clip(geometry, clippedDistance);
editOp.Name = "clip and merge features";
editOp.Clip(selection, oid, clipArea, ClipMode.PreserveArea);
editOp.Merge(clipArea, new_fc, new List<long>() { 10, 96, 12 });
// Execute the edit operation
editOp.ExecuteAsync();
//await mergeFeatures.ExecuteAsync();
MessageBox.Show("Study area has been clipped successfully.");
return true;
});
}
}
}