Esempio n. 1
0
        private Image _stencil; // draw features to the stencil

        #endregion

        #region Constructors

        /// <summary>
        /// Creates a new raster layer from the specified fileName
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="symbolizer"></param>
        public MapRasterLayer(string fileName, IRasterSymbolizer symbolizer)
            : base(fileName, symbolizer)
        {
            base.LegendText = Path.GetFileNameWithoutExtension(fileName);
            if (DataSet.NumRows * DataSet.NumColumns > 8000)
            {
                string pyrFile = Path.ChangeExtension(fileName, ".mwi");
                if (File.Exists(pyrFile) && File.Exists(Path.ChangeExtension(pyrFile, ".mwh")))
                {
                    BitmapGetter = new PyramidImage(pyrFile);
                }
                else
                {
                    BitmapGetter = CreatePyramidImage(pyrFile, DataManager.DefaultDataManager.ProgressHandler);
                }
            }
            else
            {
                Bitmap bmp = new Bitmap(DataSet.NumColumns, DataSet.NumRows);
                symbolizer.Raster = DataSet;

                DataSet.DrawToBitmap(symbolizer, bmp, null);
                InRamImage id = new InRamImage(bmp);
                id.Bounds = DataSet.Bounds;
                BitmapGetter = id;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new instance of a Raster layer, and will create a "FallLeaves" image based on the
        /// raster values.
        /// </summary>
        /// <param name="raster">The raster to use</param>
        public MapRasterLayer(IRaster raster)
            : base(raster)
        {
            base.LegendText = Path.GetFileNameWithoutExtension(raster.Filename);
            // string imageFile = Path.ChangeExtension(raster.Filename, ".png");
            // if (File.Exists(imageFile)) File.Delete(imageFile);
            if ((long)raster.NumRows * raster.NumColumns > MaxCellsInMemory)
            {
                // For huge images, assume that GDAL or something was needed anyway,
                // and we would rather avoid having to re-create the pyramids if there is any chance
                // that the old values will work ok.
                string pyrFile = Path.ChangeExtension(raster.Filename, ".mwi");
                if (File.Exists(pyrFile) && File.Exists(Path.ChangeExtension(pyrFile, ".mwh")))
                {
                    BitmapGetter = new PyramidImage(pyrFile);
                    base.LegendText = Path.GetFileNameWithoutExtension(raster.Filename);
                }
                else
                {
                    BitmapGetter = CreatePyramidImage(pyrFile, DataManager.DefaultDataManager.ProgressHandler);
                }
            }
            else
            {
                // Ensure smaller images match the scheme.
                Bitmap bmp = new Bitmap(raster.NumColumns, raster.NumRows);
                raster.PaintColorSchemeToBitmap(Symbolizer, bmp, raster.ProgressHandler);

                var id = new InRamImage(bmp) { Bounds = { AffineCoefficients = raster.Bounds.AffineCoefficients } };
                BitmapGetter = id;
            }
        }
Esempio n. 3
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"></param>
        /// <param name="progressHandler"></param>
        /// <returns></returns>
        public IImageData CreatePyramidImage(string pyrFile, IProgressHandler progressHandler)
        {
            PyramidImage py = new PyramidImage(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 = count * 2;
            }
            ProgressMeter pm = new ProgressMeter(progressHandler, "Creating Pyramids", count);
            PerformanceCounter pcRemaining = new PerformanceCounter("Memory", "Available Bytes");
            Process proc = Process.GetCurrentProcess();
            long mem;
            long freeRAM;

            for (int j = 0; j < numBlocks; j++)
            {
                int h = blockHeight;
                if (j == numBlocks - 1)
                {
                    h = DataSet.Bounds.NumRows - j * blockHeight;
                }

                mem = proc.PrivateMemorySize64 / 1000000;
                freeRAM = Convert.ToInt64(pcRemaining.NextValue()) / 1000000;
                Debug.WriteLine("Memory before: " + mem + ", " + freeRAM + " remaining.");
                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;
                }
                mem = proc.PrivateMemorySize64 / 1000000;
                freeRAM = Convert.ToInt64(pcRemaining.NextValue()) / 1000000;
                Debug.WriteLine("Memory after: " + mem + "Mb | " + freeRAM + " remaining Mb.");
            }
            pm.Reset();
            py.ProgressHandler = ProgressHandler;
            py.CreatePyramids();
            py.WriteHeader(pyrFile);
            return py;
        }