List feature classes can't find anything in SDE - why?

5732
11
11-13-2014 11:32 AM
AaronManuel
New Contributor III

I'm trying to create a script that pulls about 20 or so feature classes out of sde and puts them in a geodatabase for a group of people to look at for a special project. I'm trying to do this with a for loop and the copy_management function. However after playing around with the script for a while I realized I needed to start back at the beginning because I seem to be having an issue getting the ListFeatureClasses function to even return anything from my SDE connection. Here is just a simple test I put together:

import arcpy

import os

warehouse = r"C:\Users\aaronmanuel\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Warehouse.sde"

testgdb = r"C:\Projects\Test\TestGDB.gdb"

arcpy.env.workspace = warehouse

fcList = arcpy.ListFeatureClasses("*") 

print fcList

Running this script returns "[ ]" - an empty list.

Running it after changing the environment to the testgdb returns this:

[u'TestLine', u'coa_water_meter', u'coa_water_hydrant']

Which is correct, I put in these three features for testing purposes.

Googling has led me a few other threads of the "ListFeatureClasses returns an empty list" variety, but ultimately I couldn't find any real answer. What other factors besides stuff like typos and incorrect file paths could be causing this function to return and empty list?

Thanks.

0 Kudos
11 Replies
AaronManuel
New Contributor III

I basically just copied the example from the help link Ian had posted earlier, substituting my sde connection.

At this point I think I need to talk to my network department about potential permissions issues.

Thanks for the input everyone.

0 Kudos
PingYang
New Contributor II

Finally I figure it out, the following code from the ArcGIS help:

datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []
    for ds in datasets:
        for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
            PATH = os.path.join(arcpy.env.workspace, ds, fc)
            with arcpy.da.SearchCursor(PATH, ["*"]) as cursor:
                for row in cursor:
                    tupleList.append(row)