You will learn: how to create an ArcGIS Pro feature construction tool.
With the ArcGIS Pro SDK for .NET, you can extend ArcGIS Pro with your own unique tools and workflows. Using Microsoft Visual Studio and the Pro SDK, developers can build Pro add-ins and configurations that provide users with custom functionality specific to their organization or industry.
The Pro SDK provides a construction tool template which goes beyond a map tool to assist in your creating a new tool, with placeholders for your own feature construction code.
In this tutorial, you will use C# to create a new polygon feature construction tool which creates the polygon with a buffer distance which you specify.
Start Visual Studio.
Choose File > New > Project and then from ArcGIS templates group, select ArcGIS Pro Module Add-in. Name the add-in project "ConstructionTool".
Right click the project and choose Add > New Item and then from the ArcGIS Pro Add-ins group select ArcGIS Pro Construction Tool from the list of item templates. Name the new class file "BufferPolygonTool.cs" and press Add to close the dialog box.
Open the Config.daml
file and modify the tool item as follows:
<tool id="ConstructionTool_BufferPolygonTool"
categoryRefID="esri_editing_construction_polygon"
caption="Create Buffer Polygon"
className="BufferPolygonTool"
loadOnClick="true"
smallImage="Images\GenericButtonRed16.png"
largeImage="Images\GenericButtonRed32.png">
<tooltip heading="Create Buffer Polygon"> Create polygon with a buffer distance.<disabledText /></tooltip>
</tool>
Open the BufferPolygonTool.cs
file and modify the BufferCircleTool
constructor method as follows:
public BufferCircleTool()
{
IsSketchTool = true;
UseSnapping = true;
// SketchType = SketchGeometryType.Point;
// SketchType = SketchGeometryType.Line;
SketchType = SketchGeometryType.Polygon;
}
Modify the OnSketchCompleteAsync
method as follows:
private double BufferDistance = 200;
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
if (CurrentTemplate == null || geometry == null)
return Task.FromResult(false);
Geometry bufferedGeometry = GeometryEngine.Instance.Buffer(geometry, BufferDistance);
// Create an edit operation
var createOperation = new EditOperation();
createOperation.Name = string.Format("Create {0}", CurrentTemplate.Layer.Name);
createOperation.SelectNewFeatures = true;
// Queue feature creation
createOperation.Create(CurrentTemplate, bufferedGeometry);
// Execute the operation
return createOperation.ExecuteAsync();
}
Rebuild your solution and fix any compilation errors. Click Start to begin debugging which will start ArcGIS Pro.
In the Create Features pane, review the list of available feature layers and then click on the symbol for TestPolygons to display the list of feature construction tools below it. The last tool on the bottom right, which should be visible as a small red button, is your new construction tool.
Config.daml
is working.Compare your solution with our completed solution project.
Read more information about feature editing and construction in the ProConcepts Editing document, and also review the ProGuide on building construction tools with options.
Download and try the community sample ConstructionToolWithOptions referenced in the ProGuide above.
Review the Pro SDK API reference and find the EditOperation
class for more information, methods and additional behavior.