ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Core.Data.Raster Namespace / PixelBlock Class
Members Example

In This Topic
    PixelBlock Class
    In This Topic
    Represents a container for pixel data that can be created using Raster.CreatePixelBlock
    Syntax
    public sealed class PixelBlock : ArcGIS.Core.CoreObjectsBase, System.IDisposable  
    Public NotInheritable Class PixelBlock 
       Inherits ArcGIS.Core.CoreObjectsBase
       Implements System.IDisposable 
    Remarks
    The PixelBlock object is designed to handle generic pixel arrays from any raster data source. This means it must be able to handle single and multiband data, as well as support different pixel types. To support multiple bands, or planes, of raster data, the PixelBlock provides a separate array for each band (plane) in the raster. You can get the pixel data from the pixel block, modify the pixel values, and write the pixel block with the modified pixel values to a raster band. If the pixel block is created from a Raster, the modified pixel block can be read using the Raster.Read method and written to the raster dataset using the Raster.Write method. For a small raster dataset, the size of the pixel block can be the size of the entire dataset, which can usually be held in memory at one time. When working with large raster data, the best practice is to divide the raster into small pixel blocks and read and write these block by block using the RasterCursor Object.
    Example
    Create a raster cursor to iterate through the raster data
    await QueuedTask.Run(() =>
    {
      // Create a full raster from the raster dataset.
      ArcGIS.Core.Data.Raster.Raster raster = rasterDataset.CreateFullRaster();
    
      // Calculate size of pixel blocks to process. Use 1000 or height/width of the raster, whichever is smaller.
      var height = raster.GetHeight();
      var width = raster.GetWidth();
      int pixelBlockHeight = height > 1000 ? 1000 : height;
      int pixelBlockWidth = width > 1000 ? 1000 : width;
    
      // Create the raster cursor using the height and width calculated.
      RasterCursor rasterCursor = raster.CreateCursor(pixelBlockWidth, pixelBlockHeight);
    
      // Use a do-while loop to iterate through the pixel blocks of the raster using the raster cursor.
      do
      {
        // Get the current pixel block from the cursor.
        using (PixelBlock currentPixelBlock = rasterCursor.Current)
        {
          // Do something with the pixel block...
        }
    
        // Once you are done, move to the next pixel block.
      }
      while (rasterCursor.MoveNext());
    });
    Read and Write pixels from and to a raster dataset using pixel blocks
    await QueuedTask.Run(() =>
    {
      // Create a full raster from the raster dataset.
      ArcGIS.Core.Data.Raster.Raster raster = rasterDataset.CreateFullRaster();
    
      // Calculate size of pixel block to create. Use 128 or height/width of the raster, whichever is smaller.
      var height = raster.GetHeight();
      var width = raster.GetWidth();
      int pixelBlockHeight = height > 128 ? 128 : height;
      int pixelBlockWidth = width > 128 ? 128 : width;
    
      // Create a new (blank) pixel block.
      PixelBlock currentPixelBlock = raster.CreatePixelBlock(pixelBlockWidth, pixelBlockHeight);
    
      // Read pixel values from the raster dataset into the pixel block starting from the given top left corner.
      raster.Read(0, 0, currentPixelBlock);
    
      // Do something with the pixel block...
    
      // Write the pixel block to the raster dataset starting from the given top left corner.
      raster.Write(0, 0, currentPixelBlock);
    });
    Inheritance Hierarchy

    System.Object
       ArcGIS.Core.CoreObjectsBase
          ArcGIS.Core.Data.Raster.PixelBlock

    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also