5

I have a SDE DB which consists of 40 feature datasets and around 300 featureclasses. I need to get the full list of all featureclasses whose name does not contain "ARCHIVE". It takes several minutes using the script below. It will be unacceptable if I publish this as a geoprocessing service. How can this be improved?

import arcpy,os
import json
from arcpy import env

env.workspace=r"C:\ysde\lcimrl.sde"
arcpy.AddMessage("--------get resource dataset \n")

resourceFeatureList=[]
lodFeatureList=[]
dsList = arcpy.ListDatasets("*","Feature")
for ds in dsList:
    dsDesc = arcpy.Describe(ds)
    dsName=dsDesc.name.upper()
    arcpy.AddMessage("--------get feature class list from "+dsName+" \n")

    fcList = arcpy.ListFeatureClasses("*","",ds)
    print fcList
    for fc in fcList:
        desc = arcpy.Describe(fc)
        fcName=desc.name.upper()
        #print dsName+"_"+fcName
        if   "ARCHIVE" not in fcName:
            if dsName!="SDE.ALTERNATIVES":
                resourceFeatureList.append(fc)
            else: 
                lodFeatureList.append(fc)
print resourceFeatureList
print lodFeatureList

1 Answer 1

4

Just from running a quick test it seems like the arcpy.descibe method might be the source of your slow-down. Since all you are using it for is returning the name of your feature class, it is redundant, as you get the name when you use ListFeatureClasses. Try this and see if it speeds up your process:

import arcpy,os
import json
from arcpy import env

env.workspace=r"C:\ysde\lcimrl.sde"
arcpy.AddMessage("--------get resource dataset \n")

resourceFeatureList=[]
lodFeatureList=[]
dsList = arcpy.ListDatasets("*","Feature")
for ds in dsList:
    arcpy.AddMessage("--------get feature class list from "+ds+" \n")

    fcList = arcpy.ListFeatureClasses("*","",ds)
    print fcList
    for fc in fcList:
        if   "ARCHIVE" not in fc.upper():
            if ds.upper() !="SDE.ALTERNATIVES":
                resourceFeatureList.append(fc)
            else: 
                lodFeatureList.append(fc)
print resourceFeatureList
print lodFeatureList
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.