<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>index on Node Dangles</title>
    <link>https://maprantala.com/tags/index/</link>
    <description>Recent content in index on Node Dangles</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 27 Jan 2011 15:31:48 -0600</lastBuildDate>
    <atom:link href="https://maprantala.com/tags/index/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Checking to see if a Field Index Exists Using Python (geoprocessing 9.3).</title>
      <link>https://maprantala.com/2011/01/27/checking-to-see-if-a-field-index-exists-using-python-geoprocessing-9.3./</link>
      <pubDate>Thu, 27 Jan 2011 15:31:48 -0600</pubDate>
      <guid>https://maprantala.com/2011/01/27/checking-to-see-if-a-field-index-exists-using-python-geoprocessing-9.3./</guid>
      <description>&lt;p&gt;NOTE:  I have a &lt;a href=&#34;https://maprantala.com/2011/02/21/checking-to-see-if-a-field-index-exists-using-arcpy-argis-10-0/&#34;&gt;post here&lt;/a&gt; that shows how to check if a field exists using arcpy in ArcGIS 10.0.&lt;/p&gt;
&lt;p&gt;In developing a python script to reload a geodatabase, I wanted to create any necessary indexes.&lt;/p&gt;
&lt;p&gt;No problem creating the index, for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;gp&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;AddIndex_management(tablename, field, IndexName, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;NON_UNIQUE&amp;#34;&lt;/span&gt;, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;NON_ASCENDING&amp;#34;&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But before creating the index, I wanted to verify that it did not exist.  I tried the ever-popular, exists but could not get it to work–either it does not detect indexes or I just never got the fully-qualified name for the index right (ArcSDE using a postgres datastore).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;gp&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Exists(mgs_c5ix_fullname)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I finally found this &lt;a href=&#34;http://webhelp.esri.com/arcgiSDEsktop/9.3/index.cfm?TopicName=ListIndexes_method&#34; target=&#34;_blank&#34;&gt;ArcGIS Desktop Help 9.3 – ListIndexes method&lt;/a&gt; from ESRI.  Unfortunately, it doesn&amp;rsquo;t work-it did not like the &amp;lsquo;while&amp;rsquo; loop construction.  I&amp;rsquo;m guessing it worked in 9.2 and despite ESRI&amp;rsquo;s own &lt;a href=&#34;https://webhelp.esri.com/arcgiSDEsktop/9.3/index.cfm?TopicName=Differences_between_geoprocessor_versions&#34; target=&#34;_blank&#34;&gt;warning&lt;/a&gt; about differences in 9.2 &amp;amp; 9.3, they did not update the sample code.&lt;/p&gt;
&lt;p&gt;A key is to make sure you create a 9.3-version geoprocessing object and the following code can be used.  The caveat that I need to include is that the code only checks one table, if the index is on a different table, it will give you a false-negative.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;gp &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; arcgisscripting&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;create(&lt;span style=&#34;color:#ae81ff&#34;&gt;9.3&lt;/span&gt;)

&lt;span style=&#34;color:#66d9ef&#34;&gt;def&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;indexExists&lt;/span&gt;(tablename,indexname):
 &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;not&lt;/span&gt; gp&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Exists(tablename):
  &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; False

 indexList &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; gp&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;listindexes(tablename)

 &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; iIndex &lt;span style=&#34;color:#f92672&#34;&gt;in&lt;/span&gt; indexList:
  &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (iIndex&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Name &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; indexname):
   &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; True

 &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; False
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To call it, just pass the table and indexname you are looking for.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;indexExists(tablename,indexname)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div id=&#34;geo-post-298&#34; class=&#34;geo geo-post&#34; style=&#34;display: none&#34;&gt;
  &lt;span class=&#34;latitude&#34;&gt;&lt;/span&gt;&lt;span class=&#34;longitude&#34;&gt;&lt;/span&gt;
&lt;/div&gt;</description>
    </item>
    
  </channel>
</rss>
