Build a feature construction tool

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

Steps

Create a new ArcGIS Pro Add-In Visual Studio Project

  1. Start Visual Studio.

  2. 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

  1. 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 .

  2. 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.

  3. 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."

    Use dark colors for code blocksCopy
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
     <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

  1. 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
          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;
          }
  2. 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
         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 blocksCopy
     
    1
             Geometry bufferedGeometry = GeometryEngine.Instance.Buffer(geometry, BufferDistance);
    • Modify the feature creation code to take the new bufferedGeometry value:
    Use dark colors for code blocksCopy
     
    1
             createOperation.Create(CurrentTemplate, bufferedGeometry);
    Use dark colors for code blocksCopy
                        
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
       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();
       }

Test your construction tool

  1. Rebuild your solution and fix any compilation errors.

  2. Click Start to begin debugging which will start ArcGIS Pro.

  3. Open the Pro project from the Pro SDK sample data installation, which is installed by default in: C:\Data\FeatureTest\FeatureTest.aprx.

  4. 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.

  5. Click the Edit tab and then click Create in the Features group to show the Create Features pane.

  6. 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.

  7. Hover over the tool to confirm your caption and tooltip code from editing of Config.daml is working.

  8. Click the tool to activate it, and then sketch a simple polygon by clicking the vertices points.

  9. 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:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.