This tutorial demonstrates 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 solution configurations that provide users with custom functionality specific to their organization or industry.
The Pro SDK provides a construction tool template that goes beyond a map tool to assist developers 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 a polygon with a buffer distance of your specification.
Prerequisites
- Microsoft Visual Studio is required. See the ArcGIS Pro system requirements for latest version and compatibility.
- Install ArcGIS Pro version 3.3 or higher.
- Install the ArcGIS Pro SDK for .NET. See the Installation ProGuide for more information.
- This tutorial uses Pro SDK Community sample data.
Steps
Create a new ArcGIS Pro Add-In Visual Studio Project
-
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".
By default, the
Config.damlfile opens in Visual Studio. TheModule1.csfile contains add-in module code.Note also in the
Config.damlfile that theidattribute of theinserttag matches the ID within theModule Module1.csfile and theclassattribute also matches the class name of the module.Name To find the ArcGIS templates group, see Templates > Visual C# > ArcGIS. Also confirm that the latest .NET Framework is selected.
Create a new Pro construction tool and edit DAML
-
Right-click the project and choose Add > New Item. From the ArcGIS Pro Add-ins group > list of item templates, select ArcGIS Pro Construction Tool .
-
Name the new class file
Bufferand then click Add to close the dialog box.Polygon Tool.cs Once added, the
Bufferfile should open by default. The Construction Tool template also provides the contents of the class file, as well as corresponding code in thePolygon Tool.cs Config.damlfile for the ArcGIS Pro UI, so the tool can be activated. TheConfig.damlis updated first. -
Open the
Config.damlfile and modify the tool item as follows:When you update the
Config.daml, you change how the tool displays in the Create Features pane UI, providing helpful information to the user about the tool's name and purpose.-
Change the
categorytoRef ID esri_editing _construction _polygon -
Change the
captionto".Create Buffer Polygon" -
Change the
tooltip headingto"and the ToolTip text toCreate Buffer Polygon" "Create polygon with a buffer distance."
Use dark colors for code blocks Copy <tool id="ConstructionTool_BufferPolygonTool" categoryRefID="esri_editing_construction_polygon" caption="Create Buffer Polygon" className="BufferPolygonTool" loadOnClick="true" smallImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonRed16.png" largeImage="pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/GenericButtonRed32.png"> <tooltip heading="Create Buffer Polygon"> Create polygon with a buffer distance.<disabledText /></tooltip> </tool> -
Update your construction tool class code
-
Open the
Bufferfile and modify thePolygon Tool.cs Bufferconstructor method as follows:Polygon Tool This associates the new construction tool with polygon features, rather than point features.
-
Comment out the line:
SketchType = Sketch Geometry Type. Point; -
Uncomment the line:
SketchType = Sketch Geometry Type. Polygon;
Use dark colors for code blocks Copy public BufferPolygonTool() { IsSketchTool = true; UseSnapping = true; // Select the type of construction tool you wish to implement. // Make sure that the tool is correctly registered with the correct component category type in the daml // SketchType = SketchGeometryType.Point; // SketchType = SketchGeometryType.Line; SketchType = SketchGeometryType.Polygon; //Gets or sets whether the sketch is for creating a feature and should use the CurrentTemplate. UsesCurrentTemplate = true; //Gets or sets whether the tool supports firing sketch events when the map sketch changes. //Default value is false. FireSketchEvents = true; } -
-
Modify the
Onmethod as follows:Sketch Complete Async The
Onmethod is found at the bottom of theSketch Complete Async Bufferclass.Polygon Tool - Declare a new variable just above the method with a buffer distance value. For the
Buffervalue, you can use any value you choose. Tip: a larger number allows you to see the buffering of your sketch more clearly.Distance
Use dark colors for code blocks Copy private double BufferDistance = 200;- Just above the predefined code to create an edit operation, add a line to create the buffered polygon geometry:
Use dark colors for code blocks Copy Geometry bufferedGeometry = GeometryEngine.Instance.Buffer(geometry, BufferDistance);- Modify the feature creation code to take the new
bufferedvalue:Geometry
Use dark colors for code blocks Copy createOperation.Create(CurrentTemplate, bufferedGeometry);Use dark colors for code blocks Copy 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(); } - Declare a new variable just above the method with a buffer distance value. For the
Test your construction tool
-
Rebuild your solution and fix any compilation errors.
-
Click Start to begin debugging which will start ArcGIS Pro.
-
Open the Pro project from the Pro SDK sample data installation, which is installed by default in: C:\Data\FeatureTest\FeatureTest.aprx.
-
Once the project is open, zoom into an area where you would like to create your new polygon features. Zooming in on a park or the streets of a small neighborhood can be a good reference scale for testing.
-
Click the Edit tab and then click Create in the Features group to show the Create Features pane.
-
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.
For information on feature editing workflows in ArcGIS Pro, see 2D and 3D feature editing.
-
Hover over the tool to confirm your caption and tooltip code from editing of
Config.damlis working. -
Click the tool to activate it, and then sketch a simple polygon by clicking the vertices points.
-
Double-click to finish your sketch. You should see your new feature created with your buffer distance applied.
What's Next?
Learn how to use additional ArcGIS Pro SDK for .NET features in these tutorials: