/// <summary> /// 要素排序 /// </summary> /// <param name="pFeatureClass">要排序的要素类</param> /// <param name="columName">Name of the colum.</param> private void SortFeatures(IFeatureClass pFeatureClass, string columName) { ITableSort pTableSort = new TableSortClass(); IFields pFields = pFeatureClass.Fields; int index = pFields.FindFieldByAliasName(columName); IField pField = pFields.get_Field(index); pTableSort.Fields = pField.Name; switch (_up) { case true: pTableSort.set_Ascending(pField.Name, true); _up = false; break; case false: pTableSort.set_Ascending(pField.Name, false); _up = true; break; } pTableSort.set_CaseSensitive(pField.Name, true); pTableSort.Table = pFeatureClass as ITable; pTableSort.Sort(null); ICursor pCursor = pTableSort.Rows; _pTs = pTableSort; RefreshTable(); }
/// <summary> /// 数据排序 /// </summary> /// <param name="pFeatureClass"></param> //排序函数 private void SortFeatures(IFeatureClass pFeatureClass, IFeatureLayer _pLayer) { ITableSort pTableSort = new TableSortClass(); IFields pFields = pFeatureClass.Fields; IField pField = pFields.get_Field(col_index); col_index = 0; pTableSort.Fields = pField.Name; if (up) { pTableSort.set_Ascending(pField.Name, true); } else { pTableSort.set_Ascending(pField.Name, false); } pTableSort.set_CaseSensitive(pField.Name, true); pTableSort.Table = pFeatureClass as ITable; pTableSort.Sort(null); ICursor pCursor = pTableSort.Rows; pTs = pTableSort; RefreshTable(_pLayer, pFeatureClass, dataGridView1, pField.Name, pCursor); }
public static ICursor GetGuidFieldSortedCursor([NotNull] ITable table, [NotNull] string guidFieldName, [CanBeNull] ITrackCancel trackCancel = null) { ITableSort tableSort = CreateGuidFieldTableSort(table, guidFieldName); return(GetSortedCursor(tableSort, trackCancel)); }
public static ICursor GetSortedTableCursor([NotNull] ISelectionSet selection, [NotNull] string fieldName, [CanBeNull] ITrackCancel trackCancel = null) { ITableSort tableSort = CreateTableSort(selection.Target, fieldName, selection); return(GetSortedCursor(tableSort, trackCancel)); }
private IFeatureCursor SortData(IFeatureCursor pCursor, ITrackCancel pTrackCancel) { // sort in descending by value ITable pTable = null; pTable = m_pFeatureClass as ITable; ITableSort pTableSort = null; pTableSort = new TableSort(); pTableSort.Table = pTable; pTableSort.Cursor = pCursor as ICursor; //set up the query filter. IQueryFilter pQF = null; pQF = new QueryFilter(); pQF.SubFields = "*"; pQF.WhereClause = m_pQueryFilter.WhereClause; pTableSort.QueryFilter = pQF; IProportionalSymbolRenderer pPSRend = null; pPSRend = m_pSizeRend as IProportionalSymbolRenderer; string strValueField = null; strValueField = pPSRend.Field; pTableSort.Fields = strValueField; pTableSort.set_Ascending(strValueField, false); IDataNormalization pDataNorm = null; pDataNorm = pPSRend as IDataNormalization; if (pDataNorm.NormalizationType == esriDataNormalization.esriNormalizeByField) { // comparison is not simple comparison of field values, use callback to do custom compare // get normalization field and add to table sort string strFields = ""; strFields = strFields + strValueField; string strNormField = null; strNormField = pDataNorm.NormalizationField; strFields = strFields + ","; strFields = strFields + strNormField; pTableSort.Fields = strFields; pTableSort.set_Ascending(strNormField, false); // create new custom table call sort object and connect to the TableSort object ITableSortCallBack pTableSortCallBack = null; pTableSortCallBack = new SortCallBack(pTable.Fields.FindField(strValueField), pTable.Fields.FindField(strNormField)); pTableSort.Compare = pTableSortCallBack; } // call the sort pTableSort.Sort(pTrackCancel); // retrieve the sorted rows IFeatureCursor pSortedCursor = null; pSortedCursor = pTableSort.Rows as IFeatureCursor; return pSortedCursor; }
public void CanDetect1toNNonUnique_FileGdb() { ITable relTable = CanDetect1toNNonUnique(_fgdbWorkspace); int rowCount = relTable.RowCount(null); var firstUniqueFieldName = "Relate1NNonUnique1.Unique"; // TableSort verification int sortCount = 0; ITableSort tableSort = TableSortUtils.CreateTableSort(relTable, firstUniqueFieldName); tableSort.Compare = new FieldSortCallback(); tableSort.QueryFilter = null; tableSort.Sort(null); ICursor rows = tableSort.Rows; while (rows.NextRow() != null) { sortCount++; } string version = RuntimeUtils.Version; double v; if (double.TryParse(version, out v) && v < 10.4) { Assert.AreEqual(rowCount, sortCount); } else { Assert.IsTrue(rowCount > sortCount); // bug in TableSort for joined FGDB-Tables, since 10.4 } int orderByCount = 0; // Order By verification int fieldIndex = relTable.FindField(firstUniqueFieldName); IQueryFilter filter = new QueryFilterClass(); ((IQueryFilterDefinition)filter).PostfixClause = $"ORDER BY {firstUniqueFieldName}"; int pre = int.MinValue; foreach (IRow row in new EnumCursor(relTable, filter, false)) { int id = (int)row.Value[fieldIndex]; Assert.IsTrue(pre <= id); pre = id; orderByCount++; } Assert.AreEqual(rowCount, orderByCount); }
private static ICursor GetSortedCursor([NotNull] ITableSort tableSort, [CanBeNull] ITrackCancel trackCancel) { ITable table = tableSort.Table; if (table != null) { _msg.DebugFormat("Sorting table {0}...", DatasetUtils.GetTableName(table)); } tableSort.Sort(trackCancel); return(tableSort.Rows); }
/// <summary> /// 数据排序 /// </summary> /// <param name="pFeatureClass"></param> private void SortFeatures(IFeatureClass pFeatureClass) { ITableSort pTableSort = new TableSortClass(); IFields pFields = pFeatureClass.Fields; IField pField = pFields.get_Field(col_index); pTableSort.Fields = pField.Name; pTableSort.set_Ascending(pField.Name, up); pTableSort.set_CaseSensitive(pField.Name, true); pTableSort.Table = pFeatureClass as ITable; pTableSort.Sort(null); pFCuror = (IFeatureCursor)pTableSort.Rows; pTs = pTableSort; RefreshDataGridViewDataSource(gdvAttribute, GetAttributeTable(pFClass, pFCuror)); }
public static ITableSort CreateGuidFieldTableSort([NotNull] ITable table, [NotNull] string guidFieldName) { Assert.ArgumentNotNull(table, nameof(table)); Assert.ArgumentNotNullOrEmpty(guidFieldName, nameof(guidFieldName)); int fieldIdx = table.FindField(guidFieldName); esriFieldType fieldType = table.Fields.Field[fieldIdx].Type; Assert.ArgumentCondition(fieldType == esriFieldType.esriFieldTypeGUID || fieldType == esriFieldType.esriFieldTypeGlobalID, "Field type of {0} must be Guid or Gobal ID."); ITableSort result = CreateTableSort(table, guidFieldName); result.Compare = new GuidFieldSortCallback(); return(result); }
private IFeatureCursor SortData(IFeatureCursor pCursor, IFeatureClass FClass, IQueryFilter pQfilter, string strValueFld) { //try //{ // sort in descending by value ITable pTable = null; pTable = FClass as ITable; ITableSort pTableSort = null; pTableSort = new TableSort(); pTableSort.Table = pTable; pTableSort.Cursor = pCursor as ICursor; //set up the query filter. IQueryFilter pQF = null; pQF = new QueryFilter(); pQF.SubFields = "*"; pQF.WhereClause = pQfilter.WhereClause; pTableSort.QueryFilter = pQF; pTableSort.Fields = strValueFld; pTableSort.set_Ascending(strValueFld, true); // call the sort pTableSort.Sort(null); // retrieve the sorted rows IFeatureCursor pSortedCursor = null; pSortedCursor = pTableSort.Rows as IFeatureCursor; return(pSortedCursor); //} //catch (Exception e) //{ // System.Diagnostics.Debug.WriteLine("Sorting Error: " + e.Message); // return null; //} }