This sample code demonstrates how to flip a raster along the horizontal axis by using a RasterTransformationOp object.
How to use
- Start ArcMap.
- Add a raster into ArcMap.
- Make sure that the Spatial Analyst is turned on.
- Paste the following code into VBA.
- Set a reference to the ESRI GeoAnalyst Object Library.
- Run the sub from the Macros dialog.
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