Arcpy 10.1 ListFeatureClasses returns Raster Datasets

1009
4
Jump to solution
01-16-2014 10:05 AM
BenjaminHillam
New Contributor II
I am trying to loop through all the feature classes in an SDE geodatabase and get their name and feature count.  When I attempt to get the feature count of each feature class I run into an error because in my list there are raster datasets.  Why are there raster datasets in my resulting list from arcpy.ListFeatureClasses()? I pasted the code but it doesn't make sense to me why raster datasets are included in ListFeatureClasses?  What am I missing?

import arcpy from arcpy import env  env.workspace = r'Database Connections\MySDEgeodatabase.sde'  fcList = arcpy.ListFeatureClasses()


I looped through fcList using this code

for fc in fcList:     desc = arcpy.Describe(f)     print '{0}  {1}'.format(desc.name, desc.dataType)


This is where I realized the list contained raster datasets with dataTypes of "RasterDataset"? I want to avoid having to use arcpy.Describe() to filter to to get feature classes because there are hundreds of feature classes in the SDE geodatabase and it slows it down a ton.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
SachinKanaujia
Occasional Contributor III
There are filters based on which you can restrict what type of Dataset you want to see, Feature dataset Vs Raster dataset. I believe thats what you want to accomplish?


datasetList = arcpy.ListDatasets("*", "Feature")
for dataset in datasetList:
print dataset
fcList = arcpy.ListFeatureClasses("*","",dataset)
for fc in fcList:
print fc


Similarly
datasetList = arcpy.ListDatasets("*", "Raster")
should give you only raster datasets.

View solution in original post

0 Kudos
4 Replies
JamesCrandall
MVP Frequent Contributor
This only returns/prints info on the FeatureClass for me but it is slow:

fcList = arcpy.ListFeatureClasses()
for fc in fcList:
   desc = arcpy.Describe(fc)
   print '{0}  {1}'.format(desc.name, desc.dataType)



This zips right through very quickly and returns the same list of only FeatureClasses:

fcList = arcpy.ListFeatureClasses()
for fc in fcList:
   print fc
0 Kudos
BenjaminHillam
New Contributor II
Yeah, maybe there is something wrong with the sde geodatabase or the actually raster layer that is causing the "arcpy.ListFeatureClass" to return raster datasats.  I had to work around it by describing each item the feature class list and filter out any raster datasets.  It works but takes a really long time.  Still baffles me that ListFeatureClasses would return raster datasets.
0 Kudos
SachinKanaujia
Occasional Contributor III
There are filters based on which you can restrict what type of Dataset you want to see, Feature dataset Vs Raster dataset. I believe thats what you want to accomplish?


datasetList = arcpy.ListDatasets("*", "Feature")
for dataset in datasetList:
print dataset
fcList = arcpy.ListFeatureClasses("*","",dataset)
for fc in fcList:
print fc


Similarly
datasetList = arcpy.ListDatasets("*", "Raster")
should give you only raster datasets.
0 Kudos
BenjaminHillam
New Contributor II
Sachin, Thanks for the filtering tip that helps, but it still doesn't make sense to me that arcpy.ListFeatureClasses() would return anything other than a Feature Class. It must be something funky with the SDE or specific datasets I'm listing. I ended up using your filtering tips and arcpy.Describe to work around it.
0 Kudos