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.
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.daml file opens in Visual Studio. The Module1.cs file contains add-in module code.
Note also in the Config.daml file that the id attribute of the insertModule tag matches the ID within the Module1.cs file and the className attribute also matches the class name of the module.
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 BufferPolygonTool.cs and then click Add to close the dialog box.
Once added, the BufferPolygonTool.cs file should open by default. The Construction Tool template also provides the contents of the class file, as well as corresponding code in the Config.daml file for the ArcGIS Pro UI, so the tool can be activated. The Config.daml is updated first.
Open the Config.daml file 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 categoryRefID to esri_editing_construction_polygon
Change the caption to "Create Buffer Polygon".
Change the tooltip heading to "Create Buffer Polygon" and the ToolTip text to "Create polygon with a buffer distance."
Open the BufferPolygonTool.cs file and modify the BufferPolygonTool constructor method as follows:
This associates the new construction tool with polygon features, rather than point features.
Comment out the line: SketchType = SketchGeometryType.Point;
Uncomment the line: SketchType = SketchGeometryType.Polygon;
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
publicBufferPolygonTool() {
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 OnSketchCompleteAsync method as follows:
The OnSketchCompleteAsync method is found at the bottom of the BufferPolygonTool class.
Declare a new variable just above the method with a buffer distance value. For the BufferDistance value, you can use any value you choose. Tip: a larger number allows you to see the buffering of your sketch more clearly.
Use dark colors for code blocksCopy
1
privatedouble BufferDistance = 200;
Just above the predefined code to create an edit operation, add a line to create the buffered polygon geometry:
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.