Select to view content in your preferred language

GetFeatures returning empty SelectionSet from point geometry

261
2
Jump to solution
03-11-2025 07:29 AM
NalbertTero
New Contributor

Hello all - 

I am stymied by a simple error that I cannot resolve. I have a map tool that will be used to change an attribute value of a feature with each click. In testing, the sketch geometry is created correctly, and the tool's OnSketchCompleteAsync method fires as well. However, when passing the sketch geometry to MapView.Active.GetFeatures returns an empty SelectionSet every time, not matter where I click on the map. 

        protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
        {
            var mapView = MapView.Active;

            await QueuedTask.Run(() =>
            {
                var intersectedFeatures = mapView.GetFeatures(geometry);

                if (!intersectedFeatures.IsEmpty) // This clause is never reached.
                {
                    mapView.FlashFeature(intersectedFeatures);

                    if (intersectedFeatures.Contains(WoodlandsManager.Current.CurrentPlan))
                    {
                        var plan_feature = intersectedFeatures[WoodlandsManager.Current.CurrentPlan].FirstOrDefault();

                        Inspector inspector = new Inspector();

                        inspector.Load(WoodlandsManager.Current.CurrentPlan, plan_feature);
                        inspector["Prescription"] = _prescription;

                        EditOperation editOperation = new EditOperation();
                        editOperation.Modify(inspector);
                        editOperation.Execute();
                    }
                }
                else // This clause always is.
                {
                    MessageBox.Show("No features at the point you clicked.");
                }
            });
            return true;

  I have tried using SketchGeometryType.Point, Polygon, and Line, and SketchOutputMode.Screen and Map.

Any suggestions on why the empty SelectionSet would be greatly appreciated!

0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

By any chance, could your layers be set to be "un selectable"? It is a setting that you can see in the table of contents. Like the screenshot:

 

 

UmaHarano_2-1741708236297.png

 

 

 

View solution in original post

2 Replies
UmaHarano
Esri Regular Contributor

By any chance, could your layers be set to be "un selectable"? It is a setting that you can see in the table of contents. Like the screenshot:

 

 

UmaHarano_2-1741708236297.png

 

 

 

NalbertTero
New Contributor

That was exactly it. Thank you so much for the help - I would have taken forever to think to try that.

I was able to fix the issue by modifying the tool's OnToolActivateAsync method to ensure the chosen layer is selectable (the 'working' layer is set by the user and stored in the add-in module):

    internal class PrescriptionBrush : MapTool
    {
        protected override async Task OnToolActivateAsync(bool active)
        {
            if (WoodlandsManager.Current.CurrentPlan == null)
            {
                MessageBox.Show("No current plan is selected in the ribbon. Please select a plan to assign prescriptions to.");
                await FrameworkApplication.SetCurrentToolAsync(null);
                return;
            }
            else
            {
                await QueuedTask.Run(() =>
                {
                    WoodlandsManager.Current.CurrentPlan.SetSelectable(true);
                });

                return;
            }

 

Works great now. Thank you again!