I'm currently building a python script that will iterate through Feature Datasets within a File Geodatabase. I then want to create a new set of Feature Datasets based on the current Feature Datasets but with a different spatial reference. I want to select the Feature Classes within the original Feature Dataset and project and save them into the newly created Feature Datasets.
I want to use arcpy.da.walk to firstly get a list of the Feature Datasets in order to create the new Feature Datasets, but for some unknown reason even if I set the datatype to "FeatureDataset" nothing is returned. Any assistance to resolve the following will truly be appreciated.
Also if someone can guide me in how to only retrieve the Feature Classes in the Feature Dataset and not directly within the File Geodatabase and how then to save the the reprojected Feature Classes into the newly generated Feature Datasets.
'''
Created on Aug 25, 2014
@author: PeterW
'''
# Import system modules
import arcpy
import os
# Set current workspace
workspace = r'E:\Projects\Projects14\H103342\test2.gdb'
arcpy.env.workspace = workspace
# Set environment settings
arcpy.env.overwriteOutput = True
# Create list of Feature Classes in each Feature Dataset
fcs = []
# Iterate through each Feature Dataset within the File Geodatabase
for dirpath, dirnames, filenames in arcpy.da.Walk(workspace, datatype = "FeatureDataset"):
for filename in filenames:
print filename
Regards
Hi Peter,
replace your lines 29 and 30 with below. Since you have set datatype as FeatureDataset, filenames will be an empty list.
for dir in dirnames:
featureDataSet = os.path.join(dirpath, dir)
print featureDataSet
If you want a more function based approach
import arcpy # List through Datasets in workspace. def ListDatasets(workspace): arcpy.env.workspace = workspace datasetList = arcpy.ListDatasets("*", "Feature") arraylist = [] for dataset in datasetList: print "Dataset:" + dataset ##get path desc = arcpy.Describe(dataset) ## append to list print "Dataset Path: " + arrayitem arraylist.append(desc.catalogPath) return arraylist workspace = r"C:\Users\lew60590\Documents\ArcGIS\Default.gdb" arraylist = ListDatasets(workspace) # List through datasets and print Features for arrayitem in arraylist: arcpy.env.workspace = arrayitem fclist = arcpy.ListFeatureClasses() for fc in fclist: print "Feature:" + fc
This will list all of the feature classes. Puts any FeatureDataset name first, then FC name:
FDatasetName\FeatureClassName
def listFcsInGDB(gdb): ''' list all Feature Classes in a geodatabase, including inside Feature Datasets ''' arcpy.env.workspace = gdb print 'Processing ', arcpy.env.workspace fcs = [] for fds in arcpy.ListDatasets('','feature') + ['']: for fc in arcpy.ListFeatureClasses('','',fds): fcs.append(os.path.join(fds, fc)) return fcs gdb = r'H:\Documents\ArcGIS\Default.gdb' fcs = listFcsInGDB(gdb) for fc in fcs: print fc