/// <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); } }
/// <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); }
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(); }
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(); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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(); }
/// <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; }
/// <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; }
/// <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; }
/// <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(); }
/// <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); } }