This sample shows how to read and write pixel blocks of large raster data using raster cursor.
How to use
- Reference libraries:ESRI.ArcGIS.Geodatabase, ESRI.ArcGIS.DataSourcesRaster, ESRI.ArcGIS.Geometry.
- Call this subroutine.
Sub UsingRasterCursorOnLargeRaster(pRasterDs As IRasterDataset2)
'Create raster and raster cursor
Dim pRaster As IRaster2
Set pRaster = pRasterDs.CreateFullRaster
Set pRasterCursor = pRaster2.CreateCursorEx(Nothing)
'use IRasterEdit interface
Dim pRasterEdit As IRasterEdit
Set pRasterEdit = pRaster
'loop through each pixel block in the raster.
Dim pPB As IPixelBlock3
Dim PixelBlockWidth As Long, PixelBlockHeight As Long
Dim pTLC As IPnt
Dim pBandCol As IRasterBandCollection
Set pBandCol = pRasterDs
Do
Set pPB = pRasterCursor.PixelBlock
For k = 0 To pBandCol.Count - 1
v = pPB.PixelData(k)
For i = 0 To PixelBlockWidth - 1
For j = 0 To PixelBlockHeight - 1
v(i, j) = v(i, j) / 2
Next j
Next i
pPB.PixelData(k) = v
Next k
Set v = Nothing
Set pTLC = pRasterCursor.TopLeft
pRasterEdit.Write pTLC, pPB
Loop While pRasterCursor.Next = True
End Sub