How to use multiple inputs


Using multiple inputs

Tools can accept a single input or many inputs, depending on the operation. Tools that convert or overlay data can accept multiple datasets as input because of the nature of the operation. In a program, inputs are passed to these tools as a multivalue string, which uses a semicolon to separate each input in the string. A multivalue string is easy to construct in a program using the string manipulation functions built into the language.
In the following code example, a multivalue string is created with VB.NET and CSharp (C#) concatenation capabilities and used with the Union tool:
[C#]
public void ExampleGPUsingMultipleInputs()
{

    // Initialize the geoprocessor.
    Geoprocessor GP = new Geoprocessor();

    // Initialize the Union tool.
    Union uniontool = new Union();

    // List all feature classes in the workspace.
    GP.SetEnvironmentValue("workspace", @"C:\studyarea");
    IGpEnumList fcColl = GP.ListFeatureClasses("*", "", "");

    // Create a StringBuilder object and add the feature classes as a semicolon-delimited list.
    StringBuilder sb = new StringBuilder();
    string inputfeatures = fcColl.Next();

    while (inputfeatures != "")
    {

        sb.AppendFormat("{0};", inputfeatures);
        inputfeatures = fcColl.Next();
    }

    // Execute the Union tool with multiple inputs creating landuse.shp.
    uniontool.in_features = sb.ToString();
    uniontool.out_feature_class = "landuse.shp";
    GP.Execute(uniontool, null);

}
[VB.NET]
Public Sub ExampleGPUsingMultipleInputs()
    
    ' Initialize the geoprocessor.
    Dim GP As Geoprocessor = New Geoprocessor()
    
    ' Initialize the Union tool.
    Dim uniontool As Union = New Union()
    
    ' List all feature classes in the workspace.
    GP.SetEnvironmentValue("workspace", "C:\studyarea")
    Dim fcColl As ESRI.ArcGIS.Geoprocessing.IGpEnumList = GP.ListFeatureClasses("*", "", "")
    
    ' Create a StringBuilder object and add the feature classes as a semicolon-delimited list.
    Dim sb As StringBuilder = New StringBuilder()
    
    Dim inputfeatures As String = fcColl.Next()
    
    Do While inputfeatures <> ""
        
        sb.AppendFormat("{0};", inputfeatures)
        inputfeatures = fcColl.Next()
        
    Loop
    
    ' Execute the Union tool with multiple inputs creating landuse.shp.
    uniontool.in_features = sb.ToString()
    uniontool.out_feature_class = "landuse.shp"
    GP.Execute(uniontool, Nothing)
    
End Sub


See Also:

How Union works




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):