Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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.
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Obtains only the statistics for the small window specified by startRow, endRow etc.
        /// This only works if the window is also InRam.
        /// </summary>
        public void GetWindowStatistics()
        {
            if (IsInRam == false)
            {
                throw new ArgumentException(DataStrings.RasterRequiresCast);
            }

            ProgressMeter pm = new ProgressMeter(ProgressHandler, "Calculating Statistics.", NumRows);

            double total    = 0;
            double sqrTotal = 0;
            int    count    = 0;
            T      min      = Global.MaximumValue <T>();
            T      max      = Global.MinimumValue <T>();

            for (int row = 0; row < NumRows; row++)
            {
                for (int col = 0; col < NumColumns; col++)
                {
                    T      val    = Data[row][col];
                    double dblVal = Global.ToDouble(val);
                    if (dblVal != NoDataValue)
                    {
                        if (val.CompareTo(max) > 0)
                        {
                            max = val;
                        }
                        if (val.CompareTo(min) < 0)
                        {
                            min = val;
                        }

                        total    += dblVal;
                        sqrTotal += dblVal * dblVal;
                        count++;
                    }
                }

                pm.CurrentValue = row;
            }

            Value.Updated = false;
            Minimum       = Global.ToDouble(min);
            Maximum       = Global.ToDouble(max);
            NumValueCells = count;
            StdDeviation  = (float)Math.Sqrt((sqrTotal / NumValueCells) - (total / NumValueCells * (total / NumValueCells)));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets or sets a value at the 0 row, 0 column index.
 /// </summary>
 /// <param name="row">The 0 based vertical row index from the top</param>
 /// <param name="column">The 0 based horizontal column index from the left</param>
 /// <returns>An object reference to the actual value in the data member.</returns>
 public double this[int row, int column]
 {
     get
     {
         if (_sourceRaster.IsInRam)
         {
             return(ToDouble(_sourceRaster.Data[row][column]));
         }
         if (_rowBuffer[0] == null)
         {
             _rowBuffer[0] = _sourceRaster.ReadRow(_topRow);
         }
         if (_rowBuffer[1] == null)
         {
             _rowBuffer[1] = _sourceRaster.ReadRow(_topRow + 1);
         }
         if (_rowBuffer[2] == null)
         {
             _rowBuffer[2] = _sourceRaster.ReadRow(_topRow + 2);
         }
         int shift = row - _topRow;
         if (shift >= 0 && shift < 3)
         {
             // the value is in a row buffer
             return(ToDouble(_rowBuffer[row - _topRow][column]));
         }
         // the value was not found in the buffer.  If the value is below the row buffer, load the new row as the bottom row.
         if (shift == 3)
         {
             _rowBuffer[0] = _rowBuffer[1];
             _rowBuffer[1] = _rowBuffer[2];
             _rowBuffer[2] = _sourceRaster.ReadRow(row);
             return(ToDouble(_rowBuffer[2][column]));
         }
         if (shift == 4)
         {
             _rowBuffer[0] = _rowBuffer[2];
             _rowBuffer[1] = _sourceRaster.ReadRow(row - 1);
             _rowBuffer[2] = _sourceRaster.ReadRow(row);
             return(ToDouble(_rowBuffer[2][column]));
         }
         if (shift > 4)
         {
             _rowBuffer[0] = _sourceRaster.ReadRow(row - 2);
             _rowBuffer[1] = _sourceRaster.ReadRow(row - 1);
             _rowBuffer[2] = _sourceRaster.ReadRow(row);
             return(ToDouble(_rowBuffer[2][column]));
         }
         if (shift == -1)
         {
             _rowBuffer[0] = _sourceRaster.ReadRow(row);
             _rowBuffer[1] = _rowBuffer[0];
             _rowBuffer[2] = _rowBuffer[1];
             return(ToDouble(_rowBuffer[0][column]));
         }
         if (shift == -2)
         {
             _rowBuffer[0] = _sourceRaster.ReadRow(row);
             _rowBuffer[1] = _sourceRaster.ReadRow(row + 1);
             _rowBuffer[2] = _rowBuffer[0];
             return(ToDouble(_rowBuffer[0][column]));
         }
         if (shift < -2)
         {
             _rowBuffer[0] = _sourceRaster.ReadRow(row);
             _rowBuffer[1] = _sourceRaster.ReadRow(row + 1);
             _rowBuffer[2] = _sourceRaster.ReadRow(row + 2);
             return(ToDouble(_rowBuffer[0][column]));
         }
         // this should never happen
         throw new ApplicationException(DataStrings.IndexingErrorIn_S.Replace("%S", "Raster.Value[" + row + ", " + column + "]"));
     }
     set
     {
         _updated = true;
         if (!_sourceRaster.IsInRam)
         {
             return;
         }
         T test = (T)Convert.ChangeType(value, typeof(T));
         if (test.CompareTo(Global.MaximumValue <T>()) > 0)
         {
             _sourceRaster.Data[row][column] = Global.MaximumValue <T>();
         }
         else if (test.CompareTo(Global.MinimumValue <T>()) < 0)
         {
             _sourceRaster.Data[row][column] = Global.MinimumValue <T>();
         }
         else
         {
             // This is slow so only do this when we have to.
             _sourceRaster.Data[row][column] = test;
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the statistics of all the values. If the entire content is not currently in-ram,
        /// ReadRow will be used to read individual lines and perform the calculations.
        /// </summary>
        public override void GetStatistics()
        {
            ProgressMeter pm = new ProgressMeter(ProgressHandler, DataStrings.CalculatingStatistics, NumRows);

            T min = Global.MaximumValue <T>();
            T max = Global.MinimumValue <T>();

            double total    = 0;
            double sqrTotal = 0;
            int    count    = 0;

            if (!IsInRam || !this.IsFullyWindowed())
            {
                for (int row = 0; row < NumRowsInFile; row++)
                {
                    T[] values = ReadRow(row);
                    for (int col = 0; col < NumColumnsInFile; col++)
                    {
                        T      val    = values[col];
                        double dblVal = Global.ToDouble(val);
                        if (dblVal == NoDataValue)
                        {
                            continue;
                        }

                        if (val.CompareTo(max) > 0)
                        {
                            max = val;
                        }
                        if (val.CompareTo(min) < 0)
                        {
                            min = val;
                        }
                        total    += dblVal;
                        sqrTotal += dblVal * dblVal;
                        count++;
                    }

                    pm.CurrentValue = row;
                }
            }
            else
            {
                for (int row = 0; row < NumRows; row++)
                {
                    for (int col = 0; col < NumColumns; col++)
                    {
                        T      val    = Data[row][col];
                        double dblVal = Global.ToDouble(val);
                        if (dblVal == NoDataValue)
                        {
                            continue;
                        }

                        if (val.CompareTo(max) > 0)
                        {
                            max = val;
                        }
                        if (val.CompareTo(min) < 0)
                        {
                            min = val;
                        }
                        total    += dblVal;
                        sqrTotal += dblVal * dblVal;
                        count++;
                    }

                    pm.CurrentValue = row;
                }
            }

            Value.Updated = false;
            Minimum       = Global.ToDouble(min);
            Maximum       = Global.ToDouble(max);
            Mean          = total / count;
            NumValueCells = count;
            StdDeviation  = (float)Math.Sqrt((sqrTotal / NumValueCells) - (total / NumValueCells * (total / NumValueCells)));

            pm.Reset();
        }