How to implement TableSort to ArcGISPro SDK?

1104
6
Jump to solution
08-29-2019 12:06 PM
JamesKennedy1
New Contributor III

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

0 Kudos
1 Solution

Accepted Solutions
JamesKennedy1
New Contributor III

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.

View solution in original post

0 Kudos
6 Replies
RichRuh
Esri Regular Contributor

Hi James,

Check out this section in the Geodatabase concepts document; I think it should answer your questions.

Thanks,

--Rich

0 Kudos
JamesKennedy1
New Contributor III

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.

0 Kudos
RichRuh
Esri Regular Contributor

James,

I think setting the TableSortDescription.QueryFilter property will provide what you're looking for.

--Rich

0 Kudos
JamesKennedy1
New Contributor III

Thanks that did it!

GKmieliauskas
Esri Regular Contributor

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

0 Kudos
JamesKennedy1
New Contributor III

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.

0 Kudos