示例#1
0
        private static void DrawToBitmap(IRaster raster, IRasterSymbolizer rasterSymbolizer, IntPtr rgbData, int stride, ProgressMeter pm)
        {
            if (raster.DataType == typeof(int))
            {
                DrawToBitmapT(raster.ToRaster <int>(), rasterSymbolizer, rgbData, stride, pm);
            }
            else if (raster.DataType == typeof(float))
            {
                DrawToBitmapT(raster.ToRaster <float>(), rasterSymbolizer, rgbData, stride, pm);
            }
            else if (raster.DataType == typeof(short))
            {
                DrawToBitmapT(raster.ToRaster <short>(), rasterSymbolizer, rgbData, stride, pm);
            }
            else if (raster.DataType == typeof(byte))
            {
                DrawToBitmapT(raster.ToRaster <byte>(), rasterSymbolizer, rgbData, stride, pm);
            }
            else if (raster.DataType == typeof(double))
            {
                DrawToBitmapT(raster.ToRaster <double>(), rasterSymbolizer, rgbData, stride, pm);
            }
            else
            {
                DrawToBitmapT(raster, raster.NoDataValue, (row, col) => raster.Value[row, col], i => Marshal.ReadByte(rgbData, i), (i, b) => Marshal.WriteByte(rgbData, i, b), rasterSymbolizer, stride, pm);

                if (rasterSymbolizer.IsSmoothed)
                {
                    var mySmoother = new Smoother(stride, raster.NumColumns, raster.NumRows, rgbData, pm.ProgressHandler);
                    mySmoother.Smooth();
                }
            }
        }
示例#2
0
 /// <summary>
 /// Creates a bitmap using only the colorscheme, even if a hillshade was specified.
 /// </summary>
 /// <param name="raster">The Raster containing values that need to be drawn to the bitmap as a color scheme.</param>
 /// <param name="rasterSymbolizer">The raster symbolizer to use.</param>
 /// <param name="bitmap">The bitmap to edit. Ensure that this has been created and saved at least once.</param>
 /// <param name="progressHandler">An IProgressHandler implementation to receive progress updates.</param>
 /// <exception cref="ArgumentNullException">rasterSymbolizer cannot be null.</exception>
 public static void PaintColorSchemeToBitmap(this IRaster raster, IRasterSymbolizer rasterSymbolizer, Bitmap bitmap, IProgressHandler progressHandler)
 {
     if (raster.DataType == typeof(int))
     {
         PaintColorSchemeToBitmapT(raster.ToRaster <int>(), rasterSymbolizer, bitmap, progressHandler);
     }
     else if (raster.DataType == typeof(float))
     {
         PaintColorSchemeToBitmapT(raster.ToRaster <float>(), rasterSymbolizer, bitmap, progressHandler);
     }
     else if (raster.DataType == typeof(short))
     {
         PaintColorSchemeToBitmapT(raster.ToRaster <short>(), rasterSymbolizer, bitmap, progressHandler);
     }
     else if (raster.DataType == typeof(byte))
     {
         PaintColorSchemeToBitmapT(raster.ToRaster <byte>(), rasterSymbolizer, bitmap, progressHandler);
     }
     else if (raster.DataType == typeof(double))
     {
         PaintColorSchemeToBitmapT(raster.ToRaster <double>(), rasterSymbolizer, bitmap, progressHandler);
     }
     else
     {
         PaintColorSchemeToBitmapT(raster, raster.NoDataValue, (row, col) => raster.Value[row, col], rasterSymbolizer, bitmap, progressHandler);
     }
 }
示例#3
0
        /// <summary>
        /// Creates a bitmap from this raster using the specified rasterSymbolizer.
        /// </summary>
        /// <param name="raster">The raster to draw to a bitmap.</param>
        /// <param name="rasterSymbolizer">The raster symbolizer to use for assigning colors.</param>
        /// <param name="rgbData">Byte values representing the ARGB image bytes.</param>
        /// <param name="stride">The stride</param>
        /// <param name="pm">The progress meter to use.</param>
        public static void DrawToBitmap(this IRaster raster, IRasterSymbolizer rasterSymbolizer, byte[] rgbData, int stride, ProgressMeter pm)
        {
            if (raster.DataType == typeof(int))
            {
                DrawToBitmapT(raster.ToRaster <int>(), rasterSymbolizer, rgbData, stride, pm);
            }
            else if (raster.DataType == typeof(float))
            {
                DrawToBitmapT(raster.ToRaster <float>(), rasterSymbolizer, rgbData, stride, pm);
            }
            else if (raster.DataType == typeof(short))
            {
                DrawToBitmapT(raster.ToRaster <short>(), rasterSymbolizer, rgbData, stride, pm);
            }
            else if (raster.DataType == typeof(byte))
            {
                DrawToBitmapT(raster.ToRaster <byte>(), rasterSymbolizer, rgbData, stride, pm);
            }
            else if (raster.DataType == typeof(double))
            {
                DrawToBitmapT(raster.ToRaster <double>(), rasterSymbolizer, rgbData, stride, pm);
            }
            else
            {
                DrawToBitmapT(raster, raster.NoDataValue, (row, col) => raster.Value[row, col], i => rgbData[i], (i, b) => rgbData[i] = b, rasterSymbolizer, stride, pm);

                if (rasterSymbolizer.IsSmoothed)
                {
                    var mySmoother = new Smoother(stride, raster.NumColumns, raster.NumRows, rgbData, pm.ProgressHandler);
                    mySmoother.Smooth();
                }
            }
        }
