How to flip a raster along the horizontal axis using RasterTransformationOp


This sample code demonstrates how to flip a raster along the horizontal axis by using a RasterTransformationOp object.

How to use

  1. Start ArcMap.
  2. Add a raster into ArcMap.
  3. Make sure that the Spatial Analyst is turned on.
  4. Paste the following code into VBA.
  5. Set a reference to the ESRI GeoAnalyst Object Library.
  6. Run the sub from the Macros dialog.
[VBA]
Sub RasterTransformationOp_Flip()
    'Get the focused Map from MapDocument
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pMxDoc.FocusMap
    
    'Get the input raster from the first layer in ArcMap
    Dim pLayer As ILayer
    Dim pRasLayer As IRasterLayer
    Dim pInRaster As IRaster
    
    Set pLayer = pMap.Layer(0)
    If Not TypeOf pLayer Is IRasterLayer Then Exit Sub
    
    Set pRasLayer = pLayer
    Set pInRaster = pRasLayer.Raster
    
    'Create a RasterTransformationOp operator
    Dim pRasTransformationOp As ITransformationOp
    Set pRasTransformationOp = New RasterTransformationOp
    
    'Perform Flip operation
    Dim pOutGeoDS As IGeoDataset
    Set pOutGeoDS = pRasTransformationOp.Flip(pInRaster)
    
    'Create a raster layer from output and add it into ArcMap
    Dim pOutRasLayer As IRasterLayer
    Set pOutRasLayer = New RasterLayer
    pOutRasLayer.CreateFromDataset pOutGeoDS
    pMap.AddLayer pOutRasLayer
End Sub