Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 4 down vote accepted

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
share|improve this answer
    
you are great. It significantly increase the speed. Thanks. –  Alex Oct 8 '12 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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