private static void ReadDBFFile(string dbffilename, List <XField> fields, List <XAttribute> attributes) { FileStream fsr = new FileStream(dbffilename, FileMode.Open); BinaryReader br = new BinaryReader(fsr); DBFHeader dh = (DBFHeader)XTools.FromBytes(br, typeof(DBFHeader)); int FieldCount = (dh.HeaderLength - 33) / 32; //读字段结构 fields.Clear(); for (int i = 0; i < FieldCount; i++) { fields.Add(new XField(br)); } byte END = br.ReadByte(); //1个字节作为记录项终止标识。 //读具体数值 attributes.Clear(); for (int i = 0; i < dh.RecordCount; i++) { XAttribute attribute = new XAttribute(); char tempchar = (char)br.ReadByte(); //每个记录的开始都有一个起始字节 for (int j = 0; j < FieldCount; j++) { attribute.AddValue(fields[j].DBFValueToObject(br)); } attributes.Add(attribute); } br.Close(); fsr.Close(); }
public void WriteFile(XLayer layer, string filename) { FileStream fsr = new FileStream(filename, FileMode.Create); BinaryWriter bw = new BinaryWriter(fsr); //写文件头 WriteFileHeader(layer, bw); //写图层名称 XTools.WriteString(layer.Name, bw); //写属性字段结构 foreach (XField field in layer.Fields) { XTools.WriteString(field.datatype.ToString(), bw); XTools.WriteString(field.name, bw); } //写空间对象类型 foreach (XFeature f in layer.Features) { WriteFeature(f, bw); } //关闭文件 bw.Close(); fsr.Close(); }