I have a question on how to implement a TableSort in ArcGISPro SDK
In ArcObjects, the ArcMap SDK, you can do something like this
TableSort tableSort = new ESRI.ArcGIS.Geodatabase.TableSortClass();
tableSort.Fields = refMileField;
tableSort.set_Ascending(refMileField, true);
tableSort.QueryFilter = profileScenarioFilter2;
tableSort.Table = profileScenarioTable.Table;
tableSort.Sort(null);
Later on I use this TableSort in order to give a RowCursor its rows it needs.
What is the proper way I can convert TableSort to a RowCursor?
Or is there another way I need to convert the TableSort to another type?
Thank You
Solved! Go to Solution.
Thanks for taking the time to answer. My solution ended up being
ArcGIS.Core.Data.SortDescription refMileFieldSortDescription = new ArcGIS.Core.Data.SortDescription(refMileActualField);
refMileFieldSortDescription.SortOrder = ArcGIS.Core.Data.SortOrder.Ascending;
TableSortDescription tableSortDescription = new TableSortDescription(new List<ArcGIS.Core.Data.SortDescription>() { refMileFieldSortDescription } );
tableSortDescription.QueryFilter = profileScenarioFilter2;
Table tableSortTable = profileScenarioTable.GetTable();
RowCursor sortedScenarioCursor = tableSortTable.Sort(tableSortDescription);
you can put a Query filter in the TableSortDescription, which merged the two into being kind of a sort query command.
Hi James,
Check out this section in the Geodatabase concepts document; I think it should answer your questions.
Thanks,
--Rich
Thanks I transmuted my code to this....
ArcGIS.Core.Data.SortDescription refMileFieldSortDescription = new ArcGIS.Core.Data.SortDescription(refMileActualField);
refMileFieldSortDescription.SortOrder = ArcGIS.Core.Data.SortOrder.Ascending;
TableSortDescription tableSortDescription = new TableSortDescription(new List<ArcGIS.Core.Data.SortDescription>() { refMileFieldSortDescription } );
Table tableSortTable = profileScenarioTable.GetTable();
RowCursor sortedScenarioCursorFromSort = tableSortTable.Sort(tableSortDescription);
RowCursor sortedScenarioCursor = tableSortTable.Search(profileScenarioFilter2, false);
But now I have a new question.
How can I make sure I sort, and run my Query Filter at the same time? They both return RowCursors, but how can I merge Sorting and Searching to give me the correct rowcursor after sorting, then searching.
Thank you.
James,
I think setting the TableSortDescription.QueryFilter property will provide what you're looking for.
--Rich
Thanks that did it!
Hi James,
There is simpliest way to do what you need. Add to your QueryFilter variable PostfixClause and run Search on your table like this:
public async Task SearchingATable()
{
try
{
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => {
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
using (Table table = geodatabase.OpenDataset<Table>("EmployeeInfo"))
{
QueryFilter queryFilter = new QueryFilter
{
WhereClause = "COSTCTRN = 'Information Technology'",
SubFields = "KNOWNAS, OFFICE, LOCATION",
PostfixClause = "ORDER BY OFFICE"
};
using (RowCursor rowCursor = table.Search(queryFilter, false))
{
while (rowCursor.MoveNext())
{
using (Row row = rowCursor.Current)
{
string location = Convert.ToString(row["LOCATION"]);
string knownAs = Convert.ToString(row["KNOWNAS"]);
}
}
}
}
});
}
catch (GeodatabaseFieldException fieldException)
{
// One of the fields in the where clause might not exist. There are multiple ways this can be handled:
// Handle error appropriately
}
catch (Exception exception)
{
// logger.Error(exception.Message);
}
}
Sample from ArcGIS Pro snippets:
https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Geodatabase
Thanks for taking the time to answer. My solution ended up being
ArcGIS.Core.Data.SortDescription refMileFieldSortDescription = new ArcGIS.Core.Data.SortDescription(refMileActualField);
refMileFieldSortDescription.SortOrder = ArcGIS.Core.Data.SortOrder.Ascending;
TableSortDescription tableSortDescription = new TableSortDescription(new List<ArcGIS.Core.Data.SortDescription>() { refMileFieldSortDescription } );
tableSortDescription.QueryFilter = profileScenarioFilter2;
Table tableSortTable = profileScenarioTable.GetTable();
RowCursor sortedScenarioCursor = tableSortTable.Sort(tableSortDescription);
you can put a Query filter in the TableSortDescription, which merged the two into being kind of a sort query command.