1

When you create a feature class through ArcCatalog you get a handy menu that lets you assign fields.

enter image description here

I'm wondering if there isn't an arcpy equivalent. There's no arguments for it in the Create Feature Class tool.

I thought maybe a field info object would do it, placed in the template variable, but this failed. I then realized that field info fields don't indicate field type or most any other field properties, so this should not have been a surprise.

>>> fi = arcpy.FieldInfo ()
>>> fi.addField ("TestField", "TestField", "VISIBLE", "NONE")
>>> arcpy.CreateFeatureclass_management (outLoc, outName, "POLYGON", fi)
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 1806, in CreateFeatureclass
    raise e
RuntimeError: Object: Error in executing tool
>>> 

Currently I add each field one at a time after creating the feature class, but I'm thinking adding the fields at the time of feature class creation would be more efficient.

  • 1
    Use fieldinfo when creating layer from feature class. – FelixIP Jan 19 '18 at 0:10
  • 2
    The real cost of AddField is when rows exist. That said, I use SQL to CREATE TABLE the use that table as a template in Create Feature Class. Creating an empty table and adding fields is yet another option. – Vince Jan 19 '18 at 0:43
  • 3
    You have the option of a template feature class when using CreateFeatureClass or you could create an XML workspace document and import that instead of creating a feature class resources.arcgis.com/en/help/main/10.2/index.html#//…. In reality the penalty of adding a field to a new empty feature class should be fairly small... The ArcObjects method would run faster but is many times more tedious than arcpy. – Michael Stimson Jan 19 '18 at 1:22
1

I think the performance penalty of using AddField to add each field is small enough to make the functionality you seek be unnecessary.

At times in the past I know I have played with creating an empty table with the fields, when I know I want to add the same fields frequently, and used JoinField to add them in one step.

I also messed around with numpy.array and arcpy.da.ExtendTable at Creating numpy.array with variable number of fields to test arcpy.da.ExtendTable performance?

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.