ArcObjects Library Reference

Create DistanceOp CostDistanceFull Backlink Raster Snippet

Create a raster that calculates the backlink for a cost surface from two input GeoDataset's.

[C#]
/// <summary>
/// Create a raster that calculates the backlink for a cost surface from two input GeoDataset's.
/// </summary>
/// <param name="geoDataset_1">An IGeoDataset interface that identifies those cells or locations to which the backlink for every cell is calculated.</param>
/// <param name="geoDataset_2">An IGeoDataset interface that definines the impedance or cost to move planimetrically through each cell.</param>
/// <returns>An IGeoDataset interface that is the backlink distance.</returns>
/// <remarks>
/// Note: 
/// The input geoDataset_1 must be of Type IRaster, IRasterDataset, IRasterBand, IRasterDescriptor, or FeatureClass. For Rasters, the 
/// input value types can be either integer, string or floating-point type if in_raster_value is used.
/// 
/// The input geoDataset_2 must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor. The values on the geoDataset_2 
/// can be integer or floating point, but they cannot be negative (you cannot have a negative cost).
/// 
/// The IDistanceOp.CostDistanceFull Method has several options (distance, backlink, allocation, maxDistance and valueRaster) that 
/// will greatly vary the output raster. These values will need to be adjusted for your application to achieve 
/// the desired results.
/// 
/// For information about the IDistanceOp.CostDistanceFull Method see:
/// http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/IDistanceOp_CostDistanceFull.htm
/// 
/// For more information on working with the ArcGIS Spatial Anaylst objects see:
/// http://edndoc.esri.com/arcobjects/9.2/CPP_VB6_VBA_VCPP_Doc/COM/VB6/working/work_rasters/sptl_analyst_objs.htm
/// </remarks>
public ESRI.ArcGIS.Geodatabase.IGeoDataset CreateDistanceOpCostDistanceFullBacklinkRaster(ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_1, ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_2)
{

    if ((geoDataset_1 is ESRI.ArcGIS.Geodatabase.IRaster | geoDataset_1 is ESRI.ArcGIS.Geodatabase.IRasterDataset | geoDataset_1 is ESRI.ArcGIS.DataSourcesRaster.IRasterBand | geoDataset_1 is ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor | geoDataset_1 is ESRI.ArcGIS.Geodatabase.IFeatureClass) & (geoDataset_2 is ESRI.ArcGIS.Geodatabase.IRaster | geoDataset_2 is ESRI.ArcGIS.Geodatabase.IRasterDataset | geoDataset_2 is ESRI.ArcGIS.DataSourcesRaster.IRasterBand | geoDataset_2 is ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor))
    {

        // Create the RasterDistanceOp object			
        ESRI.ArcGIS.SpatialAnalyst.IDistanceOp distanceOp = new ESRI.ArcGIS.SpatialAnalyst.RasterDistanceOpClass();

        // Declare the output raster object
        //Note: Adjust the IDistanceOp.CostDistanceFull method options to suit your applications need.
        object object_missing1 = System.Type.Missing;
        object object_missing2 = System.Type.Missing;
        ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_result = distanceOp.CostDistanceFull(geoDataset_1, geoDataset_2, false, true, false, ref object_missing1, ref object_missing2);

        // Access the backlink raster from the output generated
        ESRI.ArcGIS.DataSourcesRaster.IRasterBandCollection rasterBandCollection = (ESRI.ArcGIS.DataSourcesRaster.IRasterBandCollection)geoDataset_result; // Explicit Cast
        ESRI.ArcGIS.DataSourcesRaster.IRasterBand rasterBand = rasterBandCollection.Item(1);
        ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_output = (ESRI.ArcGIS.Geodatabase.IGeoDataset)rasterBand; // Explicit Cast

        return geoDataset_output;

    }
    else
    {

        //Invalid type of GeoDataset for this process
        return null;

    }

}
[Visual Basic .NET]
''' <summary>
''' Create a raster that calculates the backlink for a cost surface from two input GeoDataset's.
''' </summary>
''' <param name="geoDataset_1">An IGeoDataset interface that identifies those cells or locations to which the backlink for every cell is calculated.</param>
''' <param name="geoDataset_2">An IGeoDataset interface that definines the impedance or cost to move planimetrically through each cell.</param>
''' <returns>An IGeoDataset interface that is the backlink distance.</returns>
''' <remarks>
''' Note: 
''' The input geoDataset_1 must be of Type IRaster, IRasterDataset, IRasterBand, IRasterDescriptor, or FeatureClass. For Rasters, the 
''' input value types can be either integer, string or floating-point type if in_raster_value is used.
''' 
''' The input geoDataset_2 must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor. The values on the geoDataset_2 
''' can be integer or floating point, but they cannot be negative (you cannot have a negative cost).
''' 
''' The IDistanceOp.CostDistanceFull Method has several options (distance, backlink, allocation, maxDistance and valueRaster) that 
''' will greatly vary the output raster. These values will need to be adjusted for your application to achieve 
''' the desired results.
''' 
''' For information about the IDistanceOp.CostDistanceFull Method see:
''' http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/IDistanceOp_CostDistanceFull.htm
''' 
''' For more information on working with the ArcGIS Spatial Anaylst objects see:
''' http://edndoc.esri.com/arcobjects/9.2/CPP_VB6_VBA_VCPP_Doc/COM/VB6/working/work_rasters/sptl_analyst_objs.htm
''' </remarks>
Public Function CreateDistanceOpCostDistanceFullBacklinkRaster(ByVal geoDataset_1 As ESRI.ArcGIS.Geodatabase.IGeoDataset, ByVal geoDataset_2 As ESRI.ArcGIS.Geodatabase.IGeoDataset) As ESRI.ArcGIS.Geodatabase.IGeoDataset

  If (TypeOf geoDataset_1 Is ESRI.ArcGIS.Geodatabase.IRaster _
  Or TypeOf geoDataset_1 Is ESRI.ArcGIS.Geodatabase.IRasterDataset _
  Or TypeOf geoDataset_1 Is ESRI.ArcGIS.DataSourcesRaster.IRasterBand _
  Or TypeOf geoDataset_1 Is ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor _
  Or TypeOf geoDataset_1 Is ESRI.ArcGIS.Geodatabase.IFeatureClass) _
  And (TypeOf geoDataset_2 Is ESRI.ArcGIS.Geodatabase.IRaster _
  Or TypeOf geoDataset_2 Is ESRI.ArcGIS.Geodatabase.IRasterDataset _
  Or TypeOf geoDataset_2 Is ESRI.ArcGIS.DataSourcesRaster.IRasterBand _
  Or TypeOf geoDataset_2 Is ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor) Then

    ' Create the RasterDistanceOp object			
    Dim distanceOp As ESRI.ArcGIS.SpatialAnalyst.IDistanceOp = New ESRI.ArcGIS.SpatialAnalyst.RasterDistanceOpClass

    ' Declare the output raster object
    'Note: Adjust the IDistanceOp.CostDistanceFull method options to suit your applications need.
    Dim object_missing1 As System.Object = System.Type.Missing
    Dim object_missing2 As System.Object = System.Type.Missing
    Dim geoDataset_result As ESRI.ArcGIS.Geodatabase.IGeoDataset = distanceOp.CostDistanceFull(geoDataset_1, geoDataset_2, False, True, False, object_missing1, object_missing2)

    ' Access the backlink raster from the output generated
    Dim rasterBandCollection As ESRI.ArcGIS.DataSourcesRaster.IRasterBandCollection = CType(geoDataset_result, ESRI.ArcGIS.DataSourcesRaster.IRasterBandCollection) ' Explicit Cast
    Dim rasterBand As ESRI.ArcGIS.DataSourcesRaster.IRasterBand = rasterBandCollection.Item(1)
    Dim geoDataset_output As ESRI.ArcGIS.Geodatabase.IGeoDataset = CType(rasterBand, ESRI.ArcGIS.Geodatabase.IGeoDataset) ' Explicit Cast

    Return geoDataset_output

  Else

    'Invalid type of GeoDataset for this process
    Return Nothing

  End If

End Function


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.DataSourcesRaster
  • ESRI.ArcGIS.GeoAnalyst
  • ESRI.ArcGIS.Geodatabase
  • ESRI.ArcGIS.SpatialAnalyst
  • ESRI.ArcGIS.System
  • System