Saturday 21 January 2017

arcgis 10.0 - Creating geodatabase feature class using geodatabase table schema with ArcPy?


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.



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)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...