<?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: Determine if valid query returns records in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/determine-if-valid-query-returns-records/m-p/126972#M9894</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This works on a Feature Layer.&amp;nbsp; See if it will work for you!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rowcount = int(str(arcpy.GetCount_management("DerivedLayer")))

if rowcount &amp;gt; 0:
&amp;nbsp;&amp;nbsp; 'we have rows, do something with them!
else:
&amp;nbsp;&amp;nbsp; 'no rows in the DerivedLayer, I guess exit?
&amp;nbsp;&amp;nbsp; return &lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Exactly what I needed! Thanks James!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 07:12:27 GMT</pubDate>
    <dc:creator>JohnDye</dc:creator>
    <dc:date>2021-12-11T07:12:27Z</dc:date>
    <item>
      <title>Determine if valid query returns records</title>
      <link>https://community.esri.com/t5/python-questions/determine-if-valid-query-returns-records/m-p/126970#M9892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What's the most elegant way to determine if a valid SQL Query (Attribute Query or Definition Query) returns no records?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wrote this little function to just take a layer on disk, apply a definition query and update the name of the layer then pop it into the dataframe, but before I do that I want to validate that the definition query actually returned some records.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def createDerivedLayer(SourceLayer, UpdateName, DefinitionQuery = ""): &amp;nbsp;&amp;nbsp;&amp;nbsp; """ &amp;nbsp;&amp;nbsp;&amp;nbsp; Creates a new in-memory Layer in the ArcMap Table of Contents derived from an &amp;nbsp;&amp;nbsp;&amp;nbsp; existing Layer on disk or in the ArcMap Table of Contents as referenced by the 'SourceLayer' &amp;nbsp;&amp;nbsp;&amp;nbsp; argument, and pastes the DerivedLayer into the Table of Contents. &amp;nbsp;&amp;nbsp;&amp;nbsp; Optionally applies a Definition Query to the newly Dervied Layer. &amp;nbsp;&amp;nbsp;&amp;nbsp; """ &amp;nbsp;&amp;nbsp;&amp;nbsp; SourceLayer = arcpy.mapping.Layer(str(SourceLayer)) &amp;nbsp;&amp;nbsp;&amp;nbsp; DerivedLayer = SourceLayer &amp;nbsp;&amp;nbsp;&amp;nbsp; DerivedLayer.name = str(UpdateName) &amp;nbsp;&amp;nbsp;&amp;nbsp; if DefinitionQuery: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DerivedLayer.definitionQuery = str(DefinitionQuery) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, DerivedLayer, "AUTO_ARRANGE") &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC() &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ICan anyone think of a way to see if 'DerivedLayer' has at least 1 records without having to go through the entire dataset? I think I'm just overthinking this...probably a very simply solution I'm overlooking&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jan 2014 14:08:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/determine-if-valid-query-returns-records/m-p/126970#M9892</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2014-01-09T14:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Determine if valid query returns records</title>
      <link>https://community.esri.com/t5/python-questions/determine-if-valid-query-returns-records/m-p/126971#M9893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This works on a Feature Layer.&amp;nbsp; See if it will work for you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;rowcount = int(str(arcpy.GetCount_management("DerivedLayer")))&amp;nbsp; if rowcount &amp;gt; 0: &amp;nbsp;&amp;nbsp; 'we have rows, do something with them! else: &amp;nbsp;&amp;nbsp; 'no rows in the DerivedLayer, I guess exit? &amp;nbsp;&amp;nbsp; return &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jan 2014 14:21:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/determine-if-valid-query-returns-records/m-p/126971#M9893</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-01-09T14:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: Determine if valid query returns records</title>
      <link>https://community.esri.com/t5/python-questions/determine-if-valid-query-returns-records/m-p/126972#M9894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This works on a Feature Layer.&amp;nbsp; See if it will work for you!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rowcount = int(str(arcpy.GetCount_management("DerivedLayer")))

if rowcount &amp;gt; 0:
&amp;nbsp;&amp;nbsp; 'we have rows, do something with them!
else:
&amp;nbsp;&amp;nbsp; 'no rows in the DerivedLayer, I guess exit?
&amp;nbsp;&amp;nbsp; return &lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Exactly what I needed! Thanks James!!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:12:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/determine-if-valid-query-returns-records/m-p/126972#M9894</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2021-12-11T07:12:27Z</dc:date>
    </item>
  </channel>
</rss>

