Select to view content in your preferred language

Any way to sort fields in .da cursors if data isn't FGDB?

529
1
Jump to solution
10-08-2012 04:30 PM
ChrisSnyder
Honored Contributor
According to the help for the data access cursors, you can only use the SQL sort parameters (ORDER_BY) if the input data is in FGDB format.

This is a dumb rhetorical question I guess, but: Does this mean we can't use the sort function in the .da cursors if we are using:

1. in_memory FCs
2. Grid attribute tables (.vats)

I am craving the speed of the .da cursors, but also the speed of Grid format (as opposed to FGDB raster format) in Spatial Analyst... I guess I will have to go with one or the other 😞
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisSnyder
Honored Contributor
My work around was to use .da cursors on the Grid vat directly, but load the records into a list, and then sort the list.

Even though I have to load the entire table into the list with the .da cursor and then sort it in list format (since the .da cursor sort paramter won't work with a Grid vat table), it is still 4x as fast as using the traditional arcpy cursors.

Okay I'm happy - even if the .da cuirsors won't (by themselves) sort a Grid vat.

#make sure the fields are specified in the proper list sort order - luickily I want to sort everything ascending sortRows = [r for r in arcpy.da.SearchCursor(comboGrd, ["PDRND","HAB", "COUNT"])] sortRows.sort() for sortRow in sortRows:    blah...    blah...

View solution in original post

0 Kudos
1 Reply
ChrisSnyder
Honored Contributor
My work around was to use .da cursors on the Grid vat directly, but load the records into a list, and then sort the list.

Even though I have to load the entire table into the list with the .da cursor and then sort it in list format (since the .da cursor sort paramter won't work with a Grid vat table), it is still 4x as fast as using the traditional arcpy cursors.

Okay I'm happy - even if the .da cuirsors won't (by themselves) sort a Grid vat.

#make sure the fields are specified in the proper list sort order - luickily I want to sort everything ascending sortRows = [r for r in arcpy.da.SearchCursor(comboGrd, ["PDRND","HAB", "COUNT"])] sortRows.sort() for sortRow in sortRows:    blah...    blah...
0 Kudos