[GIS] Referencing Feature Dataset in File Geodatabase with ArcPy

arcpyfeature-datasetfile-geodatabase

I'm trying to develop an arcpy script which will eventually loop through number of rasters and feature classes stored in file geodatabase. I'd like to export spatial reference for these attributes along with their name to csv. I managed to do that for raster datasets, however I'm struggling with feature classes.

All rasters are stored directly in geodatabase so I have no problem with referencing these. All feature classess are stored within 3 feature datasets. In order to reference these FCs I set env.workspace pointing to relevant Feature Dataset, which works fine. I'd like to find the way to reference all of my Fcs at once, something like:

arcpy.env.workspace="...\Name.gdb"
fcList = arcpy.ListFeatureClasses("*", "polygon", ***InFeatureDatasets***)
outFilePTH = r'...\output.csv'

Best Answer

You could get a list of the featuredatasets using the ListDatasets function, then loop through that list to get at the featureclasses within each featuredataset. From the docs:

datasetList = arcpy.ListDatasets("C*", "Feature")

for dataset in datasetList:
    print dataset