码迷,mamicode.com
首页 > 数据库 > 详细

关于SocialExplorer.IO.FastDBF库读写ArcGis dbf文件的两个小bug

时间:2019-03-24 23:08:35      阅读:525      评论:0      收藏:0      [点我收藏+]

标签:value   文件头   string   ble   gets   mit   format   values   ESS   

该库托管于GitHub,地址:https://github.com/SocialExplorer/FastDBF

贡献者应该都是老外,所以

1、分析文件头字段部分时,如果字段名有中文命名会出错

在DbfHeader类的Read(BinaryReader reader)方法

                //char[] buffer = new char[11];
                //buffer = reader.ReadChars(11);
                //string sFieldName = new string(buffer);
                //yang:ReadChars(11)读取中文字段名时会出错,已改为ReadBytes(11)
                byte[] bytes = reader.ReadBytes(11);
                string sFieldName = Encoding.Default.GetString(bytes);
                int nullPoint = sFieldName.IndexOf((char)0);
                if (nullPoint != -1)
                    sFieldName = sFieldName.Substring(0, nullPoint);                    

2、在DbfColumn类,没有设定字段类型可能存在的Float

 public enum DbfColumnType
    { 
      
      /// <summary>
      /// Character  less than 254 length
      /// ASCII text less than 254 characters long in dBASE. 
      /// 
      /// Character fields can be up to 32 KB long (in Clipper and FoxPro) using decimal 
      /// count as high byte in field length. It‘s possible to use up to 64KB long fields 
      /// by reading length as unsigned.
      /// 
      /// </summary>
      Character = 0,
      
      /// <summary>
      /// Number     Length: less than 18 
      ///   ASCII text up till 18 characters long (include sign and decimal point). 
      /// 
      /// Valid characters: 
      ///    "0" - "9" and "-". Number fields can be up to 20 characters long in FoxPro and Clipper. 
      /// </summary>
      /// <remarks>
      /// We are not enforcing this 18 char limit.
      /// </remarks>
      Number = 1,
      
      /// <summary>
      ///  L  Logical  Length: 1    Boolean/byte (8 bit) 
      ///  
      ///  Legal values: 
      ///   ?     Not initialised (default)
      ///   Y,y     Yes
      ///   N,n     No
      ///   F,f     False
      ///   T,t     True
      ///   Logical fields are always displayed using T/F/?. Some sources claims 
      ///   that space (ASCII 20h) is valid for not initialised. Space may occur, but is not defined.      
      /// </summary>
      Boolean = 2,
      
      /// <summary>
      /// D     Date     Length: 8  Date in format YYYYMMDD. A date like 0000-00- 00 is *NOT* valid. 
      /// </summary>
      Date = 3,
      
      /// <summary>
      /// M     Memo     Length: 10     Pointer to ASCII text field in memo file 10 digits representing a pointer to a DBT block (default is blanks). 
      /// </summary>
      Memo = 4,
      
      /// <summary>
      /// B     Binary          (dBASE V) Like Memo fields, but not for text processing.
      /// </summary>
      Binary = 5,
      
      /// <summary>
      /// I     Integer     Length: 4 byte little endian integer     (FoxPro)
      /// </summary>
      Integer = 6,
        /// <summary>
        ///yang:添加 F Float
        /// </summary>
      Float = 7 ,
    }
 public char ColumnTypeChar
    { 
      get
      { 
        switch(mType)
        {
          case DbfColumnType.Number:
            return N;
          
          case DbfColumnType.Character:
            return C;
          
          case DbfColumnType.Binary:
            return B;
            
          case DbfColumnType.Boolean:
            return L;
          
          case DbfColumnType.Date:
            return D;
          
          case DbfColumnType.Integer:
            return I;

          case DbfColumnType.Memo:
            return M;
          //yang:新加Float字段类型
          case DbfColumnType.Float:
            return F;
          
        }
        
        throw new Exception("Unrecognized field type!");
        
      }
    }
public static DbfColumnType GetDbaseType(char c)
    { 
      switch(c.ToString().ToUpper())
      { 
        case "C": return DbfColumnType.Character;
        case "N": return DbfColumnType.Number;
        case "B": return DbfColumnType.Binary;
        case "L": return DbfColumnType.Boolean;
        case "D": return DbfColumnType.Date;
        case "I": return DbfColumnType.Integer;
        case "M": return DbfColumnType.Memo;
        //yang:新加Float字段类型
        case "F": return DbfColumnType.Number;
      }
      
      throw new NotSupportedException(String.Format("{0} does not have a corresponding dbase type.", c));
      
    }

 

关于SocialExplorer.IO.FastDBF库读写ArcGis dbf文件的两个小bug

标签:value   文件头   string   ble   gets   mit   format   values   ESS   

原文地址:https://www.cnblogs.com/yzhyingcool/p/10591063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!