How to orthorectify an image using DEM


This sample code demonstrates how to orthorectify an image using DEM.

How to use

  1. Modify the path names and file names accordingly
  2. Use in VBA
[VBA]
Sub Orthorectification()
    
    'this example reads a RPC image and peform orthorectification using a DEM
    Dim pRPCRasterDS As IRasterDataset
    Dim pDEMRasterDS As IRasterDataset
    Dim pRPCRaster As IRaster2
    
    'open RPC raster data
    Set pRPCRasterDS = OpenRasterDataset("c:\data", "aa.img")
    Set pRPCRaster = pRPCRasterDS.CreateDefaultRaster
    
    'open a DEM
    Set pDEMRasterDS = OpenRasterDataset("c:\data", "dem.img")
    
    'Get geodata xform from the raster
    Dim pRPCXform As IRPCXform
    Set pRPCXform = pRPCRaster.GeodataXform
    
    'set DEM
    Dim pSensorXform As ISensorXform
    Set pSensorXform = pRPCXform
    Set pSensorXform.DEM = pDEMRasterDS.CreateDefaultRaster
    
    'SaveAs
    Dim pSaveAs As ISaveAs
    Set pSaveAs = pRPCRaster
    pSaveAs.SaveAs "c:\data\orthoimage.img", Nothing, "IMAGINE Image"
    
End Sub


Public Function OpenRasterDataset(sPath As String, sName As String) As IRasterDataset
    Dim pRWSF As IWorkspaceFactory
    Dim pWs As IRasterWorkspace
    
    Set pRWSF = New RasterWorkspaceFactory
    Set pWs = pRWSF.OpenFromFile(sPath, 0)
    Set OpenRasterDataset = pWs.OpenRasterDataset(sName)
End Function