Beispiel #1
0
        /// <summary>
        /// Gets the feature at the specified Object ID
        /// </summary>
        /// <param name="oid">Row index. Zero-based.</param>
        /// <param name="table">The feature table containing the schema used to
        /// read the row.</param>
        /// <returns>The feature row for the given row index</returns>
        /// <exception cref="InvalidDbaseFileOperationException">
        /// Thrown if this reader is closed (check <see cref="IsOpen"/> before calling),
        /// or if the column is an unsupported type.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="oid"/>
        /// &lt; 0 or <paramref name="oid"/> &gt;= <see cref="RecordCount"/></exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="table"/> is
        /// null</exception>
        /// <exception cref="ObjectDisposedException">Thrown when the method is called and
        /// Object has been disposed</exception>
        internal IFeatureDataRecord GetAttributes(UInt32 oid, FeatureDataTable <UInt32> table)
        {
            checkState();

            if (!_isOpen)
            {
                throw new InvalidDbaseFileOperationException("An attempt was made to read " +
                                                             "from a closed dBase file");
            }

            if (oid <= 0 || oid > RecordCount)
            {
                throw new ArgumentOutOfRangeException("Invalid DataRow requested " +
                                                      "at index " + oid);
            }

            if (_reader.IsRowDeleted(oid)) // is record marked deleted?
            {
                return(null);
            }

            if (table != null)
            {
                FeatureDataRow <UInt32> dr = table.NewRow(oid);

                foreach (DbaseField field in Header.Columns)
                {
                    try
                    {
                        dr[field.ColumnName] = _reader.GetValue(oid, field);
                    }
                    catch (NotSupportedException)
                    {
                        String message = String.Format("Column type {0} is not supported.",
                                                       field.DataType);
                        throw new InvalidDbaseFileOperationException(message);
                    }
                }

                return(dr);
            }
            else
            {
                ShapeFileFeatureDataRecord dr = new ShapeFileFeatureDataRecord(Header.Columns);
                dr.SetColumnValue(0, oid);
                dr.SetColumnValues(1, 1 + Header.Columns.Count, _reader.GetValues(oid));//jd: added 1 to Header.Columns.Count because we are offsetting the start index by one (OID is stored at zero)

                return(dr);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the feature at the specified Object ID
        /// </summary>
        /// <param name="oid">Row index. Zero-based.</param>
        /// <param name="table">The feature table containing the schema used to 
        /// read the row.</param>
        /// <returns>The feature row for the given row index</returns>
        /// <exception cref="InvalidDbaseFileOperationException">
        /// Thrown if this reader is closed (check <see cref="IsOpen"/> before calling), 
        /// or if the column is an unsupported type.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="oid"/> 
        /// &lt; 0 or <paramref name="oid"/> &gt;= <see cref="RecordCount"/></exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="table"/> is 
        /// null</exception>
        /// <exception cref="ObjectDisposedException">Thrown when the method is called and 
        /// Object has been disposed</exception>
        internal IFeatureDataRecord GetAttributes(UInt32 oid, FeatureDataTable<UInt32> table)
        {
            checkState();

            if (!_isOpen)
            {
                throw new InvalidDbaseFileOperationException("An attempt was made to read " +
                                                             "from a closed dBase file");
            }

            if (oid <= 0 || oid > RecordCount)
            {
                throw new ArgumentOutOfRangeException("Invalid DataRow requested " +
                                                      "at index " + oid);
            }

            if (_reader.IsRowDeleted(oid)) // is record marked deleted?
            {
                return null;
            }

            if (table != null)
            {
                FeatureDataRow<UInt32> dr = table.NewRow(oid);

                foreach (DbaseField field in Header.Columns)
                {
                    try
                    {
                        dr[field.ColumnName] = _reader.GetValue(oid, field);
                    }
                    catch (NotSupportedException)
                    {
                        String message = String.Format("Column type {0} is not supported.",
                                                       field.DataType);
                        throw new InvalidDbaseFileOperationException(message);
                    }
                }

                return dr;
            }
            else
            {
                ShapeFileFeatureDataRecord dr = new ShapeFileFeatureDataRecord(Header.Columns);
                dr.SetColumnValue(0, oid);
                dr.SetColumnValues(1, 1 + Header.Columns.Count, _reader.GetValues(oid));//jd: added 1 to Header.Columns.Count because we are offsetting the start index by one (OID is stored at zero)

                return dr;
            }
        }