Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

You can try JoinField to join the geodatabase Table to the blank Featureclass. The join field can be Objectid. The resulting fields should be blank.

share|improve this answer
add comment

Well, it looks from the documentation like you can define a feature class as a template input via python as well. So, one option would be to add an X and Y field (make sure they are the right data type (I know double works, not sure what others). Then you can even calculate all of those as 0,0 or just leave null. Then create XY Event Layer from that table, and use the output as the input schema for the new feature class except delete the X and Y fields you created.

Otherwise, if you don't want to do something along that lines, I don't know the specifics of this part of ArcPy well enough to type up sample code for you or anything, but might I suggest you just look at, instead of importing another schema as a template, why don't you use ArcPy to identify the details of each field in the table http://resources.arcgis.com/en/help/main/10.1/index.html#//018v00000012000000 and then from that you could loop through each field in the resulting fields object and re-create each field from those details in the new feature class by calling the AddField GP Tool or something along that lines.

I'm not saying either of those are the absolute ideal answer you're looking for, nor am I swearing they're computationally the absolutely most efficient (because like I said, I've not personally done that in ArcPy), but they should work. Hope it helps.

share|improve this answer
    
Using X & Y fields is out of the question, as this is a polygon feature class. Second option worked though. I provided the code below in my answer. Thanks! –  Mireslav Feb 24 at 14:09
add comment

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 the second 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)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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