Beispiel #1
0
        /// <summary>
        /// Render the full raster block by block, and then save the values to the pyramid raster.
        /// This will probably be nasty and time consuming, but what can you do.
        /// </summary>
        /// <param name="pyrFile">File name of the file the pyramid image should be saved to.</param>
        /// <param name="progressHandler">The progress handler.</param>
        /// <returns>The created pyramid image.</returns>
        public IImageData CreatePyramidImage(string pyrFile, IProgressHandler progressHandler)
        {
            PyramidImage py          = new(pyrFile, DataSet.Bounds);
            int          width       = DataSet.Bounds.NumColumns;
            int          blockHeight = 32000000 / width;

            if (blockHeight > DataSet.Bounds.NumRows)
            {
                blockHeight = DataSet.Bounds.NumRows;
            }
            int numBlocks = (int)Math.Ceiling(DataSet.Bounds.NumRows / (double)blockHeight);
            int count     = DataSet.NumRows;

            if (_symbolizer.ShadedRelief.IsUsed)
            {
                count *= 2;
            }

            ProgressMeter      pm          = new(progressHandler, "Creating Pyramids", count);
            PerformanceCounter pcRemaining = new("Memory", "Available Bytes");
            Process            proc        = Process.GetCurrentProcess();

            for (int j = 0; j < numBlocks; j++)
            {
                int h = blockHeight;
                if (j == numBlocks - 1)
                {
                    h = DataSet.Bounds.NumRows - (j * blockHeight);
                }
#if DEBUG
                var mem     = proc.PrivateMemorySize64 / 1000000;
                var freeRam = Convert.ToInt64(pcRemaining.NextValue()) / 1000000;
                Debug.WriteLine("Memory before: " + mem + ", " + freeRam + " remaining.");
#endif
                pm.BaseMessage = "Reading from Raster";
                pm.SendProgress();
                using (IRaster r = DataSet.ReadBlock(0, j * blockHeight, width, h))
                {
                    byte[] vals = new byte[h * 4 * width];
                    r.DrawToBitmap(Symbolizer, vals, width * 4, pm);
                    pm.BaseMessage = "Writing to Pyramids";
                    pm.SendProgress();
                    py.WriteWindow(vals, j * blockHeight, 0, h, width, 0);
                    Symbolizer.HillShade = null;
                }
#if DEBUG
                mem     = proc.PrivateMemorySize64 / 1000000;
                freeRam = Convert.ToInt64(pcRemaining.NextValue()) / 1000000;
                Debug.WriteLine("Memory after: " + mem + "Mb | " + freeRam + " remaining Mb.");
#endif
            }

            pm.Reset();
            py.ProgressHandler = ProgressHandler;
            py.CreatePyramids();
            py.WriteHeader(pyrFile);
            return(py);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a bmp from the in-memory portion of the raster. This will be stored as a
        /// fileName with the same name as the current raster, but ends in bmp.
        /// </summary>
        /// <returns>The created bmp.</returns>
        public Bitmap CreateBitmap()
        {
            string fileName = Path.ChangeExtension(_raster.Filename, ".bmp");
            Bitmap bmp      = new Bitmap(_raster.NumRows, _raster.NumColumns, PixelFormat.Format32bppArgb);

            bmp.Save(fileName); // this is needed so that lockbits doesn't cause exceptions
            _raster.DrawToBitmap(this, bmp);
            bmp.Save(fileName);
            return(bmp);
        }