Using RasterDescriptor in a conversion operation

Created:4/4/2001
Description:

RasterDescriptor provides a way of using a field other than "value" field in the raster table. This code shows an example of converting a thematic raster to a polygon shape file using RasterDescriptor.

How to use:
  1. Start ArcMap and paste the code into VBA.
  2. Add a thematic raster into ArcMap.
  3. Change the field name and output directory in the code to fit your data.
  4. Change the output file name if necessary.
  5. Set the reference: ESRI Spatial Analyst Extension Object Library.
  6. Make sure the Spatial Analyst Extension is checked.
  7. Run the procedure: UsingRasterDescriptor().
Sub UsingRasterDescriptor()
     ' Set the three variables to fit your data
     Dim sFieldName As String
    Dim sPath As String
    Dim sFileName As String
    sFieldName = "Landuse"  ' Field Name in raster table
    sPath = "c:\temp"  ' Output directory
    sFileName = "ConOut.shp"  ' Name of output shapefile

     ' Get Map
     Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap

     ' Get raster from layer
     Dim pRLayer As IRasterLayer
    Set pRLayer = pMap.Layer(0)
    Dim pInRaster As IRaster
    Set pInRaster = pRLayer.Raster

     ' Create RasterDecriptor
     Dim pRDescr As IRasterDescriptor
    Set pRDescr = New RasterDescriptor
    pRDescr.Create pInRaster, Nothing, sFieldName
    
     ' Create ConversionOp
     Dim pConversionOp As IConversionOp
    Set pConversionOp = New RasterConversionOp

     ' Create workspace for feature output
     Dim pWS As IWorkspace
    Dim pWSF As IWorkspaceFactory
    Set pWSF = New ShapefileWorkspaceFactory
    Set pWS = pWSF.OpenFromFile(sPath, 0)

     ' Perform conversion
     Dim pOutFClass As IFeatureClass
    Set pOutFClass = pConversionOp.RasterDataToPolygonFeatureData(pRDescr, pWS, sFileName, True)

End Sub