testing for raster

390
4
10-29-2012 06:13 PM
by Anonymous User
Not applicable
Original User: dhealey

In 10.1, I'm using  FC_List = arcpy.ListFeatureClasses() to capture a list of fc's names,
    but some of those are also raster.
Now, I'm not seeing that in the doc http://resources.arcgis.com/en/help/main/10.1/index.html#//018v00000018000000.
    However, to humor me.

Using Arcpy, what test can I use to distinguish fc from raster?

As in perhaps...

for name in FC_List:
   if name.ObjectType_for_example == "raster":
      process_raster(name)
   else:
      process_fc(name)
0 Kudos
4 Replies
by Anonymous User
Not applicable
Original User: Caleb1987

You can use the list rasters function:

rasterList = arcpy.ListRasters()
for raster in rasterList:
    print raster
0 Kudos
by Anonymous User
Not applicable
You can try something like this:

arcpy.env.workspace = r'C:\temp'

rasterList = arcpy.ListRasters()
for raster in rasterList:
    print raster
    # do something with these

fc_list = arcpy.ListFeatureClasses()
for fc in fc_list:
    print fc
    # do something with these
0 Kudos
by Anonymous User
Not applicable
Original User: curtvprice

Using Arcpy, what test can I use to distinguish fc from raster?


That list function should be only return feature classes. ListDatasets gives you both flavors. But to answer your question, the properties of an object are determined using the Describe function. You're looking for the "datasetType" property:

Dataset properties

arcpy.Describe(dataset).datasetType in ["RasterDataset","RasterBand"]
0 Kudos
by Anonymous User
Not applicable
Original User: dhealey

That list function should be only return feature classes. ListDatasets gives you both flavors. But to answer your question, the properties of an object are determined using the Describe function. You're looking for the "datasetType" property:

arcpy.Describe(dataset).datasetType in ["RasterDataset","RasterBand"]


<<That list function should be only return feature classes.>>
Yes, that is what the docs say, but I do not have time to wrestle with tech support.

I saw the <<arcpy.ListRasters>> already and would have used it if needed, thx.
<<arcpy.Describe(fc).datasetType>> works great and will probably use is more often.

Thank you both of you.
0 Kudos