Esempio n. 1
0
        /// <summary>
        /// Opens the specified file
        /// </summary>
        public override void Open()
        {
            NoDataValue = Global.ToDouble(Global.MinimumValue <T>()); // Sets it to the appropriate minimum for the int datatype

            ReadHeader(Filename);

            StartRow         = 0;
            EndRow           = NumRows - 1;
            StartColumn      = 0;
            EndColumn        = NumColumns - 1;
            NumColumnsInFile = NumColumns;
            NumRowsInFile    = NumRows;
            NumValueCells    = 0;
            Value            = new ValueGrid <T>(this);

            DataType = typeof(T);

            if (base.NumColumnsInFile * base.NumRowsInFile < 64000000)
            {
                base.IsInRam = true;
                Data         = ReadRaster();
                base.GetStatistics();
            }
            else
            {
                base.IsInRam = false;
                // Don't read in any data at this point.  Let the user use ReadRaster for specific blocks.
            }
        }
Esempio n. 2
0
        /// <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
            NumValueCells = 0;
            if (IsInRam)
            {
                Bounds = new RasterBounds(NumRows, NumColumns, new[] { 0.5, 1.0, 0.0, NumRows - .5, 0.0, -1.0 });
                Data   = new T[NumRows][];
                for (int row = 0; row < NumRows; row++)
                {
                    Data[row] = new T[NumColumns];
                }
            }

            Value       = new ValueGrid <T>(this);
            NoDataValue = Global.ToDouble(Global.MinimumValue <T>());
            DataType    = typeof(T);
        }
Esempio n. 3
0
        /// <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
            Bounds.AffineCoefficients = new AffineTransform(Bounds.AffineCoefficients).TransfromToCorner(startColumn, startRow);
            if (inRam)
            {
                if (NumRows * NumColumns < 64000000)
                {
                    IsInRam = true;
                    Read();
                }
            }

            Value = new ValueGrid <T>(this);
        }
Esempio n. 4
0
        /// <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 ValueGrid <T>(this);
        }
Esempio n. 5
0
 /// <inheritdoc/>
 protected override void Dispose(bool disposeManagedResources)
 {
     if (disposeManagedResources)
     {
         Data = null;
         ValuesT = null;
     }
     base.Dispose(disposeManagedResources);
 }
Esempio n. 6
0
 /// <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 ValueGrid <T>(this);
 }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Raster{T}"/> class.
        /// </summary>
        /// <param name="numRows">The number of rows in the raster</param>
        /// <param name="numColumns">The number of columns in the raster</param>
        /// <param name="valueGrid">The default ValueGrid only supports standard numeric types, but if a different kind of value grid is needed, this allows it.</param>
        public Raster(int numRows, int numColumns, ValueGrid <T> valueGrid)
        {
            NumRows    = numRows;
            NumColumns = numColumns;
            IsInRam    = true;
            DataType   = typeof(T);
            if (numRows * numColumns > 64000000)
            {
                NumRowsInFile    = numRows;
                NumColumnsInFile = numColumns;
                IsInRam          = false;
                Bounds           = new RasterBounds(numRows, numColumns, new[] { 0.5, 1.0, 0.0, numRows - .5, 0.0, -1.0 });
                NoDataValue      = 0; // sets the no-data value to the minimum value for the specified type.
                ValuesT          = valueGrid;
                Value            = ValuesT;
                return;
            }

            Initialize();
        }