Represents a header of dBase-file.
示例#1
0
 /// <summary>
 /// Computes the sizes of attribute fileds taking into accound
 /// attribute values of the features.
 /// </summary>
 /// <param name="DbaseHeader">The header of the dBase attribute file</param>
 /// <param name="Features">Enumerator of features</param>
 private void RecountColumnLengths(DbaseFileHeader DbaseHeader, IEnumerable Features)
 {
     foreach (DbaseFieldDescriptor field in DbaseHeader.DBaseColumns)
     {
         var fieldValues = Features.OfType <Feature>().Select(f => f[field.Name]);
         DbaseHeader.RecountColumnLength(field, fieldValues);
     }
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of MapAround.IO.DbaseWriter
 /// </summary>
 /// <param name="filename">File name</param>
 /// <param name="dbaseHeader">A dBase file header</param>
 public DbaseWriter(string filename, DbaseFileHeader dbaseHeader)
 {
     if (filename == null)
         throw new ArgumentNullException("filename");
     this._header = dbaseHeader;
     FileStream filestream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Write);
     _writer = new BinaryWriter(filestream, this._header.Encoding);
 }
示例#3
0
        public DbaseReader(string filename)
        {

            if (!File.Exists(filename))
                throw new FileNotFoundException(String.Format("File \"{0}\" not found", filename));
            _filename = filename;
            _headerIsParsed = false;
            _dbaseHeader = new DbaseFileHeader();
        }
示例#4
0
 public DbaseReader(string filename)
 {
     if (!File.Exists(filename))
     {
         throw new FileNotFoundException(String.Format("File \"{0}\" not found", filename));
     }
     _filename       = filename;
     _headerIsParsed = false;
     _dbaseHeader    = new DbaseFileHeader();
 }
示例#5
0
        /// <summary>
        /// Gets the header from a dbf file.
        /// </summary>
        /// <param name="dbfFile">The DBF file.</param>
        /// <returns>The dBase file header</returns>
        public static DbaseFileHeader GetDbaseHeader(string dbfFile)
        {
            if (!File.Exists(dbfFile))
            {
                throw new FileNotFoundException(dbfFile + " not found");
            }
            DbaseFileHeader header = new DbaseFileHeader();

            header.Read(new BinaryReader(new FileStream(dbfFile, FileMode.Open, FileAccess.Read, FileShare.Read)));
            return(header);
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of MapAround.IO.DbaseWriter
        /// </summary>
        /// <param name="filename">File name</param>
        /// <param name="dbaseHeader">A dBase file header</param>
        public DbaseWriter(string filename, DbaseFileHeader dbaseHeader)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            this._header = dbaseHeader;
            FileStream filestream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Write);

            _writer = new BinaryWriter(filestream, this._header.Encoding);
        }
示例#7
0
        /// <summary>
        /// Generates a dBase file header.
        /// </summary>
        /// <param name="dbFields">An array containing the dBase filed descriptors</param>
        /// <param name="count">The record count</param>
        /// <returns>A stub of dBase file header</returns>
        public static DbaseFileHeader GetDbaseHeader(DbaseFieldDescriptor[] dbFields, int count)
        {
            DbaseFileHeader header = new DbaseFileHeader();

            header.NumRecords = count;

            foreach (DbaseFieldDescriptor dbField in dbFields)
            {
                header.AddColumn(dbField.Name, dbField.DbaseType, dbField.DataType, dbField.Length, dbField.DecimalCount);
            }

            return(header);
        }
示例#8
0
        /// <summary>
        /// Gets a stub of dBase file header
        /// </summary>
        /// <param name="feature">The feature</param>
        /// <param name="count">The record count</param>
        /// <param name="attributeNames">A list containing the attribute names</param>
        /// <returns>A stub of dBase file header</returns>
        public static DbaseFileHeader GetDbaseHeader(Feature feature, List <string> attributeNames, int count)
        {
            //string[] names = feature.Layer.FeatureAttributeNames.ToArray();// attribs.GetNames();
            string[]        names  = attributeNames.ToArray();// attribs.GetNames();
            DbaseFileHeader header = new DbaseFileHeader();

            header.NumRecords = count;
            int i = 0;

            foreach (string name in names)
            {
                Type type = feature.Attributes[i].GetType();// attribs.GetType(name);
                header.AddColumn(name, type);
                i++;
            }
            header.Encoding = System.Text.ASCIIEncoding.ASCII;
            return(header);
        }
