There are no built-in methods in ArcObjects to perform grouping of rows/features. It is common task in table processing so it is strange to me that this functionality is missed. To implement grouping developers can use at now following approaches:
IQueryFilterDefinition.PostfixClause
IQueryFilter queryFilter = new QueryFilterClass
{
PostfixClause = "GROUP BY SOME_FIELD"
};
ICursor cursor = table.Search(queryFilter, true);
But:
You can sort rows with ITableSort and then iterate through records to form groups. But:
It would be great if you provide a way to group table data in ArcObjects with following key features:
It can be something like that:
public class CustomTableGroup : ITableGroupCallBack
{
public bool IsNewGroup(int[] fieldIndicies, object[] currentValues, object[] newValues)
{
// determine here if passed newValues start a new group
}
}
// ...
ITableGroup tableGroup = new TableGroupClass
{
Table = table,
Fields = "field1, field2, field3",
Group = new CustomTableGroup()
};
// ...
IGroupCursor groupCursor = null;
try
{
groupCursor = tableGroup.Group();
for (IGroup group; (group = groupCursor.NextGroup()) != null;)
{
// indices of the fields to group by
int[] fieldIndices = group.FieldIndices;
// values of the fields to group by for the current group
object[] fieldValues = group.FieldValues;
// iterate through the group
ICursor cursor = null;
try
{
cursor = group.Rows;
for (IRow row; (row = cursor.NextRow()) != null;)
{
// do something
}
}
finally
{
if (cursor != null)
Marshal.ReleaseComObject(cursor);
}
}
}
finally
{
if (groupCursor != null)
Marshal.ReleaseComObject(groupCursor);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.