Converting data using GeoAnalyst objects (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > ArcGIS extensions > Spatial Analyst > Converting data using GeoAnalyst objects (ArcObjects .NET 10.6 SDK)

Converting data using GeoAnalyst objects


Summary
This topic provides a brief introduction to converting raster data for spatial analysis operations.

About converting data using GeoAnalyst objects

The RasterConversionOp object in the GeoAnalyst library provides conversion functionality for the ArcGIS Engine core product. You can use this object without an ArcGIS Spatial Analyst or ArcGIS 3D Analyst extension license.
The methods of RasterConversionOp are divided into the following three groups:
  • IConversionOp interface methods provide functionality to convert a raster to a feature class or vice versa.
  • IRasterImportOp or IRasterImportOp2 interface methods are used to import GRID ASCII, FLOAT, and USGS DEM format files as a raster.
  • IRasterExportOp interface methods are used to export a raster to an ASCII or a FLOAT file.
The geoprocessing tools in the Conversion toolbox provide the same functionality. For more information on conversion tools, see An overview of the Conversion toolbox.
The following code demonstrates how to convert a raster dataset to line feature data:
[C#]
public void ConvertRaterToLineFeature()
{
    //Convert the raster to a line feature class.
    //Get the input raster.
    IRasterDataset inRas01;
    inRas01=OpenRasterDataset("c:\\temp", "streamgrd");
    //Create RasterConverionOp.
    IConversionOp conversionOp;
    conversionOp=new RasterConversionOpClass();
    //Create Raster Analysis Environment. 
    IRasterAnalysisEnvironment env;
    env=(IRasterAnalysisEnvironment)conversionOp;
    IWorkspaceFactory workspaceFactory=new RasterWorkspaceFactoryClass();
    IWorkspace workspace=workspaceFactory.OpenFromFile("c:\\temp", 0);
    env.OutWorkspace=workspace;
    //Create an output shapefile workspace.
    IWorkspaceFactory wsFactory;
    wsFactory=new ShapefileWorkspaceFactoryClass();
    IWorkspace shapeWS;
    shapeWS=wsFactory.OpenFromFile("C:\\temp", 0);
    //Execute conversion. 
    IGeoDataset featClassOut;
    System.Object minDangle=(System.Object)1.0;
    featClassOut=conversionOp.RasterDataToLineFeatureData((IGeoDataset)inRas01,
        shapeWS, "stream1.shp", false, false, ref minDangle);
}
[VB.NET]
Public Sub ConvertRaterToLineFeature()
    'Convert the raster to a line feature class.
    'Get the input raster.
    Dim inRas01 As IRasterDataset
    inRas01=OpenRasterDataset("c:\temp", "streamgrd")
    'Create RasterConverionOp.
    Dim conversionOp As IConversionOp
    conversionOp=New RasterConversionOpClass()
    'Create Raster Analysis Environment.
    Dim env As IRasterAnalysisEnvironment
    env=conversionOp
    Dim workspaceFactory As IWorkspaceFactory=New RasterWorkspaceFactoryClass()
    Dim workspace As IWorkspace=workspaceFactory.OpenFromFile("c:\temp", 0)
    env.OutWorkspace=workspace
    'Create an output shapefile workspace.
    Dim wsFactory As IWorkspaceFactory
    wsFactory=New ShapefileWorkspaceFactoryClass()
    Dim shapeWS As IWorkspace
    shapeWS=wsFactory.OpenFromFile("C:\temp", 0)
    'Execute conversion.
    Dim featClassOut As IGeoDataset
    featClassOut=conversionOp.RasterDataToLineFeatureData(inRas01, shapeWS, "stream1.shp", False, False, 1.0#)
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced