コード例 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public int GetOrdinal(string name)
 {
     for (int i = 0; i < _dbfReader.GetHeader().NumFields; i++)
     {
         if (0 == CultureAwareCompare(_dbfReader.GetHeader().Fields[i].Name, name))
         {
             return(i);
         }
     }
     // Throw an exception if the ordinal cannot be found.
     throw new IndexOutOfRangeException("Could not find specified column in results.");
 }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the ShapefileDataReader class.
        /// </summary>
        /// <param name="filename">The shapefile to read (minus the .shp extension)</param>
        ///<param name="geometryFactory">The GeometryFactory to use.</param>
        public ShapefileDataReader(string filename, GeometryFactory geometryFactory)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException("geometryFactory");
            }
            _geometryFactory = geometryFactory;
            _open            = true;

            if (filename.ToLower().EndsWith(".shp"))
            {
                filename = filename.ToLower().Replace(".shp", String.Empty);
            }

            _dbfReader = new DbaseFileReader(filename + ".dbf");
            _shpReader = new ShapefileReader(filename + ".shp", geometryFactory);

            _dbfHeader   = _dbfReader.GetHeader();
            _recordCount = _dbfHeader.NumRecords;

            // copy dbase fields to our own array. Insert into the first position, the shape column
            _dbaseFields    = new DbaseFieldDescriptor[_dbfHeader.Fields.Length + 1];
            _dbaseFields[0] = DbaseFieldDescriptor.ShapeField();
            for (int i = 0; i < _dbfHeader.Fields.Length; i++)
            {
                _dbaseFields[i + 1] = _dbfHeader.Fields[i];
            }

            _shpHeader     = _shpReader.Header;
            _dbfEnumerator = _dbfReader.GetEnumerator();
            _shpEnumerator = _shpReader.GetEnumerator();
            _moreRecords   = true;
        }