Copy attributes from layer to table except OID and Geometry

820
4
Jump to solution
08-27-2019 09:03 AM
CCWeedcontrol
Occasional Contributor III

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
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Have you tried GDB FeatureClass properties—ArcPy Functions | ArcGIS Desktop 

Properties

PropertyExplanationData Type
areaFieldName
(Read Only)

The name of the geometry area field.

String
lengthFieldName
(Read Only)

The name of the geometry length field.

String

View solution in original post

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

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']
CCWeedcontrol
Occasional Contributor III

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
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Have you tried GDB FeatureClass properties—ArcPy Functions | ArcGIS Desktop 

Properties

PropertyExplanationData Type
areaFieldName
(Read Only)

The name of the geometry area field.

String
lengthFieldName
(Read Only)

The name of the geometry length field.

String
0 Kudos
CCWeedcontrol
Occasional Contributor III

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]‍‍‍‍
0 Kudos