/// <summary> /// Opens a new instance of the BinaryRaster /// </summary> /// <param name="filename">The string filename of the raster file to open</param> /// <param name="inRam">Boolean, indicates whether or not the values for the raster should be loaded into memory</param> public virtual void Open(string filename, bool inRam) { Filename = filename; ReadHeader(filename); if (inRam) { if (NumRowsInFile*NumColumnsInFile < 64000000) { IsInRam = true; Read(); } } Value = new DoubleValueGrid(this); }
/// <summary> /// This converts this object into a raster defined by the specified window dimensions. /// </summary> /// <param name="filename">The string filename to open</param> /// <param name="startRow">The integer row index to become the first row to load into this raster.</param> /// <param name="endRow">The 0 based integer row index to become the last row included in this raster.</param> /// <param name="startColumn">The 0 based integer column index for the first column of the raster.</param> /// <param name="endColumn">The 0 based integer column index for the last column to include in this raster.</param> /// <param name="inRam">Boolean. If this is true and the window is small enough, this will load the window into ram.</param> public virtual void OpenWindow(string filename, int startRow, int endRow, int startColumn, int endColumn, bool inRam) { Filename = filename; ReadHeader(filename); NumRows = endRow - startRow + 1; NumColumns = endColumn - startColumn + 1; StartColumn = startColumn; StartRow = startRow; EndColumn = endColumn; EndRow = EndRow; // Reposition the "raster" so that it matches the window, not the whole raster // X = [0] + [1] * column + [2] * row; // Y = [3] + [4] * column + [5] * row; // Translation only needs to change two coefficients Bounds.AffineCoefficients[0] = Bounds.AffineCoefficients[0] + Bounds.AffineCoefficients[1]*startColumn + Bounds.AffineCoefficients[2]*startRow; Bounds.AffineCoefficients[3] = Bounds.AffineCoefficients[3] + Bounds.AffineCoefficients[4]*startColumn + Bounds.AffineCoefficients[5]*startRow; if (inRam) { if (NumRows*NumColumns < 64000000) { IsInRam = true; Read(); } } Value = new DoubleValueGrid(this); }
/// <summary> /// Calls the basic setup for the raster /// </summary> protected void Initialize() { StartRow = 0; EndRow = NumRows-1; StartColumn = 0; EndColumn = NumColumns - 1; NumColumnsInFile = NumColumns; NumRowsInFile = NumRows; // Just set the cell size to one Bounds = new RasterBounds(NumRows, NumColumns, new[] { 0.5, 1.0, 0.0, NumRows - .5, 0.0, -1.0 }); NumValueCells = 0; NoDataValue = int.MinValue;// sets the no-data value to the minimum value for the specified type. if (IsInRam) { Data = new double[NumRows][]; for (int row = 0; row < NumRows; row++) { Data[row] = new double[NumColumns]; } } Value = new DoubleValueGrid(this); _doubleNoDataValue = double.MinValue; // Sets it to the appropriate minimum for the int datatype }