[GIS] Creating geodatabase feature class using geodatabase table schema with ArcPy

arcgis-10.0arcpyesri-geodatabasefeature-classtable

Is there a way in ArcPy to create an empty polygon geodatabase feature class that will acquire the schema of a geodatabase table?

I know that it's possible in ArcCatalog (New -> Feature Class and then import all the fields from a table) but I wonder if it can be written in a Python script.

The CreateFeatureclass_management tool allows only Feature Layers as schema templates.

Best Answer

Here's code for the solution based on the accepted answer:

#define the input table name  
tblIN = "LFA_WYKAZ"  
#define new feature class name  
fcOUT = "LFA"  
#define projection  
projection = "c:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\National Grids\Europe\ETRS 1989 Poland CS92.prj"  
#create empty polygon feature class  
arcpy.CreateFeatureclass_management(arcpy.env.workspace, fcOUT, "POLYGON", "", "", "", projection)  
#join fields from the input table  
arcpy.JoinField_management(fcOUT, "OBJECTID", tblIN, "OBJECTID")

Below you'll find code for the solution based on @John's answer. Upto ArcGIS 10.0 JoinField is available only for ArcInfo. This one will work for all licence levels:

#define input table name
tblIN = "LFA_WYKAZ"
#define new feature class name
fcOUT = "LFA"
#define projection
projection = "c:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\National Grids\Europe\ETRS 1989 Poland CS92.prj"
#create empty polygon feature class 
arcpy.CreateFeatureclass_management(arcpy.env.workspace, fcOUT, "POLYGON", "", "", "", projection)
#acquire field list from the input table
desc = arcpy.Describe(tblIN)
fieldListComplete = desc.fields
#limit field list to all fields except OBJECT_ID
fieldList = fieldListComplete[1:]
#create fields in the output feature class
for i in fieldList:
    arcpy.AddField_management(fcOUT, i.name, i.type, "", "", i.length)