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


Create DistanceOp Cost Path Raster Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Create DistanceOp Cost Path Raster Snippet

Create a raster that is the least-cost path(s) from three input GeoDataset's

[C#]
/// <summary>
/// Create a raster that is the least-cost path(s) from three input GeoDataset's.
/// </summary>
/// <param name="geoDataset_1">An IGeoDataset interface that identifies those cells or locations to which the least cost path is determined to the least costly source.</param>
/// <param name="geoDataset_2">An IGeoDataset interface that represents the minimum accumulative cost distance over a cost surface from each cell to a set of source cells.</param>
/// <param name="geoDataset_3">An IGeoDataset interface that represents cost back link Raster used to determine the path to return to a source via the least-cost path.</param>
/// <returns>An IGeoDataset interface that is the the least-cost path(s).</returns>
/// <remarks>
/// Note: 
/// The input geoDataset_1 must be of Type IRaster, IRasterDataset, IRasterBand, IRasterDescriptor, or FeatureClass. The Raster 
/// consists of cells which are to be considered in the IDistance::CostPath method calculations having valid values ('0' is a 
/// valid value), and the remaining cells must be assigned to NoData
/// 
/// The input geoDataset_2 must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor. The distance Raster is usually 
/// created with the IDistanceOp::CostDistance method (or by the IDistanceOp::CostDistanceFull method).
/// 
/// The input geoDataset_3 must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor. For each cell in the back 
/// link raster, a value identifies the neighbor that is the next cell on the least accumulative cost path from the cell to a 
/// single or set of source cells.
/// 
/// The IDistanceOp.CostPath Method has one option (pathType) that 
/// will greatly vary the output raster. This value will need to be adjusted for your application to achieve 
/// the desired results.
/// 
/// For information about the IDistanceOp.CostPath Method see:
/// http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/IDistanceOp_CostPath.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 CreateDistanceOpCostPathRaster(ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_1, ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_2, ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_3)
{

    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) & (geoDataset_3 is ESRI.ArcGIS.Geodatabase.IRaster | geoDataset_3 is ESRI.ArcGIS.Geodatabase.IRasterDataset | geoDataset_3 is ESRI.ArcGIS.DataSourcesRaster.IRasterBand | geoDataset_3 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.CostPath method options to suit your applications need.
        ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_output=distanceOp.CostPath(geoDataset_1, geoDataset_2, geoDataset_3, ESRI.ArcGIS.SpatialAnalyst.esriGeoAnalysisPathEnum.esriGeoAnalysisPathForEachZone);

        return geoDataset_output;
    }
    else
    {

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

    }

}
[Visual Basic .NET]
''' <summary>
''' Create a raster that is the least-cost path(s) from three input GeoDataset's.
''' </summary>
''' <param name="geoDataset_1">An IGeoDataset interface that identifies those cells or locations to which the least cost path is determined to the least costly source.</param>
''' <param name="geoDataset_2">An IGeoDataset interface that represents the minimum accumulative cost distance over a cost surface from each cell to a set of source cells.</param>
''' <param name="geoDataset_3">An IGeoDataset interface that represents cost back link Raster used to determine the path to return to a source via the least-cost path.</param>
''' <returns>An IGeoDataset interface that is the the least-cost path(s).</returns>
''' <remarks>
''' Note: 
''' The input geoDataset_1 must be of Type IRaster, IRasterDataset, IRasterBand, IRasterDescriptor, or FeatureClass. The Raster 
''' consists of cells which are to be considered in the IDistance::CostPath method calculations having valid values ('0' is a 
''' valid value), and the remaining cells must be assigned to NoData
''' 
''' The input geoDataset_2 must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor. The distance Raster is usually 
''' created with the IDistanceOp::CostDistance method (or by the IDistanceOp::CostDistanceFull method).
''' 
''' The input geoDataset_3 must be of Type IRaster, IRasterDataset, IRasterBand, or IRasterDescriptor. For each cell in the back 
''' link raster, a value identifies the neighbor that is the next cell on the least accumulative cost path from the cell to a 
''' single or set of source cells.
''' 
''' The IDistanceOp.CostPath Method has one option (pathType) that 
''' will greatly vary the output raster. This value will need to be adjusted for your application to achieve 
''' the desired results.
''' 
''' For information about the IDistanceOp.CostPath Method see:
''' http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/IDistanceOp_CostPath.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 CreateDistanceOpCostPathRaster(ByVal geoDataset_1 As ESRI.ArcGIS.Geodatabase.IGeoDataset, ByVal geoDataset_2 As ESRI.ArcGIS.Geodatabase.IGeoDataset, ByVal geoDataset_3 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) _
  And (TypeOf geoDataset_3 Is ESRI.ArcGIS.Geodatabase.IRaster _
  Or TypeOf geoDataset_3 Is ESRI.ArcGIS.Geodatabase.IRasterDataset _
  Or TypeOf geoDataset_3 Is ESRI.ArcGIS.DataSourcesRaster.IRasterBand _
  Or TypeOf geoDataset_3 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.CostPath method options to suit your applications need.
    Dim geoDataset_output As ESRI.ArcGIS.Geodatabase.IGeoDataset=distanceOp.CostPath(geoDataset_1, geoDataset_2, geoDataset_3, ESRI.ArcGIS.SpatialAnalyst.esriGeoAnalysisPathEnum.esriGeoAnalysisPathForEachZone)

    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