/// <summary> /// Creates a new instance of GdalFileOverviewImage /// </summary> public GdalFileOverviewImage(string filename) { _source = new GdalImageSource(filename); }
/// <summary> /// /// </summary> /// <param name="filename"></param> /// <returns></returns> private IImageData OpenFile(string filename) { GdalImage result = new GdalImage(filename); if(result.Width > 8000 || result.Height > 8000) { // Firstly, if there are pyramids inside of the GDAL file itself, we can just work with this directly, // without creating our own pyramid image. // For now, we can't get fast, low-res versions without some kind of pyramiding happening. // since that can take a while for huge images, I'd rather do this once, and create a kind of // standardized file-based pyramid system. Maybe in future pyramid tiffs could be used instead? string pyrFile = Path.ChangeExtension(filename, ".mwi"); if(File.Exists(pyrFile)) { if(File.Exists(Path.ChangeExtension(pyrFile, ".mwh"))) { return new PyramidImage(filename); } File.Delete(pyrFile); } GdalImageSource gs = new GdalImageSource(filename); PyramidImage py = new PyramidImage(pyrFile, gs.Bounds); int width = gs.Bounds.NumColumns; int blockHeight = 64000000 / width; if (blockHeight > gs.Bounds.NumRows) blockHeight = gs.Bounds.NumRows; int numBlocks = (int)Math.Ceiling(gs.Bounds.NumRows/(double)blockHeight); ProgressMeter pm = new ProgressMeter(ProgressHandler, "Copying Data To Pyramids", numBlocks* 2); ProgressHandler.Progress("pyramid", 0, "Copying Data To Pyramids: 0% Complete"); Application.DoEvents(); for(int j = 0; j < numBlocks; j++) { int h = blockHeight; if(j==numBlocks-1) { h = gs.Bounds.NumRows - j*blockHeight; } Stopwatch sw = new Stopwatch(); sw.Start(); byte[] vals = gs.ReadWindow(j*blockHeight, 0, h, width, 0); Debug.WriteLine("Reading Value time: " + sw.ElapsedMilliseconds); pm.CurrentValue = j * 2 + 1; sw.Reset(); sw.Start(); py.WriteWindow(vals, j * blockHeight, 0, h, width, 0); sw.Stop(); Debug.WriteLine("Writing Pyramid time: " + sw.ElapsedMilliseconds); pm.CurrentValue = (j+1) * 2; } gs.Dispose(); pm.Reset(); py.CreatePyramids(ProgressHandler); py.WriteHeader(pyrFile); return py; } result.Open(filename); return result; }