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


How to access the features in an in-memory output layer using IFeatureCursor (ArcObjects .NET 10.5 SDK)

How to access the features in an in-memory output layer using IFeatureCursor


Summary
Some geoprocessing tools, such as MakeFeatureLayer and MakeTableView, create in-memory feature layers and table views. However, you might want to access the features and rows by using cursors. This topic shows how to get a feature cursor for the output layer created by the MakeFeatureLayer tool.

Accessing features in an in-memory output layer using IFeatureCursor

In geoprocessing, the primary reason for making and using layers and table views is to perform attribute and area selections. By making a layer or table view first, you can perform selections without affecting the original data source. Layers, layer files, and table views can be used as input to many of the geoprocessing tools. Some tools, such as MakeFeatureLayer and MakeTableView, can create in-memory feature layers and table views. When a geoprocessing tool creates a feature layer or a table view, you may want to access the features and rows using cursors.
To access features in an in-memory output layer using IFeatureCursor, follow these steps:
  1. Initialize the geoprocessor.
  2. Initialize the geoprocessing tool.
  3. Set up the geoprocessing tool parameters.
  4. Run the tool.
  5. Decode the feature layer to get the output feature class.
  6. Get a cursor to the features in the feature class.
The following code example shows how to access the features in the output layer created by the Make Feature Layer tool. This examples uses DecodeFeatureLayer method of IGPUtilities3 to return the feature class and query filter specified by the given geoprocessing value object.
IGeoprocessorResult2 is used to get the return value of an executed tool.
[C#]
// Intialize the geoprocessor.
Geoprocessor GP=new Geoprocessor();

// Intialize the MakeFeatureLayer tool.
MakeFeatureLayer makefeaturelayer=new MakeFeatureLayer();

// Set up the GP tool parameters and run the tool.
makefeaturelayer.in_features=@"C:\gp\nfld.gdb\wells";
makefeaturelayer.out_layer="Wells_Lyr";
makefeaturelayer.where_clause="WELL_YIELD > 150";

IGeoProcessorResult result=(IGeoProcessorResult)GP.Execute(makefeaturelayer, null);

IFeatureClass fc;
IQueryFilter qf;

IGPUtilities gpUtils=new GPUtilitiesClass();
gpUtils.DecodeFeatureLayer(result.GetOutput(0), out fc, out qf);

IFeatureCursor cursor=fc.Insert(true);
[VB.NET]
/ / Intialize the Geoprocessor.
Dim gp As ESRI.ArcGIS.Geoprocessor.Geoprocessor=New ESRI.ArcGIS.Geoprocessor.Geoprocessor

/ / Intialize the MakeFeatureLayer tool.
Dim makefeaturelayer As MakeFeatureLayer=New MakeFeatureLayer

/ / Set up the GP tool parameters And run the tool.
makefeaturelayer.in_features="C:\SDK\data\nfld.gdb\Wells"
makefeaturelayer.out_layer="Wells_Lyr"
makefeaturelayer.where_clause="WELL_YIELD > 150"

Dim result As IGeoProcessorResult
result=gp.Execute(makefeaturelayer, Nothing)

Dim fc As IFeatureClass=Nothing
Dim qf As IQueryFilter=Nothing

Dim gpUtils As IGPUtilities=New GPUtilities
gpUtils.DecodeFeatureLayer(result.GetOutput(0), fc, qf)

Dim cursor As IFeatureCursor=fc.Insert(True)
For more information about geoprocessing tools and working with layers and table views, see An overview of the Layers and Table Views toolset.


See Also:

Tool return values
IGPUtilities3 interface




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
Engine Developer Kit Engine
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced