-
Notifications
You must be signed in to change notification settings - Fork 119
ProGuide Feature Selection
Language: C#
Subject: Map Exploration
Contributor: ArcGIS Pro SDK Team <arcgisprosdk@esri.com>
Organization: Esri, http://www.esri.com
Date: 10/06/2024
ArcGIS Pro: 3.4
Visual Studio: 2022
This guide demonstrates how to create a simple map tool for feature selection. See ProConcepts Map Exploration, MapTool for more information on the MapTool pattern.
Prerequisites
- Download and install the sample data required for this guide as instructed in ArcGIS Pro SDK Community Samples Releases.
- Create a new ArcGIS Pro Module Add-in, and name the project MapToolSelect. If you are not familiar with the ArcGIS Pro SDK, you can follow the steps in the ProGuide Build your first add-in to get started.
- Add a new ArcGIS Pro Add-ins | ArcGIS Pro Map Tool item to the add-in project, and name the item MapToolSelect.
Step 1
Modify the Config.daml file tool item as follows:
- Change the caption to "Select Features".
- Change the tool heading to "Select Features" and the ToolTip text to "Select features on the current map using a rectangular sketch."
...
<tool id="MapToolSelect_MapToolSelect" caption="Select Features"
className="MapToolSelect" loadOnClick="true" keytip="TS"
smallImage="GenericButtonRed16" largeImage="GenericButtonRed32"
condition="esri_mapping_mapPane">
<tooltip heading="Select Features">
Select features on the current map using a rectangular sketch.
<disabledText />
</tooltip>
</tool>
...
Build the sample and validate the UI on the ArcGIS Pro ribbon.
Step 2
The required feature selection functions must be implemented in the MapToolSelect class.
First, SketchOutputMode in the constructor is changed to SketchOutputMode.Screen. MapView.SelectFeatures and MapView.GetFeatures throw a System.ArgumentException if a 3D query is attempted in SketchOutputMode.Map, so you need to change the sketch projection to screen coordinates.
public MapToolSelect()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Rectangle;
SketchOutputMode = SketchOutputMode.Screen;
}
Note: If IsSketchTool is not set to true, the map view will not switch to sketching mode when the tool is activated, and a sketch will not be produced.
The OnSketchCompleteAsync method can be overwritten to implement the required selection functionality. The MapTool base class provides an ActiveMapView property that provides a link to the current active map view. The MapView, in turn, provides a method that can be used to select features that intersect a given geometry.
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// Using the active map view to select
// the features that intersect the sketch geometry
ActiveMapView.SelectFeatures(geometry);
return true;
});
}
Note: ActiveMapView is a property provided by the MapTool base class; however, the same reference can also be obtained from the MapView class as shown below.
// Get the active map view
var mapView = MapView.Active;
if (mapView != null) { // Use map view here }
Step 3
Rebuild the add-in. Fix any compilation errors.
Step 4
Debug the add-in. Run the debugger and start ArcGIS Pro. Open the C:\Data\Interacting with Maps\Interacting with Maps.aprx project that contains a 3D map with feature data. Try the selection tool on the 3D scene as shown here:
Close Pro and return to Visual Studio.
Step 5
Return to the OnSketchCompleteAsync routine. Replace the ActiveMapView.SelectFeatures(geometry); line with the following code
protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// Using the active map view to select
// the features that intersect the sketch geometry
SelectionSet selection = ActiveMapView.SelectFeatures(geometry);
var numFeatures = selection.Count;
// iterate the set of features returned
var selectionDict = selection.ToDictionary();
foreach (var kvp in selectionDict)
{
MapMember mapMember = kvp.Key;
List<long> oids = kvp.Value;
// OR use the dictionary w mapMember as the key
// oids = selectionDict[mapMember];
}
return true;
});
}
The SelectionSet object is new at 3.0. It replaces the generic .NET collection of IEnumerable<KeyValuePair<MapMember,List<long>>>
which methods such as MapView.SelectFeatures returned or consumed. You can return to this enumeration structure by referencing the ToDictionary method as shown above. Similarly, a SelectionSet can be constructed from an enumeration by using the FromDictionary static method. For example
SelectionSet selection = SelectionSet.FromDictionary(enumFeatures);
Place a breakpoint in this method, start ArcGIS Pro, activate the tool and sketch on the map to select features. Step through the lines of code to verify the features that are returned. Close Pro when finished.
Home | API Reference | Requirements | Download | Samples
- Overview of the ArcGIS Pro SDK
- What's New for Developers at 3.4
- Installing ArcGIS Pro SDK for .NET
- Release notes
- Resources
- Pro SDK Videos
- ProSnippets
- ArcGIS Pro API
- ProGuide: ArcGIS Pro Extensions NuGet
Migration
- ProSnippets: Framework
- ProSnippets: DAML
- ProConcepts: Framework
- ProConcepts: Asynchronous Programming in ArcGIS Pro
- ProConcepts: Advanced topics
- ProGuide: Custom settings
- ProGuide: Command line switches for ArcGISPro.exe
- ProGuide: Reusing ArcGIS Pro Commands
- ProGuide: Licensing
- ProGuide: Digital signatures
- ProGuide: Command Search
- ProGuide: Keyboard shortcuts
Add-ins
- ProGuide: Installation and Upgrade
- ProGuide: Your first add-in
- ProGuide: ArcGIS AllSource Project Template
- ProConcepts: Localization
- ProGuide: Content and Image Resources
- ProGuide: Embedding Toolboxes
- ProGuide: Diagnosing ArcGIS Pro Add-ins
- ProGuide: Regression Testing
Configurations
Customization
- ProGuide: The Ribbon, Tabs and Groups
- ProGuide: Buttons
- ProGuide: Label Controls
- ProGuide: Checkboxes
- ProGuide: Edit Boxes
- ProGuide: Combo Boxes
- ProGuide: Context Menus
- ProGuide: Palettes and Split Buttons
- ProGuide: Galleries
- ProGuide: Dockpanes
- ProGuide: Code Your Own States and Conditions
Styling
- ProSnippets: Content
- ProSnippets: Browse Dialog Filters
- ProConcepts: Project Content and Items
- ProConcepts: Custom Items
- ProGuide: Custom Items
- ProGuide: Custom browse dialog filters
- ArcGIS Pro TypeID Reference
- ProSnippets: Editing
- ProConcepts: Editing
- ProConcepts: COGO
- ProConcepts: Annotation Editing
- ProConcepts: Dimension Editing
- ProGuide: Editing Tool
- ProGuide: Sketch Tool With Halo
- ProGuide: Construction Tools with Options
- ProGuide: Annotation Construction Tools
- ProGuide: Annotation Editing Tools
- ProGuide: Knowledge Graph Construction Tools
- ProGuide: Templates
3D Analyst Data
Plugin Datasources
Topology
Linear Referencing
Object Model Diagram
- ProSnippets: Geometry
- ProSnippets: Geometry Engine
- ProConcepts: Geometry
- ProConcepts: Multipatches
- ProGuide: Building Multipatches
Relational Operations
- ProSnippets: Knowledge Graph
- ProConcepts: Knowledge Graph
- ProGuide: Knowledge Graph Construction Tools
Reports
- ProSnippets: Map Authoring
- ProSnippets: Annotation
- ProSnippets: Charts
- ProSnippets: Labeling
- ProSnippets: Renderers
- ProSnippets: Symbology
- ProSnippets: Text Symbols
- ProConcepts: Map Authoring
- ProConcepts: Annotation
- ProConcepts: Dimensions
- ProGuide: Tray buttons
- ProGuide: Custom Dictionary Style
- ProGuide: Geocoding
3D Analyst
CIM
Graphics
Scene
Stream
Voxel
- ProSnippets: Map Exploration
- ProSnippets: Custom Pane with Contents
- ProConcepts: Map Exploration
- ProGuide: Map Pane Impersonation
- ProGuide: TableControl
Map Tools
- ProGuide: Feature Selection
- ProGuide: Identify
- ProGuide: MapView Interaction
- ProGuide: Embeddable Controls
- ProGuide: Custom Pop-ups
- ProGuide: Dynamic Pop-up Menu
Network Diagrams
- ArcGIS Pro API Reference Guide
- ArcGIS Pro SDK (pro.arcgis.com)
- arcgis-pro-sdk-community-samples
- ArcGISPro Registry Keys
- ArcGIS Pro DAML ID Reference
- ArcGIS Pro Icon Reference
- ArcGIS Pro TypeID Reference
- ProConcepts: Distributing Add-Ins Online
- ProConcepts: Migrating to ArcGIS Pro
- FAQ
- Archived ArcGIS Pro API Reference Guides
- Dev Summit Tech Sessions