I'm trying to create a simple function to sort based on a point FC X & Y values and then add a sequential ID. I know the 'old' update cursor supports sort fields directly, where arcpy.da.searchcursor you must use an SQL statement such as ORDER BY.
I'm leaning towards using shape tokens since the input FC may or may not have an X & Y coordinate field.
fields = ['OID@','SHAPE@X','SHAPE@Y','NewID']
sqlOrder = "ORDER BY {0}, {1} ASC".format(fields[1],fields[2])
startNumber = 100
with arcpy.da.UpdateCursor('Renum', fields,sql_clause = (None, sqlOrder) as cusor:
for row in cursor:
row[3] = startNumber + 1
cursor.updateRow(row)For which I'm getting:
Traceback (most recent call last):
File "<string>", line 2, in <module>
RuntimeError: Bad syntax in request. (status code 400).
The input FC is in a fGDB so SQL ORDER BY is supported (according to the documentation).
I guess this is less so about evaluating this code as it is the question: do SQL statements accepts shape tokens?
I guess my alternative is to simply add XY values and then have a known set of fields to work with.