Listing data in an SDE

1636
4
Jump to solution
03-13-2014 06:48 AM
Zeke
by
Regular Contributor III
I wrote the code below to list datasets and associated feature classes and shape types (point, polygon, etc.) in an sde. This works fine until I get to the last dataset, Zoning, which contains one feature class and one topology. There, it errors out with "RuntimeError: DescribeData: Method feature type does not exist". Also errors on shapeType if I don't check featureType first.

Guessing this has something to do with desc not liking the topology, but is there a way around this other than catching the exception and then continue? Thanks.

def getLists():     dsList = arcpy.ListDatasets("*")     for ds in dsList:         dsName = ds.split(".")         print dsName[2].upper()          print " - Feature Classes"         fcList = arcpy.ListFeatureClasses("*", "", ds)         if len(fcList) == 0:             print "\t - " + "No feature class in this dataset. \n"             continue         for fc in fcList:             desc = arcpy.Describe(fc)             if desc.featureType == "Simple":                 fcName = fc.split(".")                 desc = arcpy.Describe(fc)                 print "\t - " + fcName[2] + ": " + desc.shapeType         print "\n"
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ShawnThorne
Esri Contributor
When you're listing the Feature Datasets, you're specifying an asterisk (*) - which is getting everything.  Try specifying ("*", "Feature") to list just the Feature Classes.

dsList = arcpy.ListDatasets("*","Feature")


Here's a script I wrote that lists all of the Feature Datasets (and the Feature Classes contained within them, with their geometry type) in an SDE/Oracle instance.  Just modify the name of the connection file for the SDE user.

Hope this helps.

-Shawn

 import arcpy, gc  # Write results to a textfile logfile = open(r'C:\TEMP\List_FCs_in_FDs.log', 'w')   def log_results(message):     print(message)     logfile.write(message)     logfile.flush()     return  def main():     try:          EGDB = arcpy.env.workspace = r'Database Connections\ORCL - SDE@SERVER.sde'                  fdList = arcpy.ListDatasets("*", "Feature")          fdCnt = 0         totalFCcnt = 0          if arcpy.Exists(EGDB) == True:              for eachFD in sorted(fdList) :                 fdCnt += 1                 log_results("\n {0}. Feature Dataset '{1}'\n".format(str(fdCnt),eachFD))                 fcCnt = 0                  # Cannot use  fdEGDB = EGDB + '/' + eachFD  returns Cartesian Product                 fdEGDB = arcpy.env.workspace = EGDB + '/' + eachFD                 fcList = arcpy.ListFeatureClasses("*")                 for eachFC in sorted(fcList):                     desc = arcpy.Describe(eachFC)                     log_results("   -> " + eachFC + ' (' + desc.shapeType + ')')                     fcCnt += 1                     totalFCcnt += 1                  if fcCnt == 0:                     log_results("\n   Feature Dataset '{0}' does not contain any Feature Classes!!\n".format(eachFD))                 else:                     log_results("\n   # of Feature Classes in the '{0}' Feature  Dataset : {1}\n".format(eachFD,str(fcCnt)))               log_results("\n TOTAL # OF FEATURE DATASETS COUNTED : {0}".format(str(fdCnt)))             log_results(" TOTAL # OF FEATURE CLASSES COUNTED  : {0}\n".format(str(totalFCcnt)))          else:             log_results("\n The specified SDE Connection File DOES NOT EXIST\n")             return          log_results ("\n\n COMPLETED!! \n\n")          del fcCnt         del fdCnt         del fcList         del fdList         del fdEGDB         del eachFD         del totalFCcnt          gc.collect()      except arcpy.ExecuteError:         log_results (arcpy.GetMessages(2))      except Exception as e:         log_results (e[0])  if __name__ == '__main__':     main() 

View solution in original post

4 Replies
JoshuaChisholm
Occasional Contributor III
Hello Greg,

I'm not sure if this is satisfactory, but you could skip over the topology.
if desc.dataType=='Topology':
    continue

(Just make sure this line goes before the lines that error out)

Let me know if it works for you!
0 Kudos
Zeke
by
Regular Contributor III
Thanks Joshua. That fix, as well as the try/catch, stops the error but doesn't print the one feature class that is in the dataset. Hmmm...
0 Kudos
ShawnThorne
Esri Contributor
When you're listing the Feature Datasets, you're specifying an asterisk (*) - which is getting everything.  Try specifying ("*", "Feature") to list just the Feature Classes.

dsList = arcpy.ListDatasets("*","Feature")


Here's a script I wrote that lists all of the Feature Datasets (and the Feature Classes contained within them, with their geometry type) in an SDE/Oracle instance.  Just modify the name of the connection file for the SDE user.

Hope this helps.

-Shawn

 import arcpy, gc  # Write results to a textfile logfile = open(r'C:\TEMP\List_FCs_in_FDs.log', 'w')   def log_results(message):     print(message)     logfile.write(message)     logfile.flush()     return  def main():     try:          EGDB = arcpy.env.workspace = r'Database Connections\ORCL - SDE@SERVER.sde'                  fdList = arcpy.ListDatasets("*", "Feature")          fdCnt = 0         totalFCcnt = 0          if arcpy.Exists(EGDB) == True:              for eachFD in sorted(fdList) :                 fdCnt += 1                 log_results("\n {0}. Feature Dataset '{1}'\n".format(str(fdCnt),eachFD))                 fcCnt = 0                  # Cannot use  fdEGDB = EGDB + '/' + eachFD  returns Cartesian Product                 fdEGDB = arcpy.env.workspace = EGDB + '/' + eachFD                 fcList = arcpy.ListFeatureClasses("*")                 for eachFC in sorted(fcList):                     desc = arcpy.Describe(eachFC)                     log_results("   -> " + eachFC + ' (' + desc.shapeType + ')')                     fcCnt += 1                     totalFCcnt += 1                  if fcCnt == 0:                     log_results("\n   Feature Dataset '{0}' does not contain any Feature Classes!!\n".format(eachFD))                 else:                     log_results("\n   # of Feature Classes in the '{0}' Feature  Dataset : {1}\n".format(eachFD,str(fcCnt)))               log_results("\n TOTAL # OF FEATURE DATASETS COUNTED : {0}".format(str(fdCnt)))             log_results(" TOTAL # OF FEATURE CLASSES COUNTED  : {0}\n".format(str(totalFCcnt)))          else:             log_results("\n The specified SDE Connection File DOES NOT EXIST\n")             return          log_results ("\n\n COMPLETED!! \n\n")          del fcCnt         del fdCnt         del fcList         del fdList         del fdEGDB         del eachFD         del totalFCcnt          gc.collect()      except arcpy.ExecuteError:         log_results (arcpy.GetMessages(2))      except Exception as e:         log_results (e[0])  if __name__ == '__main__':     main() 
Zeke
by
Regular Contributor III
Thanks Shawn.
0 Kudos