Is there any method in ArcGIS Pro SDK to select by shape like in ArcObjects SDK ?

621
4
11-16-2022 01:05 AM
KhaledAliMoh
New Contributor II

I want to select a feature by using a geometry in a map like in IMap interface in ArcObjects and get the feature object too.

// ArcObjects
void SelectByShape(IGeometry Shape, ISelectionEnvironment env, bool justOne);

 

Note: I know that I can use

var features = activeView.GetFeatures(geometry);

But this method exists in the MapView class not in the Map class.

 

0 Kudos
4 Replies
CharlesMacleod
Esri Regular Contributor

Selection is on the MapView. Not the Map.

0 Kudos
KhaledAliMoh
New Contributor II

Okay, then how can I enforce it to select only one feature ? or I have to use QueryFilter after use GetFeatures method ?

0 Kudos
CharlesMacleod
Esri Regular Contributor
There is a Mapview SelectFeatures that takes a spatial query as a parameter
0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Charlie is correct here are some examples:

MapView.Active.SelectFeatures(MapView.Active.Extent);

or 

var selection = MapView.Active.SelectFeatures(clipPoly);

You have to run the SelectFeatures method on the MCT meaning you have to use QueuedTask.Run as in the MapTool sample below:

  internal class MapTool1 : MapTool
  {
    public MapTool1()
    {
      IsSketchTool = true;
      SketchType = SketchGeometryType.Polygon;
      SketchOutputMode = SketchOutputMode.Map;
    }
    protected override Task OnToolActivateAsync(bool active)
    {
      return base.OnToolActivateAsync(active);
    }
    protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
    {
      // https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic11992.html
      bool result = await QueuedTask.Run(() =>
      {
        var selectionSet = MapView.Active.SelectFeatures(geometry);
        return true;
      });
      return result;
    }
  }
0 Kudos