示例#4
0
        /// <summary>
        /// This uses the BaseValue and BinSize properties in order to categorize the values
        /// according to the source.  The cells in the bin will receive a value that is equal
        /// to the midpoint between the range.  So a range from 0 to 10 will all have the value
        /// of 5.  Values with no data continue to be marked as NoData.
        /// </summary>
        /// <param name="source">The source raster.</param>
        /// <param name="destName">The output filename.</param>
        /// <param name="progressHandler">The progress handler for messages.</param>
        /// <returns>The IRaster of binned values from the original source.</returns>
        public bool BinRaster(IRaster source, string destName, ICancelProgressHandler progressHandler)
        {
            IRaster result;

            try
            {
                result            = Raster.Create(destName, string.Empty, source.NumColumns, source.NumRows, source.NumBands, source.DataType, new string[] { });
                result.Bounds     = source.Bounds.Copy();
                result.Projection = source.Projection;
            }
            catch (Exception)
            {
                File.Copy(source.Filename, destName);
                result = Raster.Open(destName);
            }

            bool finished;

            if (source.DataType == typeof(int))
            {
                finished = BinRaster(source.ToRaster <int>(), result.ToRaster <int>(), progressHandler);
            }
            else if (source.DataType == typeof(float))
            {
                finished = BinRaster(source.ToRaster <float>(), result.ToRaster <float>(), progressHandler);
            }
            else if (source.DataType == typeof(short))
            {
                finished = BinRaster(source.ToRaster <short>(), result.ToRaster <short>(), progressHandler);
            }
            else if (source.DataType == typeof(byte))
            {
                finished = BinRaster(source.ToRaster <byte>(), result.ToRaster <byte>(), progressHandler);
            }
            else if (source.DataType == typeof(double))
            {
                finished = BinRaster(source.ToRaster <double>(), result.ToRaster <double>(), progressHandler);
            }
            else
            {
                finished = BinRasterSlow(source, result, progressHandler);
            }

            if (finished)
            {
                result.Save();
            }

            return(finished);
        }
示例#5
0
        /// <summary>
        /// Create Hillshade of values ranging from 0 to 1, or -1 for no-data regions.
        /// This should be a little faster since we are accessing the Data field directly instead of working
        /// through a value parameter.
        /// </summary>
        /// <param name="raster">The raster to create the hillshade from.</param>
        /// <param name="shadedRelief">An implementation of IShadedRelief describing how the hillshade should be created.</param>
        /// <param name="progressHandler">An implementation of IProgressHandler for progress messages</param>
        public static float[][] CreateHillShade(this IRaster raster, IShadedRelief shadedRelief, IProgressHandler progressHandler = null)
        {
            if (progressHandler == null)
            {
                progressHandler = raster.ProgressHandler;
            }
            var pm = new ProgressMeter(progressHandler, SymbologyMessageStrings.DesktopRasterExt_CreatingShadedRelief, raster.NumRows);

            Func <int, int, double> getValue;

            if (raster.DataType == typeof(int))
            {
                var r = raster.ToRaster <int>();
                getValue = (row, col) => r.Data[row][col];
            }
            else if (raster.DataType == typeof(float))
            {
                var r = raster.ToRaster <float>();
                getValue = (row, col) => r.Data[row][col];
            }
            else if (raster.DataType == typeof(short))
            {
                var r = raster.ToRaster <short>();
                getValue = (row, col) => r.Data[row][col];
            }
            else if (raster.DataType == typeof(byte))
            {
                var r = raster.ToRaster <byte>();
                getValue = (row, col) => r.Data[row][col];
            }
            else if (raster.DataType == typeof(double))
            {
                var r = raster.ToRaster <double>();
                getValue = (row, col) => r.Data[row][col];
            }
            else
            {
                getValue = (row, col) => raster.Value[row, col];
            }


            return(CreateHillShadeT(raster, getValue, shadedRelief, pm));
        }