示例#9
0
 /// <summary>
 /// Computes the count of DBF records
 ///  </summary>
 /// <param name="DbaseHeader">The header of the dBase attribute file</param>
 /// <param name="Features">Enumerator of features</param>
 private void RecountRecords(DbaseFileHeader DbaseHeader, IEnumerable Features)
 {
     DbaseHeader.NumRecords = Features.Cast <Feature>().Count();
 }
示例#10
0
 /// <summary>
 /// Gets the header from a dbf file.
 /// </summary>
 /// <param name="dbfFile">The DBF file.</param>
 /// <returns>The dBase file header</returns>
 public static DbaseFileHeader GetDbaseHeader(string dbfFile)
 {
     if (!File.Exists(dbfFile))
         throw new FileNotFoundException(dbfFile + " not found");
     DbaseFileHeader header = new DbaseFileHeader();
     header.Read(new BinaryReader(new FileStream(dbfFile, FileMode.Open, FileAccess.Read, FileShare.Read)));
     return header;
 }
示例#11
0
        /// <summary>
        /// Generates a dBase file header.
        /// </summary>
        /// <param name="dbFields">An array containing the dBase filed descriptors</param>
        /// <param name="count">The record count</param>
        /// <returns>A stub of dBase file header</returns>
        public static DbaseFileHeader GetDbaseHeader(DbaseFieldDescriptor[] dbFields, int count)
        {
            DbaseFileHeader header = new DbaseFileHeader();
            header.NumRecords = count;

            foreach (DbaseFieldDescriptor dbField in dbFields)
                header.AddColumn(dbField.Name, dbField.DbaseType, dbField.DataType, dbField.Length, dbField.DecimalCount);

            return header;
        }
示例#12
0
 /// <summary>
 /// Gets a stub of dBase file header
 /// </summary>
 /// <param name="feature">The feature</param>
 /// <param name="count">The record count</param>
 /// <param name="attributeNames">A list containing the attribute names</param>
 /// <returns>A stub of dBase file header</returns>
 public static DbaseFileHeader GetDbaseHeader(Feature feature, List<string> attributeNames, int count)
 {
     //string[] names = feature.Layer.FeatureAttributeNames.ToArray();// attribs.GetNames();
     string[] names = attributeNames.ToArray();// attribs.GetNames();
     DbaseFileHeader header = new DbaseFileHeader();
     header.NumRecords = count;
     int i = 0;
     foreach (string name in names)
     {
         Type type = feature.Attributes[i].GetType();// attribs.GetType(name);
         header.AddColumn(name, type);
         i++; 
     }
     header.Encoding = System.Text.ASCIIEncoding.ASCII;
     return header;
 }
示例#13
0
 /// <summary>
 /// Computes the count of DBF records
 ///  </summary>
 /// <param name="DbaseHeader">The header of the dBase attribute file</param>
 /// <param name="Features">Enumerator of features</param>
 private void RecountRecords(DbaseFileHeader DbaseHeader, IEnumerable Features)
 {
     DbaseHeader.NumRecords = Features.Cast<Feature>().Count();
 }
示例#14
0
 /// <summary>
 /// Computes the sizes of attribute fileds taking into accound 
 /// attribute values of the features.
 /// </summary>
 /// <param name="DbaseHeader">The header of the dBase attribute file</param>
 /// <param name="Features">Enumerator of features</param>
 private void RecountColumnLengths(DbaseFileHeader DbaseHeader, IEnumerable Features)
 {
     foreach (DbaseFieldDescriptor field in DbaseHeader.DBaseColumns)
     {
         var fieldValues = Features.OfType<Feature>().Select(f => f[field.Name]);
         DbaseHeader.RecountColumnLength(field, fieldValues);
     }
 }