Return system fields

2400
4
Jump to solution
10-10-2013 07:04 PM
GinoMellino
Occasional Contributor
Hi All.

This is a pretty straight-forward question...is there any way to return a list of system fields or differentiate between system managed fields vs user fields using ArcPy? I'm talking about being able to single out fields such as OBJECTID, FID, SHAPE.AREA, SHAPE, etc. I know I can get a reference to them by name but I was hoping there would be a more elegant way of achieving this?

Thanks in advance
Gino

P.S. I am sorry if this is a duplicate question, I did search for the answer but came up with bupkis. If so please smack my backside and send me to the correct thread :eek:
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
NeilAyres
MVP Alum
Sorry, the above code should be modified to return the name attribute of the field object...
sysFieldList = [] attFields = arcpy.ListFields(fc_name) for attField in attFields:     if attField.required:         sysFieldList.append(attField.name)  print "System Fields", sysFieldList

You can get other attributes like type, aliasName etc

Cheers,
Neil

View solution in original post

0 Kudos
4 Replies
NeilAyres
MVP Alum
Perhaps something like this :
sysFieldList = []
attFields = arcpy.ListFields(fc_name)
for attField in attFields:
    if attField.required:
        sysFieldList.append(attField)

print "System Fields", sysFieldList

Cheers,
Neil
0 Kudos
XanderBakker
Esri Esteemed Contributor
Hi Gino,

Additional to what Neil is showing you can determine the name of the Shape field by describing it:

import arcpy
desc = arcpy.Describe(r'path to your featureclass')
fldNameShape = desc.shapeFieldName


Find more info about the describe properties of a Featureclass here: FeatureClass properties (arcpy)

Another way of accessing standard fields (not determining the name though) is using tokens in for instance an arcpy.da.SearchCursor. Some examples are:

  • SHAPE@ �?? A geometry object for the feature.

  • SHAPE@AREA �?? A double of the feature's area.

  • SHAPE@LENGTH �?? A double of the feature's length.

  • OID@ �?? The value of the ObjectID field.

You can find Python code examples here: SearchCursor (arcpy.da)

Kind regards,

Xander
NeilAyres
MVP Alum
Sorry, the above code should be modified to return the name attribute of the field object...
sysFieldList = [] attFields = arcpy.ListFields(fc_name) for attField in attFields:     if attField.required:         sysFieldList.append(attField.name)  print "System Fields", sysFieldList

You can get other attributes like type, aliasName etc

Cheers,
Neil
0 Kudos
GinoMellino
Occasional Contributor
Thanks for the replies guys, they are very much appreciated. Neil, that is exactly what I was after!

Thanks again!
0 Kudos