2

When a Table/FeatureClass is queried using ArcPy a cursor is used, you can bring just the fields required, but sometimes it is required the whole set of fields, and "*" can be used:

with arcpy.da.UpdateCursor(table, "*", where_clause=wc) as cursor:

It is needed to know which field holds the geometry. In this case is not possible to use a token because ALL the fields are required.

The following implementation was tested:

with arcpy.da.UpdateCursor(table, "*", where_clause=wc) as cursor:
 shape_index = cursor.fields.index("Shape")
 for row in cursor:
 my_geometry = row[shape_index]

but it was found that geometry field can have other names aside "Shape".

[Edit]: arcpy package name added to the code

asked Jul 6, 2023 at 9:12
3
  • Your UpdateCursor syntax isn't valid. It's always better to specify an explicit column list, since you can then always know which field is which. Commented Jul 6, 2023 at 13:28
  • @Vince according to the documentation the syntax is valid, yes it is better to have the list of the fields, but in this case this piece of code will be used to access several feature classes. Commented Jul 7, 2023 at 12:40
  • 1
    The correct syntax is with arcpy.da.UpdateCursor(.... If you've done something with import to make what you have valid, it should be included in the code block. Commented Jul 7, 2023 at 12:48

1 Answer 1

5

You can get the the geometry field name using the Describe function.

geometry_field_name = arcpy.Describe(table).shapeFieldName
shape_index = cursor.fields.index(geometry_field_name)
answered Jul 6, 2023 at 9:44

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.