This document is archived and information here might be outdated.  Recommended version.


How to project a raster with a datum transformation (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 project a raster with a datum transformation (ArcObjects .NET 10.6 SDK)

How to project a raster with a datum transformation


Summary
Projecting a raster from one projection to another can be done using the ProjectRaster geoprocessing tool. For customization, you can use the geoprocessor and call the ProjectRaster_management command. This topic shows how to project rasters and set datum transformation using the ArcObjects application programming interface (API).

Projecting a raster with a datum transformation

When projecting raster data, you can specify a transformation if the spatial references of the input and output are based on different datum. See the following code example:
[C#]
public static void ProjectRasterWithDatumTransformation(IRasterDataset2
    rasterDataset, ISpatialReference outSR, esriSRGeoTransformation2Type geoTrans)
{
    //This example shows how to specify a datum transformation when projecting raster data.
    //rasterDataset—Represents input of a raster dataset that has a known spatial reference.
    //outSR—Represents the spatial reference of the output raster dataset.
    //geoTrans—Represents the geotransformation between the input and output spatial reference.
    //Set output spatial reference.

    IRaster raster=rasterDataset.CreateFullRaster();
    IRasterProps rasterProps=(IRasterProps)raster;
    rasterProps.SpatialReference=outSR;

    //Specify the geotransformation.
    ISpatialReferenceFactory2 srFactory=new SpatialReferenceEnvironmentClass();
    IGeoTransformation geoTransformation=(IGeoTransformation)
        srFactory.CreateGeoTransformation((int)geoTrans);

    //Add to the geotransformation operation set.
    IGeoTransformationOperationSet operationSet=new
        GeoTransformationOperationSetClass();
    operationSet.Set(esriTransformDirection.esriTransformForward, geoTransformation);
    operationSet.Set(esriTransformDirection.esriTransformReverse, geoTransformation);

    //Set the geotransformation on the raster.
    IRaster2 raster2=(IRaster2)raster;
    raster2.GeoTransformations=operationSet;

    //Save the result.
    ISaveAs saveas=(ISaveAs)raster;
    saveas.SaveAs(@"c:\temp\outputRaster.img", null, "IMAGINE Image");
}
[VB.NET]
Public Sub ProjectRasterWithDatumTransformation(ByVal rasterDataset As IRasterDataset2, ByVal outSR As ISpatialReference, ByVal geoTrans As esriSRGeoTransformation2Type)
    
    'This example shows how to specify a datum transformation when projecting raster data.
    'rasterDataset—Represents input of a raster dataset that has a known spatial reference.
    'outSR—Represents the spatial reference of the output raster dataset.
    'geoTrans—Represents the geotransformation between the input and output spatial reference.
    
    'Set output spatial reference.
    Dim raster As IRaster=rasterDataset.CreateFullRaster()
    Dim rasterProps As IRasterProps=CType(raster, IRasterProps)
    rasterProps.SpatialReference=outSR
    
    'Specify the geotransformation.
    Dim srFactory As ISpatialReferenceFactory2=New SpatialReferenceEnvironmentClass()
    Dim geoTransformation As IGeoTransformation=CType(srFactory.CreateGeoTransformation(CType(geoTrans, Integer)), IGeoTransformation)
    
    'Add to the geotransformation operation set.
    Dim operationSet As IGeoTransformationOperationSet=New GeoTransformationOperationSetClass()
    operationSet.Set(esriTransformDirection.esriTransformForward, geoTransformation)
    operationSet.Set(esriTransformDirection.esriTransformReverse, geoTransformation)
    
    'Set the geotransformation on the raster.
    Dim raster2 As IRaster2=CType(raster, IRaster2)
    raster2.GeoTransformations=operationSet
    
    'Save the result.
    Dim saveas As ISaveAs=CType(raster, ISaveAs)
    saveas.SaveAs("c:\temp\outputRaster.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 Advanced ArcGIS Desktop Advanced
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Basic ArcGIS Desktop Basic
Engine Developer Kit Engine