<?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 Method for checking if selection set is present on layer that works for all cases in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/method-for-checking-if-selection-set-is-present-on/m-p/737234#M57049</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: verdana, geneva;"&gt;&lt;SPAN style="color: #111111; text-align: center;"&gt;I've been trying to determine the best way of testing whether there is a selection set present on a layer using ArcPy. As many of you will be aware, the Get Count (Data Management) method returns a count of the total number features selected in a layer, or failing that&lt;SPAN style="color: #111111; text-align: center;"&gt; (when there is no selection present)&lt;/SPAN&gt; the total number of features in that layer. So initially, the method I used to check for a selection set was to compare the number returned by &lt;SPAN style="color: #111111; text-align: center;"&gt;Get Count with the number returned by a &lt;SPAN style="color: #111111; text-align: center;"&gt;Get Count done on the layer's underlying feature class accessed via the Describe CatalogPath property (ignoring the issue where all features are selected)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #111111; text-align: center; line-height: 1.5;"&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #111111; font-family: verdana, geneva; font-size: 10pt; text-align: center; line-height: 1.5;"&gt;This method worked fine until I started testing this with layers that had been created as subsets of features from an actual feature class using the '&lt;EM&gt;Create layer from selected features&lt;/EM&gt;' (ArcMap&amp;gt;Table of Contents&amp;gt;Right-click&amp;gt;Selection&amp;gt;&lt;SPAN style="color: #111111; text-align: center;"&gt;Create layer from selected features&lt;/SPAN&gt;). In this case the &lt;SPAN style="color: #111111; text-align: center;"&gt;Get Count accessed via the Describe CatalogPath property will always be different to that returned when done on the layer.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5; text-align: center; color: #111111; font-size: 10pt; font-family: verdana, geneva;"&gt;So then I stumbled on the lesser known FIDSet Describe property, and thought great problem solved. However, this was not the case: the FIDSet property works as you'd expect it should for layers that are based directly on an underlying feature class i.e. it returns a list of OIDs for selected features, or an empty list if none are selected, BUT, it works differently if your layer was created as a selection from another layer. In the latter case, &lt;SPAN style="color: #111111; text-align: center;"&gt;if no features are selected&lt;/SPAN&gt; &lt;SPAN style="color: #111111; text-align: center;"&gt;it returns a list of OIDs for &lt;SPAN style="text-decoration: underline;"&gt;all&lt;/SPAN&gt; of the features in the layer (like Get Count).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;&lt;SPAN style="line-height: 1.5; text-align: center; color: #111111; font-size: 10pt;"&gt;My current workaround for this issue, works for all cases (tested so far!) but adds an unwanted overhead to the script tools that use it. My method to test whether or not a selection set is present&lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5;"&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;is to &lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5;"&gt;temporarily switch the selection set and then check if the count on this is zero. If it is zero then there's no selection set and &lt;/SPAN&gt;conversely&lt;SPAN style="line-height: 1.5;"&gt; if it's not zero then there is. This works fine, but when this is run on large data sets this switching selection back and forth can be quite slow. So my question is, can anyone suggest a better performing method that will work for all cases?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; text-align: left;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN style="line-height: 1.5; font-family: verdana, geneva;"&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; text-align: left;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN style="line-height: 1.5; font-family: verdana, geneva;"&gt;Darren&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;p.s. the FIDSet issue is already listed on&lt;/SPAN&gt; &lt;A class="jive-link-external-small" href="http://ideas.arcgis.com/ideaView?id=087300000008I1J&amp;amp;returnUrl=%2Fapex%2FideaList%3Fc%3D09a300000004xET%26p%3D1%26sort%3Dcomments" rel="nofollow" target="_blank"&gt;ESRI Ideas&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 05 Nov 2014 02:19:15 GMT</pubDate>
    <dc:creator>DarrenSmith</dc:creator>
    <dc:date>2014-11-05T02:19:15Z</dc:date>
    <item>
      <title>Method for checking if selection set is present on layer that works for all cases</title>
      <link>https://community.esri.com/t5/python-questions/method-for-checking-if-selection-set-is-present-on/m-p/737234#M57049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: verdana, geneva;"&gt;&lt;SPAN style="color: #111111; text-align: center;"&gt;I've been trying to determine the best way of testing whether there is a selection set present on a layer using ArcPy. As many of you will be aware, the Get Count (Data Management) method returns a count of the total number features selected in a layer, or failing that&lt;SPAN style="color: #111111; text-align: center;"&gt; (when there is no selection present)&lt;/SPAN&gt; the total number of features in that layer. So initially, the method I used to check for a selection set was to compare the number returned by &lt;SPAN style="color: #111111; text-align: center;"&gt;Get Count with the number returned by a &lt;SPAN style="color: #111111; text-align: center;"&gt;Get Count done on the layer's underlying feature class accessed via the Describe CatalogPath property (ignoring the issue where all features are selected)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #111111; text-align: center; line-height: 1.5;"&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #111111; font-family: verdana, geneva; font-size: 10pt; text-align: center; line-height: 1.5;"&gt;This method worked fine until I started testing this with layers that had been created as subsets of features from an actual feature class using the '&lt;EM&gt;Create layer from selected features&lt;/EM&gt;' (ArcMap&amp;gt;Table of Contents&amp;gt;Right-click&amp;gt;Selection&amp;gt;&lt;SPAN style="color: #111111; text-align: center;"&gt;Create layer from selected features&lt;/SPAN&gt;). In this case the &lt;SPAN style="color: #111111; text-align: center;"&gt;Get Count accessed via the Describe CatalogPath property will always be different to that returned when done on the layer.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 1.5; text-align: center; color: #111111; font-size: 10pt; font-family: verdana, geneva;"&gt;So then I stumbled on the lesser known FIDSet Describe property, and thought great problem solved. However, this was not the case: the FIDSet property works as you'd expect it should for layers that are based directly on an underlying feature class i.e. it returns a list of OIDs for selected features, or an empty list if none are selected, BUT, it works differently if your layer was created as a selection from another layer. In the latter case, &lt;SPAN style="color: #111111; text-align: center;"&gt;if no features are selected&lt;/SPAN&gt; &lt;SPAN style="color: #111111; text-align: center;"&gt;it returns a list of OIDs for &lt;SPAN style="text-decoration: underline;"&gt;all&lt;/SPAN&gt; of the features in the layer (like Get Count).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;&lt;SPAN style="line-height: 1.5; text-align: center; color: #111111; font-size: 10pt;"&gt;My current workaround for this issue, works for all cases (tested so far!) but adds an unwanted overhead to the script tools that use it. My method to test whether or not a selection set is present&lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5;"&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;is to &lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5;"&gt;temporarily switch the selection set and then check if the count on this is zero. If it is zero then there's no selection set and &lt;/SPAN&gt;conversely&lt;SPAN style="line-height: 1.5;"&gt; if it's not zero then there is. This works fine, but when this is run on large data sets this switching selection back and forth can be quite slow. So my question is, can anyone suggest a better performing method that will work for all cases?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; text-align: left;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN style="line-height: 1.5; font-family: verdana, geneva;"&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; text-align: left;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="text-align: left;"&gt;&lt;SPAN style="line-height: 1.5; font-family: verdana, geneva;"&gt;Darren&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;p.s. the FIDSet issue is already listed on&lt;/SPAN&gt; &lt;A class="jive-link-external-small" href="http://ideas.arcgis.com/ideaView?id=087300000008I1J&amp;amp;returnUrl=%2Fapex%2FideaList%3Fc%3D09a300000004xET%26p%3D1%26sort%3Dcomments" rel="nofollow" target="_blank"&gt;ESRI Ideas&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Nov 2014 02:19:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/method-for-checking-if-selection-set-is-present-on/m-p/737234#M57049</guid>
      <dc:creator>DarrenSmith</dc:creator>
      <dc:date>2014-11-05T02:19:15Z</dc:date>
    </item>
  </channel>
</rss>

