I am attempting to write a script that processes a lot of different feature classes in a geodatabase. Most of the feature classes have the same schema as the user connecting to the database
geodatabase.myschema.featureclass
however some feature classes have a schema belonging to a different user
geodatabase.differentschema.featureclass2
When using arcpy with a .sde connection and user that owns the default schema, I do not need to specify the schema name when referencing feature classes in arcpy tools.
import arcpy, os
db = r"D:\GIS\DBConns\geodatabase.sde"
fc = "featureclass"
fcpath = os.path.join(db, fc)
result = int(arcpy.GetCount_management(fcpath).getOutput(0))
print result
> 147
However if I reference the feature class with a different schema, the above doesn't work
Runtime error Traceback (most recent call last): File "<string">, line 6, in <module>
File "C:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 15370, in GetCount
raise e Execute Error:
Failed to execute. Parameters are not valid.
Error 000732: Input Rows:
D:\GIS\DBConns\geodatabase.sde\featureclass2 does not exist or is not supported
Failed to execute (GetCount).
If I change the fc
variable to include the schema name e.g. fc = "differentschema.featureclass2"
then it works no problem.
Is there a way to quickly determine the schema name for a feature class from arcpy so that the tools work correctly?
I tried doing an arcpy.ListFeatureClasses("*featureclass2")
however this adds a lot of time to the process (the gdb has a lot of feature classes, many of which are in Feature Datasets also), so would like to avoid that if possible.