I am trying to copy attributes from a layer to a table but the Geometry fields are giving me problems. I need help ignoring the OID and Geometry fields and i though line 11 would do it.
The feature class fields
Shape.STArea() & Shape>STLength()
Table fields
Shape_STarea_ & Shape_STLength
I have the following but get error.
line 17, in <module>
iCur.insertRow(row)
RuntimeError: Cannot find field 'Shape.STArea()'
arcpy.env.workspace = r"C:Temp\Test.gdb"
database = r"C:Temp\Test.gdb"
fc1 = "TestLayer1
fc2 = "Table1"
dsc = arcpy.Describe(fc1)
fields = dsc.fields
# List all field names except the OID field and geometry fields
#
fieldnames = [fields.name for fields in fields if fields.name != dsc.OIDFieldName and fields.type != 'Geometry']
# Create cursors and insert new rows
with arcpy.da.SearchCursor(fc1,fieldnames) as sCur:
with arcpy.da.InsertCursor(fc2,fieldnames) as iCur:
for row in sCur:
iCur.insertRow(row)
del sCur
Solved! Go to Solution.
Have you tried GDB FeatureClass properties—ArcPy Functions | ArcGIS Desktop
Properties
Property Explanation Data Type areaFieldName (Read Only)The name of the geometry area field.
String lengthFieldName (Read Only)The name of the geometry length field.
String
use the new data access Describe instead of the old. access is via a dictionary key value
desc = arcpy.da.Describe(in_fc)
flds = arcpy.ListFields(in_fc)
[fld.name for fld in flds if fld.name != desc['OIDFieldName'] and fld.type != 'Geometry']
['Parts',
'Points',
'Curves',
'Shape_Length',
'Shape_Area',
'A0',
'A1',
'Value_0']
I got a typeError
fldnames = [fld.name for fld in flds if fld.name != desc['OIDFieldName'] and fld.type != 'Geometry']
TypeError: 'geoprocessing describe data object' object is not subscriptable
Have you tried GDB FeatureClass properties—ArcPy Functions | ArcGIS Desktop
Properties
Property Explanation Data Type areaFieldName (Read Only)The name of the geometry area field.
String lengthFieldName (Read Only)The name of the geometry length field.
String
Yes that did it and 'Shape.STArea()' and fields.name != 'Shape.STLength()' would have probably worked too.
fields.name for fields in fields if fields.name != desc.OIDFieldName and fields.type != 'Geometry' and fields.name != desc.areaFieldName and \
flds.name != desc.lengthFieldName]