2

I have a list of layers (.ListLayers()) taken from a dataframe . In my case the layers can have two types of data source either shapefile or GDB. I want to start different actions depending on the source type. What I thought of so far: it would be possible to compare the 'desc.name[-4:]' with '".shp"' like:

import arcpy

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
lyrlist = arcpy.mapping.ListLayers(mxd, "", df)

for lyr in lyrlist:
    desc = arcpy.Describe(lyr)

    if (desc.name[-4:] == ".shp"):
        #do something with the shapefile
    else:
        #do something with the GDB feature class)

I still believe this option must be hidden somewhere in the describe method.

Is it possible to distinguish shapefiles from geodatabase feature class with the arcpy describe() method?

2

The Describe object's dataType property will return Shapefile for a shapefile, and FeatureClass for a Geodatabase Feature Class

if desc.featureClass.dataType == 'Shapefile':
    #do something to shapefiles

if desc.featureClass.dataType == 'FeatureClass':
    #do something to feature classes

From ArcGIS Desktop Help pages for Describe

A Shapefile returns a dataType of "ShapeFile".
Describe - Shapefile

A Geodatabase Feature Class returns a dataType of "FeatureClass".
Describe - GDB Feature Class

  • @EikeMike that one had a 'gotcha' of needing the featureClass object included. At first I said to use desc.dataType however that doesn't work from within ArcMap looking at a layer (it just returns featureLayer) – Midavalo Jul 4 '16 at 9:04
1

If you see Describe as just one way to do this, then an alternative is the dataSource property of the layer:

for lyr in lyrlist:
    if lyr.dataSource[-4:] == ".shp":
        #do something with the shapefile
    else:
        #do something with the GDB feature class)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.