<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: GetFeatures result hierarchy in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/getfeatures-result-hierarchy/m-p/1481503#M11601</link>
    <description>&lt;P&gt;To partially answer my own question, you can implement a SortedDictionary on the results of the mapTool click to at least create a sorted list based on your Table of Contents.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt; features = new Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt;();
features = mapView.GetFeatures(geometry).ToDictionary();

Dictionary&amp;lt;int, string&amp;gt; theHitList = new Dictionary&amp;lt;int, string&amp;gt;();

var counter = 0;
foreach (var feature in features)
{
       theHitList.Add(counter, feature.Key.Name);
       counter++;
}

var theLayerName = getTopLayer(theHitList, features.First().Key.Map);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The getTopLayer function with the SortedDictionary is in this function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        private static string getTopLayer(Dictionary&amp;lt;int,string&amp;gt; clickList, Map theMap)
        {
            var layers = MapView.Active.Map.GetLayersAsFlattenedList(); // MapView.Active.Map.Layers.Where(layer =&amp;gt; layer is FeatureLayer);
            SortedDictionary&amp;lt;int, string&amp;gt; sortedLayerList = new SortedDictionary&amp;lt;int, string&amp;gt;();

            foreach (var layer in clickList)
            {                
                var curLayerName = layer.Value;
                for (int i = 0; i &amp;lt; layers.Count; i++)
                {
                    if (layers[i].Name == curLayerName)
                    {
                        sortedLayerList.Add(i, layers[i].Name); 
                        break;
                    }
                }
            }
            return sortedLayerList.First().Value;
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still learning C# so I'm sure there are more elegant and efficient ways to do this. In my use case, I'm labelling so I was really only concerned with the topmost layer that was clicked on using the mapTool. Nonetheless, the sortedDictionary is the mechanism to sort the information. all you do is just walk through the layers in the TOC, and add the clicked features' layer and TOC position number. So far, this has worked in my testing so I'm happy enough with this approach.&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
    <pubDate>Thu, 30 May 2024 19:01:02 GMT</pubDate>
    <dc:creator>SteveCole</dc:creator>
    <dc:date>2024-05-30T19:01:02Z</dc:date>
    <item>
      <title>GetFeatures result hierarchy</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/getfeatures-result-hierarchy/m-p/1480327#M11597</link>
      <description>&lt;P&gt;Is there anyway to enforce a hierarchy on the results returned when using GetFeatures? For example, lets say I have a location with 3 features at a location- a road (line), a stream (line), and a bridge (point). Ideally, I'd like to have the results returned in the same order as my Table of Contents (bridge-&amp;gt;road-&amp;gt;stream) but, in reality, it's returning otherwise (road-&amp;gt;bridge-&amp;gt;stream).&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 16:12:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/getfeatures-result-hierarchy/m-p/1480327#M11597</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2024-05-29T16:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: GetFeatures result hierarchy</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/getfeatures-result-hierarchy/m-p/1481503#M11601</link>
      <description>&lt;P&gt;To partially answer my own question, you can implement a SortedDictionary on the results of the mapTool click to at least create a sorted list based on your Table of Contents.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt; features = new Dictionary&amp;lt;MapMember, List&amp;lt;long&amp;gt;&amp;gt;();
features = mapView.GetFeatures(geometry).ToDictionary();

Dictionary&amp;lt;int, string&amp;gt; theHitList = new Dictionary&amp;lt;int, string&amp;gt;();

var counter = 0;
foreach (var feature in features)
{
       theHitList.Add(counter, feature.Key.Name);
       counter++;
}

var theLayerName = getTopLayer(theHitList, features.First().Key.Map);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The getTopLayer function with the SortedDictionary is in this function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        private static string getTopLayer(Dictionary&amp;lt;int,string&amp;gt; clickList, Map theMap)
        {
            var layers = MapView.Active.Map.GetLayersAsFlattenedList(); // MapView.Active.Map.Layers.Where(layer =&amp;gt; layer is FeatureLayer);
            SortedDictionary&amp;lt;int, string&amp;gt; sortedLayerList = new SortedDictionary&amp;lt;int, string&amp;gt;();

            foreach (var layer in clickList)
            {                
                var curLayerName = layer.Value;
                for (int i = 0; i &amp;lt; layers.Count; i++)
                {
                    if (layers[i].Name == curLayerName)
                    {
                        sortedLayerList.Add(i, layers[i].Name); 
                        break;
                    }
                }
            }
            return sortedLayerList.First().Value;
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still learning C# so I'm sure there are more elegant and efficient ways to do this. In my use case, I'm labelling so I was really only concerned with the topmost layer that was clicked on using the mapTool. Nonetheless, the sortedDictionary is the mechanism to sort the information. all you do is just walk through the layers in the TOC, and add the clicked features' layer and TOC position number. So far, this has worked in my testing so I'm happy enough with this approach.&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 19:01:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/getfeatures-result-hierarchy/m-p/1481503#M11601</guid>
      <dc:creator>SteveCole</dc:creator>
      <dc:date>2024-05-30T19:01:02Z</dc:date>
    </item>
  </channel>
</rss>

