Ejemplo n.º 1
0
        /// <summary>
        /// Creates the Attributes Table if it does not already exist.
        /// </summary>
        private void InitAttributeTable()
        {
            // The Attributes either don't exist or have been loaded and will now replace the ones in the file.
            if (Attributes == null || Attributes.Table?.Columns.Count > 0)
            {
                return;
            }

            // Only add an FID field if there are no attributes at all.
            IDataTable newTable = new DS_DataTable();

            newTable.Columns.Add("FID");

            // Added by [email protected] - Index mode has no attributes and no features - so Features.count is Null and so was not adding any rows and failing
            int numRows = IndexMode ? ShapeIndices.Count : Features.Count;

            for (int i = 0; i < numRows; i++)
            {
                IDataRow dr = newTable.NewRow();
                dr["FID"] = i;
                newTable.Rows.Add(dr);
            }

            Attributes.Table = newTable;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads just the content requested in order to satisfy the paging ability of VirtualMode for the DataGridView
        /// </summary>
        /// <param name="startIndex">The integer lower page boundary</param>
        /// <param name="numRows">The integer number of attribute rows to return for the page</param>
        /// <param name="fieldNames">The list or array of fieldnames to return.</param>
        /// <returns>A DataTable populated with data rows with only the specified values.</returns>
        public override IDataTable GetAttributes(int startIndex, int numRows, IEnumerable <string> fieldNames)
        {
            if (AttributesPopulated)
            {
                return(base.GetAttributes(startIndex, numRows, fieldNames));
            }
            IDataTable result = new DS_DataTable();

            DataColumn[] columns = GetColumns();

            // Always add FID in this paging scenario.
            result.Columns.Add("FID", typeof(int));

            var fields = fieldNames as IList <string> ?? fieldNames.ToList();

            foreach (string name in fields)
            {
                foreach (var col in columns)
                {
                    if (string.Equals(col.ColumnName, name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        result.Columns.Add(col);
                        break;
                    }
                }
            }

            for (int i = 0; i < numRows; i++)
            {
                IDataRow dr = result.NewRow();
                dr["FID"] = startIndex + i;
                result.Rows.Add(dr);
            }

            // Most use cases with an expression use only one or two fieldnames. Tailor for better
            // performance in that case, at the cost of performance in the "read all " case.
            // The other overload without fieldnames specified is designed for that case.
            foreach (string field in fields)
            {
                if (field == "FID")
                {
                    continue;
                }
                object[] values = _attributeTable.SupplyPageOfData(startIndex, numRows, field);
                for (int i = 0; i < numRows; i++)
                {
                    result.Rows[i][field] = values[i];
                }
            }

            return(result);
        }