How to perform a geodata transformation on a raster (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with image and raster data > Processing raster data > Geodata transformations > How to perform a geodata transformation on a raster (ArcObjects .NET 10.6 SDK)

How to perform a geodata transformation on a raster


Summary
A geodata transformation is a mathematical model that performs geometric transformation on a raster. The geodata transformation consists of concrete classes, such as PolynomialXform, RPCXform, AdjustXform, and so on.

Performing a geodata transformation on a raster

To perform a geodata transformation on a raster, follow these steps:
  1. Set the transformation on the raster using the IRaster2 interface.
  2. Set the cell size.
  3. Set the output extent.
See the following code example:
[C#]
public static void SetGeodataXformAndSaveAs(IRaster2 raster, IGeodataXform xform)
{
    //Get the original extent and cell size of the raster.
    IRasterProps rasterProp=raster as IRasterProps;
    IEnvelope extent=rasterProp.Extent;
    IPnt cellSize=rasterProp.MeanCellSize();
    double xCell=cellSize.X;
    double yCell=cellSize.Y;

    //Set the xform on the raster.
    raster.GeodataXform=xform;

    //Transform the cell size first, then the extent; the sequence matters.
    xform.TransformCellsize(esriTransformDirection.esriTransformForward, ref xCell,
        ref yCell, extent);
    xform.TransformExtent(esriTransformDirection.esriTransformForward, extent);

    //Put the transformed extent and cell size on the raster and save as.
    rasterProp.Extent=extent;
    rasterProp.Width=Convert.ToInt32(extent.Width / xCell);
    rasterProp.Height=Convert.ToInt32(extent.Height / yCell);

    //Save the raster.
    ISaveAs saveAs=raster as ISaveAs;
    saveAs.SaveAs(@"c:\temp\image1.img", null, "IMAGINE Image");
}
[VB.NET]
Public Sub SetGeodataXformAndSaveAs(ByVal raster As IRaster2, ByVal xform As IGeodataXform)
    
    'Get the original extent and cell size of the raster.
    Dim rasterProp As IRasterProps=TryCast(raster, IRasterProps)
    Dim extent As IEnvelope=rasterProp.Extent
    Dim cellSize As IPnt=rasterProp.MeanCellSize()
    Dim xCell As Double=cellSize.X
    Dim yCell As Double=cellSize.Y
    
    'Set the xform on the raster.
    raster.GeodataXform=xform
    
    'Transform the cell size first, then the extent; the sequence matters.
    xform.TransformCellsize(esriTransformDirection.esriTransformForward, xCell, yCell, extent)
    xform.TransformExtent(esriTransformDirection.esriTransformForward, extent)
    
    'Put the transformed extent and cell size on the raster and save as.
    rasterProp.Extent=extent
    rasterProp.Width=Convert.ToInt32(extent.Width / xCell)
    rasterProp.Height=Convert.ToInt32(extent.Height / yCell)
    
    'Save the raster.
    Dim saveAs As ISaveAs=TryCast(raster, ISaveAs)
    saveAs.SaveAs("c:\temp\image1.img", Nothing, "IMAGINE Image")
    
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine