ArcObjects Library Reference

Create DistanceOp EucAllocation Raster Snippet

Create a raster that has for each cell the zone of the closest source cell (in Euclidean distance).

[C#]
/// <summary>
/// Create a raster that has for each cell the zone of the closest source cell (in Euclidean distance).
/// </summary>
/// <param name="geoDataset">An IGeoDataset interface that has those cells or locations whose values are assigned to the output cell locations that they are closest to.</param>
/// <returns>An IGeoDataset interface that is the zone of the closest source cells.</returns>
/// <remarks>
/// Note: the input geoDataset's must be of Type IRaster, IRasterDataset, IRasterBand, IRasterDescriptor or IFeatureClass.
/// 
/// The IDistanceOp.EucAllocation Method has two options (maxDistance and valueRaster) that 
/// will greatly vary the output raster. Thess values will need to be adjusted for your application to achieve 
/// the desired results.
/// 
/// For information about the IDistanceOp.EucAllocation Method see:
/// http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/IDistanceOp_EucAllocation.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 CreateDistanceOpEucAllocationRaster(ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset)
{

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

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

        // Declare the output raster object				
        //Note: Adjust the IDistanceOp.EucAllocation method options to suit your applications need.
        object object_missing1 = System.Type.Missing;
        object object_missing2 = System.Type.Missing;
        ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset_output = distanceOp.EucAllocation(geoDataset, ref object_missing1, ref object_missing2);

        return geoDataset_output;
    }
    else
    {

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

    }

}
[Visual Basic .NET]
''' <summary>
''' Create a raster that has for each cell the zone of the closest source cell (in Euclidean distance).
''' </summary>
''' <param name="geoDataset">An IGeoDataset interface that has those cells or locations whose values are assigned to the output cell locations that they are closest to.</param>
''' <returns>An IGeoDataset interface that is the zone of the closest source cells.</returns>
''' <remarks>
''' Note: the input geoDataset's must be of Type IRaster, IRasterDataset, IRasterBand, IRasterDescriptor or IFeatureClass.
''' 
''' The IDistanceOp.EucAllocation Method has two options (maxDistance and valueRaster) that 
''' will greatly vary the output raster. Thess values will need to be adjusted for your application to achieve 
''' the desired results.
''' 
''' For information about the IDistanceOp.EucAllocation Method see:
''' http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriSpatialAnalyst/IDistanceOp_EucAllocation.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 CreateDistanceOpEucAllocationRaster(ByVal geoDataset As ESRI.ArcGIS.Geodatabase.IGeoDataset) As ESRI.ArcGIS.Geodatabase.IGeoDataset

  If (TypeOf geoDataset Is ESRI.ArcGIS.Geodatabase.IRaster _
  Or TypeOf geoDataset Is ESRI.ArcGIS.Geodatabase.IRasterDataset _
  Or TypeOf geoDataset Is ESRI.ArcGIS.DataSourcesRaster.IRasterBand _
  Or TypeOf geoDataset Is ESRI.ArcGIS.GeoAnalyst.IRasterDescriptor _
  Or TypeOf geoDataset Is ESRI.ArcGIS.Geodatabase.IFeatureClass) 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.EucAllocation 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_output As ESRI.ArcGIS.Geodatabase.IGeoDataset = distanceOp.EucAllocation(geoDataset, object_missing1, object_missing2)

    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