Guest User

ArcGIS Pro SDK write in raster

a guest
Nov 10th, 2017
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. await QueuedTask.Run(() => {
  2.       string outputFolderName = "folderName";
  3.       string rasterName = "name.tiff";
  4.       string rasterFormat = "TIFF";
  5.  
  6.       Raster raster = currentRasterLayer.GetRaster();
  7.  
  8.       //create output directory and a new datastore
  9.       string outputFolder = Path.Combine(Project.Current.HomeFolderPath, ouputFolderName);
  10.       Directory.CreateDirectory(outputFolder);
  11.       FileSystemConnectionPath outputConnectionPath = new FileSystemConnectionPath(
  12.             new System.Uri(outputFolder), FileSystemDatastoreType.Raster);
  13.       FileSystemDatastore outputDataStore = new FileSystemDatastore(outputConnectionPath);
  14.  
  15.       //create a copy of the opened raster
  16.       RasterDataset resultRasterDataset = raster.SaveAs(rasterName, outputDataStore, rasterFormat);
  17.       Raster resultRaster = resultRasterDataset.CreateFullRaster();
  18.       if (!resultRaster.CanEdit()) {
  19.             MessageBox.Show("Cannot edit raster");
  20.             return;
  21.       }
  22.  
  23.       PixelBlock pixelBlock = resultRaster.CreatePixelBlock(resultRaster.GetWidth(), resultRaster.GetHeight());
  24.       pixelBlock.Clear(0);
  25.       resultRaster.Write(0, 0, pixelBlock);
  26.       resultRaster.Refresh();
  27. });
RAW Paste Data Copied