public ShapefileDataReader(IStreamProviderRegistry streamProviderRegistry, IGeometryFactory geometryFactory)
        {
            if (streamProviderRegistry == null)
            {
                throw new ArgumentNullException("streamProviderRegistry");
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException("geometryFactory");
            }
            _open = true;

            _dbfReader = new DbaseFileReader(streamProviderRegistry);
            _shpReader = new ShapefileReader(streamProviderRegistry, 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;
        }
Example #2
0
            /// <summary>
            /// Initializes a new instance of the <see cref="DbaseFileEnumerator"/> class.
            /// </summary>
            /// <param name="parent"></param>
            public DbaseFileEnumerator(DbaseFileReader parent)
            {
                _parent = parent;
                Stream stream = parent._streamProvider.OpenRead();

                _dbfReader = new BinaryReader(stream, parent._header.Encoding);
                ReadHeader();
            }
        /// <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>
        /// <param name="encoding">The encoding to use for reading the attribute data</param>
        public ShapefileDataReader(string filename, IGeometryFactory geometryFactory, Encoding encoding)
        {
            if (String.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException("filename");
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException("geometryFactory");
            }

            _open = true;

            string prjFile = Path.ChangeExtension(filename, ".prj");

            CoordinateSystem = File.Exists(prjFile) ? PrjFileReader.Read(prjFile) : null;

            string dbfFile = Path.ChangeExtension(filename, "dbf");

            _dbfReader = encoding != null
                ? new DbaseFileReader(dbfFile, encoding)
                : new DbaseFileReader(dbfFile);

            string shpFile = Path.ChangeExtension(filename, "shp");

            _shpReader = new ShapefileReader(shpFile, 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;
            CheckIfHasFID();
        }