GetFeatures, IsSelectable, IsVisible

442
2
Jump to solution
03-04-2022 08:21 AM
Living2Learn
New Contributor

ArcGIS Pro API 2.9
Real basic question converting from ArcObjects(IIdentify) to ArcGIS Pro.
I have multiple layers I need to gather information about.
Using the API community example CustomPopup. 
//Get the features that intersect the sketch geometry.
var result = mapView.GetFeatures(geometry);
for (var kvp in results)
{

if (kvp.Key.Name == myLayer.Name) {// do something}

}

This only returns layers the end user has set as selectable and display turned on.
I already know I can set them SetSelectable, get current status and setback after MapTool is deactivated.
How to get all layers regardless if they're selectable or visible?

 

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

You can iterate through map feature layers and make spatial query:

                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.FilterGeometry = geometry;
                filter.SpatialRelationship = SpatialRelationship.Intersects;

                var allLayers = map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
                foreach (var layer in allLayers)
                {
                    var featClass = layer.GetFeatureClass();
                    using (var rows = featClass.Search(filter, false))
                    {
                        while (rows.MoveNext())
                        {
                            using (var feature = rows.Current as Feature)
                            {
                            }
                        }
                    }
                }

View solution in original post

2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

You can iterate through map feature layers and make spatial query:

                SpatialQueryFilter filter = new SpatialQueryFilter();
                filter.FilterGeometry = geometry;
                filter.SpatialRelationship = SpatialRelationship.Intersects;

                var allLayers = map.GetLayersAsFlattenedList().OfType<FeatureLayer>();
                foreach (var layer in allLayers)
                {
                    var featClass = layer.GetFeatureClass();
                    using (var rows = featClass.Search(filter, false))
                    {
                        while (rows.MoveNext())
                        {
                            using (var feature = rows.Current as Feature)
                            {
                            }
                        }
                    }
                }
Living2Learn
New Contributor

Thank you for the response. 
Your suggestion was what I ultimately used. 

0 Kudos