Web Analytics Made Easy -
StatCounter

Node Dangles

Checking to see if a Field Index Exists Using Arcpy (ArGIS 10.0)

Updating some python code from 9.3 that using geoprocessing  to 10.0 using arcpy and the first real object I’ve had to change relates to detecting whether or not an index exists on a table.

I previously posted code using a 9.3 geoprocessing commands, the core of it being:

indexList = gp.listindexes(tablename)
for iIndex in indexList:
    if (iIndex.Name == indexname):
       return True
return False

With arcpy, ESRI has gone back to using the Describe methodology.  Way back when GISers use to type most of their commands into their wood-burning computers, the command ‘Describe’ was used to retrieve information about a coverage, grid, or other data set in our fancy AMLs (or SMLs).  The snippet below shows a function for checking to see if a table has an index with a specified named.

def indexExists(tablename,indexname):

 if not arcpy.Exists(tablename):
  return False

 tabledescription = arcpy.Describe(tablename)

 for iIndex in tabledescription.indexes:
  if (iIndex.Name == indexname):
   return True

 return False

Menu