/// <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; } }
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; } }
/// <summary> /// This does not have to be used to work, but provides a default implementation for writing bitmap, /// and will be used by the MapRasterLayer class during file creation. /// </summary> /// <param name="progressHandler"></param> protected void DefaultWriteBitmap(IProgressHandler progressHandler) { if (DataSet.NumRowsInFile * DataSet.NumColumnsInFile > 8000 * 8000) { // 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(DataSet.Filename, ".mwi"); BitmapGetter = CreatePyramidImage(pyrFile, progressHandler); OnItemChanged(this); return; } Bitmap bmp = new Bitmap(DataSet.NumColumns, DataSet.NumRows, PixelFormat.Format32bppArgb); if (_symbolizer.DrapeVectorLayers == false) { // Generate the colorscheme, modified by hillshading if that hillshading is used all in one pass DataSet.DrawToBitmap(Symbolizer, bmp, progressHandler); } else { // work backwards. when we get to this layer do the colorscheme. // First, use this raster and its colorscheme to drop the background DataSet.PaintColorSchemeToBitmap(Symbolizer, bmp, progressHandler); // Set up a graphics object with a transformation pre-set so drawing a geographic coordinate // will draw to the correct location on the bitmap Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.AntiAlias; Extent extents = DataSet.Extent; Rectangle target = new Rectangle(0, 0, bmp.Width, bmp.Height); ImageProjection ip = new ImageProjection(extents, target); // Cycle through each layer, and as long as it is not this layer, draw the bmp foreach (ILegendItem layer in GetParentItem().LegendItems) { // Temporarily I am only interested in doing this for vector datasets IFeatureLayer fl = layer as IFeatureLayer; if (fl == null) { continue; } fl.DrawSnapShot(g, ip); } if (Symbolizer.ShadedRelief.IsUsed) { // After we have drawn the underlying texture, apply a hillshade if it is requested Symbolizer.PaintShadingToBitmap(bmp, progressHandler); } } InRamImage image = new InRamImage(bmp); image.Bounds = DataSet.Bounds.Copy(); BitmapGetter = image; Symbolizer.Validate(); OnInvalidate(this, new EventArgs()); OnItemChanged(); }
/// <summary> /// Initializes a new instance of the <see cref="MapRasterLayer"/> class from the specified fileName. /// </summary> /// <param name="fileName">Filename of the corresponding raster file.</param> /// <param name="symbolizer">Symbolizer used for drawing the raster data.</param> public MapRasterLayer(string fileName, IRasterSymbolizer symbolizer) : base(fileName, symbolizer) { LegendText = Path.GetFileNameWithoutExtension(fileName); // CGX if (File.Exists(fileName)) { if ((long)DataSet.NumRows * DataSet.NumColumns > MaxCellsInMemory) { string pyrFile = Path.ChangeExtension(fileName, ".mwi"); BitmapGetter = File.Exists(pyrFile) && File.Exists(Path.ChangeExtension(pyrFile, ".mwh")) ? new PyramidImage(pyrFile) : CreatePyramidImage(pyrFile, DataManager.DefaultDataManager.ProgressHandler); } else { Bitmap bmp = new Bitmap(DataSet.NumColumns, DataSet.NumRows); symbolizer.Raster = DataSet; DataSet.DrawToBitmap(symbolizer, bmp); var id = new InRamImage(bmp) { Bounds = DataSet.Bounds }; BitmapGetter = id; } } }