This sample code demonstrates how to convert a Raster to a shapefile using RasterConvertHelper object.
How to use
- Start ArcMap.
- Add a raster into ArcMap.
- Make sure that the Spatial Analyst or 3D Extension is turned on.
- Paste the following code into VBA.
- Set a reference to the ESRI GeoAnalyst Object Library.
- Run the sub from the Macros dialog.
Sub RasterConvertHelper()
'Get the focused Map from MapDocument
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
'Get the input raster from the first layer in ArcMap
Dim pLayer As ILayer
Dim pRasLayer As IRasterLayer
Dim pInRaster As IRaster
Set pLayer = pMap.Layer(0)
If Not TypeOf pLayer Is IRasterLayer Then Exit Sub
Set pRasLayer = pLayer
Set pInRaster = pRasLayer.Raster
'Create a RasterConvertHelper operator
Dim pRasConvertHelper As IRasterConvertHelper
Set pRasConvertHelper = New RasterConvertHelper
Dim pEnv As IRasterAnalysisEnvironment
Set pEnv = New RasterAnalysis
pEnv.SetCellSize esriRasterEnvMaxOf
'Perform ToShapefile operation
Dim pOutFClass As IFeatureClass
Set pOutFClass = pRasConvertHelper.ToShapefile(pInRaster, esriGeometryAny, pEnv)
'Create a feature layer from output and add it into ArcMap
Dim pOutFeatureLayer As IFeatureLayer
Set pOutFeatureLayer = New FeatureLayer
Set pOutFeatureLayer.FeatureClass = pOutFClass
pOutFeatureLayer.Name = "My new feature layer"
pMap.AddLayer pOutFeatureLayer
End Sub