/// <summary> /// Writes the header, regardless of which subtype of binary raster this is written for /// </summary> /// <param name="filename">The string filename specifying what file to load</param> public void ReadHeader(string filename) { BinaryReader br = new BinaryReader(new FileStream(filename, FileMode.Open)); StartColumn = 0; NumColumns = br.ReadInt32(); NumColumnsInFile = NumColumns; EndColumn = NumColumns - 1; StartRow = 0; NumRows = br.ReadInt32(); NumRowsInFile = NumRows; EndRow = NumRows - 1; Bounds = new RasterBounds(NumRows, NumColumns, new[] {0.0, 1.0, 0.0, NumRows, 0.0, -1.0}); CellWidth = br.ReadDouble(); Bounds.AffineCoefficients[5] = -br.ReadDouble(); // dy Xllcenter = br.ReadDouble(); Yllcenter = br.ReadDouble(); RasterDataTypes dataType = (RasterDataTypes) br.ReadInt32(); if (dataType != RasterDataTypes.DOUBLE) { throw new ArgumentException( MessageStrings.ArgumentOfWrongType_S1_S2.Replace("%S1", filename).Replace("%S2", "BinaryDoubleRaster")); } DoubleNoDataValue = br.ReadDouble(); string prj = Encoding.ASCII.GetString(br.ReadBytes(255)).Replace('\0', ' ').Trim(); if (prj != null) { if (prj.Length == 0) Projection = null; } else { Projection = new ProjectionInfo(); Projection.ReadProj4String(prj); } Notes = Encoding.ASCII.GetString(br.ReadBytes(255)).Replace('\0', ' ').Trim(); if (Notes != null) if (Notes.Length == 0) Notes = null; br.Close(); }
/// <summary> /// Writes the header, regardless of which subtype of binary raster this is written for /// </summary> /// <param name="filename">The string filename specifying what file to load</param> public void ReadHeader(string filename) { // Our older formats used ASCII encoding for the characters, not Unicode. The difference is that in the old fashion method, // of ASCII, each character is a single byte. In Unicode, it is two bytes. if we write Future binary handlers, however, they should use unicode, // not ASCII, and strings should just use the converter which has a string length followed by the unicode strings. BinaryReader br = new BinaryReader(new FileStream(filename, FileMode.Open)); StartColumn = 0; NumColumns = br.ReadInt32(); NumColumnsInFile = NumColumns; EndColumn = NumColumns - 1; StartRow = 0; NumRows = br.ReadInt32(); NumRowsInFile = NumRows; EndRow = NumRows - 1; Bounds = new RasterBounds(NumRows, NumColumns, new[] {0.0, 1.0, 0.0, NumRows, 0.0, -1.0}); CellWidth = br.ReadDouble(); Bounds.AffineCoefficients[5] = -br.ReadDouble(); // dy Xllcenter = br.ReadDouble(); Yllcenter = br.ReadDouble(); RasterDataTypes dataType = (RasterDataTypes) br.ReadInt32(); if (dataType != RasterDataTypes.SINGLE) { throw new ArgumentException( MessageStrings.ArgumentOfWrongType_S1_S2.Replace("%S1", filename).Replace("%S2", "BinaryFloatRaster")); } FloatNoDataValue = br.ReadSingle(); string proj = Encoding.ASCII.GetString(br.ReadBytes(255)).Replace('\0', ' ').Trim(); Projection = new ProjectionInfo(); Projection.ReadProj4String(proj); Notes = Encoding.ASCII.GetString(br.ReadBytes(255)).Replace('\0', ' ').Trim(); if (Notes.Length == 0) Notes = null; br.Close(); }