zoukankan      html  css  js  c++  java
  • 关于FastDBF库读写ArcGis dbf文件的小bug

    该库托管于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)//Encoding注意UTF-8与GBK
                    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));
          
        }
  • 相关阅读:
    Jenkins自定义变量共享
    HTML中调用JavaScript的几种情况和规范写法
    [Python] 建 Django 项目
    [Django] Window上通过IIS发布Django网站
    [Python] 怎么把HTML的报告转换为图片,利用无头浏览器
    VMware vSphere Client
    mysql优化
    LINUX 内核的优化
    sed强大的固定替换格式
    nfs以及优化
  • 原文地址:https://www.cnblogs.com/yzhyingcool/p/10591063.html
Copyright © 2011-2022 走看看