2

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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 18, 2018 at 23:39
3
  • 1
    Use fieldinfo when creating layer from feature class. Commented Jan 19, 2018 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. Commented Jan 19, 2018 at 0:43
  • 4
    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. Commented Jan 19, 2018 at 1:22

1 Answer 1

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?

answered Jan 19, 2018 at 0:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.