Writes dBase IV files.
Used mainly for writing ESRI Shapefile attributes.
Beispiel #1
0
        /// <summary>
        /// Writes the attribute file.
        /// </summary>
        /// <param name="featureCollection">A collection containing features which attributes is to be written</param>
        /// <param name="dbaseFile">file attributes</param>
        public void WriteAttributes(string dbaseFile, ICollection <Feature> featureCollection)
        {
            if (this._dbaseHeader == null)
            {
                throw new NullReferenceException("dbaseHeader");
            }

            if (string.IsNullOrEmpty(dbaseFile))
            {
                throw new ArgumentNullException("dbaseFile");
            }

            //if there is no file attributes - create
            if (!File.Exists(dbaseFile))
            {
                Stream file = File.Create(dbaseFile);
                file.Close();
            }

            this.RecountColumnLengths(this._dbaseHeader, featureCollection);
            this.RecountRecords(this._dbaseHeader, featureCollection);


            DbaseWriter dbaseWriter = new DbaseWriter(dbaseFile, this._dbaseHeader);

            //dbaseWriter.WriteHeader();//this._dbaseHeader);
            try
            {
                //this.RecountColumnLengths(this._dbaseHeader, featureCollection);
                dbaseWriter.WriteHeader();    //this._dbaseHeader);
                int j = 0;
                foreach (Feature feature in featureCollection)
                {
                    ArrayList values = new ArrayList();
                    for (int i = 0; i < dbaseWriter.Header.NumFields; i++)
                    {
                        values.Add(feature[dbaseWriter.Header.DBaseColumns[i].Name]);    //   attribs[Header.Fields[i].Name]);
                    }
                    dbaseWriter.Write(values, j);
                    j++;
                }

                //end of file
                dbaseWriter.Write((byte)26);
            }
            finally
            {
                dbaseWriter.Close();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Writes the attribute file.
        /// </summary>
        /// <param name="featureCollection">A collection containing features which attributes is to be written</param>
        /// <param name="dbaseFile">file attributes</param>
        public void WriteAttributes(string dbaseFile, ICollection<Feature> featureCollection)
        {
                if (this._dbaseHeader == null)
                    throw new NullReferenceException("dbaseHeader");

                if (string.IsNullOrEmpty(dbaseFile))
                    throw new ArgumentNullException("dbaseFile");

                //if there is no file attributes - create
                if (!File.Exists(dbaseFile))
                {
                    Stream file = File.Create(dbaseFile);
                    file.Close();
                }

                this.RecountColumnLengths(this._dbaseHeader, featureCollection);
                this.RecountRecords(this._dbaseHeader,featureCollection);
                

                DbaseWriter  dbaseWriter = new DbaseWriter(dbaseFile, this._dbaseHeader);
                //dbaseWriter.WriteHeader();//this._dbaseHeader);
                try
                {

                    //this.RecountColumnLengths(this._dbaseHeader, featureCollection);
                    dbaseWriter.WriteHeader();//this._dbaseHeader);
                    int j = 0;
                    foreach (Feature feature in featureCollection)
                    {
                        ArrayList values = new ArrayList();
                        for (int i = 0; i < dbaseWriter.Header.NumFields; i++)
                            values.Add(feature[dbaseWriter.Header.DBaseColumns[i].Name]);//   attribs[Header.Fields[i].Name]);
                        dbaseWriter.Write(values, j);
                        j++;
                    }

                    //end of file
                    dbaseWriter.Write((byte)26);
                }
                finally
                {
                    dbaseWriter.Close();
                }
        }