private async Task WriteTiles(string outDir) { var srcMRR = viewModel.Path; this.IsEnabled = false; var tileGenerator = viewModel.SelectedGenerator.Generator; await Task.Run(() => { Stopwatch s = new Stopwatch(); s.Start(); int maxZoom, totalTiles; IRasterDataset dataSet = RasterDatasetFactory.Open(srcMRR); tileGenerator.GetJobSize(dataSet, viewModel.MaxZoom > 0 ? viewModel.MaxZoom : 100, out maxZoom, out totalTiles); viewModel.MaxProgress = totalTiles; viewModel.ProgressVisible = Visibility.Visible; viewModel.ResetProgress(); System.Progress <int> progress = new Progress <int>((i) => viewModel.AddToProgress(1)); var output = new CompressedFileOutput(outDir); tileGenerator.CreateAllTiles(dataSet, maxZoom, output, progress); CreateMissingTopLevelTile(outDir, output); s.Stop(); Console.WriteLine(s.Elapsed); }); this.IsEnabled = true; viewModel.ProgressVisible = Visibility.Collapsed; }
public static double GetCellAreaAboveThreshold(string inputFile, int fieldIndex, int bandIndex, double threshold) { // number of cells over threshold double cellCount = 0; // open the file and get the dataset var dataset = RasterDatasetFactory.Open(inputFile); // get the raster info var info = dataset.Info; // get sequential tile iterator for read for current field var iterator = dataset.GetSequentialTileIterator(fieldIndex); // begin the iterator iterator.Begin(); // iterate over each tile in raster foreach (var tile in iterator) { // get band to read uint ubandIndex = (uint)bandIndex; var band = tile.GetBandData <double>(ubandIndex); // iterate over each cell in tile and read for (uint y = 0; y < tile.YSize; y++) { for (uint x = 0; x < tile.XSize; x++) { double value; bool valid; // get the cell value band.GetCellValue(x + y * tile.XSize, out value, out valid); // check its valid and above threshold if (valid && (value > threshold)) { cellCount++; } } } } // end the iterator iterator.End(); // close the dataset dataset.Close(); // calculate area return(cellCount * (info.FieldInfo[fieldIndex].CellSizeX.Decimal * info.FieldInfo[fieldIndex].CellSizeY.Decimal)); }