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:
- Initialize the geoprocessor.
- Initialize the geoprocessing tool.
- Set up the geoprocessing tool parameters.
- Run the tool.
- Decode the feature layer to get the output feature class.
- 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 valuesIGPUtilities3 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):
- ESRI.ArcGIS.Geoprocessing
- ESRI.ArcGIS.Geodatabase
- ESRI.ArcGIS.Geoprocessor
- ESRI.ArcGIS.DataManagementTools
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |