In this topic
- About GPDataTypeArcObject
- Assigning GPDataTypeArcObject to tool parameters
- Composite data type
- MultiValue data type
- ValueTable data type
About GPDataTypeArcObject
In geoprocessing, every tool parameter must be assigned a corresponding GPDataTypeArcObject. Simple GPDataTypeArcObjects include the following:
- GPStringType—Any set of alphanumeric characters
- GPBooleanType—A true or false value
- GPLongType—An integer value between -2,147,483,648 and 2,147,483,647
In addition to these simple GPDataTypeArcObjects, there are dozens of other ArcObjects data types built specifically for data found in ArcGIS, such as Feature Class and Extent. The GPDataTypeArcObject is chosen for a parameter based on the data type of its value. For example, if the parameter value is a String data type, the corresponding GPDatatypeArcObject must be GPStringType. Assigning a GPDataTypeArcObject to a parameter provides the following information to the Geoprocessing framework about the parameter:
- The parameter's acceptable values
- Operations that can be performed on the data
- The manner in which the data is stored
Also, the geoprocessing framework provides an associated user interface (UI) control for every GPDataTypeArcObject. When you input data, the geoprocessing framework validates the data based on its data type. Consider the example of a custom function tool the 'Add Field tool' that adds a new field to a specified feature class. Notice the Add Field Tool dialog box of the custom feature tool in the following screenshot that shows the different UI created for different GPDataTypeArcObject.
For a complete list of GPDataTypeArcObjects, see IGPDataType. All implementing classes of IGPDataType are considered GPDataTypeArcObjects. To learn more about GPArcObjectDataTypes and descriptions, see List of Geoprocessing data types.
Assigning GPDataTypeArcObject to tool parameters
When creating a custom geoprocessing function tool, the parameters of the tool are assigned the corresponding GPDataTypeArcObject using the GPParameter.setDataTypeByRef() method. The following code snippet shows how to assign appropriate GPDataTypeArcObjects to Input Feature and Field Name parameters of the Add Field Tool in the BaseGeoprocessingTool.getParameterInfo() method in your custom function tool class. To learn more about creating custom function tool class refer topic Creating custom function tool class.
[Java]
//custom geoprocessing Function tool class
class AddTool extends BaseGeoprocessingTool{
/*Defines the parameters of the tool*/
public IArray getParameterInfo()throws IOException, AutomationException{
IArray parameters = new Array();
GPParameter parameter;
//Parameter 1: Input Feature
parameter = new GPParameter();
parameter.setName("in_Feature");
parameter.setDisplayName("Input Feature");
parameter.setDirection
(esriGPParameterDirection.esriGPParameterDirectionInput);
parameter.setParameterType(esriGPParameterType.esriGPParameterTypeRequired);
//The parameter accepts feature classes.
parameter.setDataTypeByRef(new DEFeatureClassType());
//The corresponding assigned value is DEFeatureClass.
parameter.setValueByRef(new DEFeatureClass());
parameters.add(parameter);
//.....
//Parameter 2: Field Name
parameter = new GPParameter();
parameter.setName("in_fieldName");
parameter.setDisplayName("Field Name");
parameter.setDirection
(esriGPParameterDirection.esriGPParameterDirectionInput);
parameter.setParameterType(esriGPParameterType.esriGPParameterTypeRequired);
//The parameter accepts string values.
parameter.setDataTypeByRef(new GPStringType());
parameter.setValueByRef(new GPString());
parameters.add(parameter);
return parameters;
}
}
Some of the GPDataTypeArcObjects that are used in special circumstances are described below:
Composite data type
Typically, a tool parameter corresponds to one GPDataTypeArcObject. However, there are scenarios where the parameter's value can be of different data types. Consider the example in the following screen shot, the Input Dataset parameter for the Append tool can be a FeatureLayer, TableView, or RasterLayer data type.
When a parameter supports more than one data type, it's called a composite data type. The corresponding ArcObjects component for a composite data type is GPCompositeDataType. The GPDataTypeArcObjects that corresponds to the parameter are defined by the GPCompositeDatatype.addDataype() method.
The following code snippet shows the composite data type for a parameter that accepts a raster layer, feature layer, or table view:
[Java]
Class CustomFunctionTool extends BaseGeoprocessingTool{
public IArray getParameterInfo()throws IOException, AutomationException{
IArray parameters = new Array();
GPParameter parameter;
parameter = new GPParameter();
parameter.setName("in_dataset");
parameter.setDisplayName("Input Dataset");
parameter.setDirection
(esriGPParameterDirection.esriGPParameterDirectionInput);
parameter.setParameterType(esriGPParameterType.esriGPParameterTypeRequired);
//The parameter accepts input data of different data types.
IGPCompositeDataType compositeDataType = new GPCompositeDataType();
//List the acceptable data types.
compositeDataType.addDataType(new GPFeatureLayerType());
compositeDataType.addDataType(new GPRasterLayerType());
compositeDataType.addDataType(new GPTableViewType());
//Assign the GPDataTypeArcObject to the parameters.
parameter.setDataTypeByRef((IGPDataType)compositeDataType);
parameter.setValueByRef((IGPValue)new GPTableView());
parameters.add(parameter);
return parameters;
}
}
MultiValue data type
In general, the Custom function tools that perform batch conversions between formats, can have parameters that support multiple inputs of the same data type. Consider the example of the Calculate Area tool, which calculates the area of polygon feature classes. It can calculate the area for multiple inputs of feature classes as a batch process.
The following screen shot shows the Java Calculate Area Batch tool dialog box. Notice the parameter Input Features can accept multiple values.
In such cases, the GPDataTypeArcObject of the parameter is defined as MultiValueType. The following code shows how to create a parameter and assign a MultiValueType GPDataTypeArcObject to accept multiple input feature layers:[Java]
// MultiValueType parameter of feature layers and feature classes.
Class CalculateAreaBatch extends BaseGeoprocessingTool{
public IArray getParameterInfo()throws IOException, AutomationException{
IArray parameters = new Array();
GPParameter inputFeatures = new GPParameter();
inputFeatures.setName("input_features");
inputFeatures.setDisplayName("Input Features");
inputFeatures.setParameterType
(esriGPParameterType.esriGPParameterTypeRequired);
inputFeatures.setDirection
(esriGPParameterDirection.esriGPParameterDirectionInput);
//The parameter supports multiple values.
IGPMultiValueType mvType = new GPMultiValueType();
//The multiple values are of GPFeatureLayerType data type.
IGPDataType inputType = new GPFeatureLayerType();
mvType.setMemberDataTypeByRef(inputType);
//Assign a data type to the parameter.
inputFeatures.setDataTypeByRef((IGPDataType)mvType);
IGPMultiValue mvValue = new GPMultiValue();
mvValue.setMemberDataTypeByRef(inputType);
inputFeatures.setValueByRef((IGPValue)mvValue);
parameters.add(inputFeatures);
return parameters;
}
}
ValueTable data type
When a parameter's value accepts multiple inputs of different data types, it's called a ValueTableType. An example of a ValueTableType is shown in the following screen shot of the Union tool dialog box. Notice, the Input Features parameter for this tool is a table with two columns. The data type of the first column is FeatureLayer and the data type of the second column is String. The GPValueTableType is the GPDataTypeArcObject that supports such parameters.
The following code shows how to assign GPValueTableType GPDataTypeArcObject to a tool's parameter.
[Java]
Class UnionTool extends BaseGeoprocessingTool{
public IArray getParameterInfo()throws IOException, AutomationException{
IArray parameters = new Array();
IGPParameterEdit3 inputFeatures = new GPParameter();
inputFeatures.setName("input_features");
inputFeatures.setDisplayName("Input Features");
inputFeatures.setParameterType
(esriGPParameterType.esriGPParameterTypeRequired);
inputFeatures.setDirection
(esriGPParameterDirection.esriGPParameterDirectionInput);
//Create ValueTableType.
IGPValueTableType valueTableType = new GPValueTableType();
//The first data type is GPFeatureLayerType.
IGPDataType inputLayerType = new GPFeatureLayerType();
valueTableType.addDataType(inputLayerType, "Features", 600, null);
//The second data type is GPLongType.
IGPDataType inputLongType = new GPLongType();
valueTableType.addDataType(inputLongType, "Rank", 100, null);
//Assign the GPDataTypeArcObject to the input parameter.
inputFeatures.setDataTypeByRef((IGPDataType)valueTableType);
//Assign values.
IGPValueTable valueTable = new GPValueTable();
//Define the data type for the value ArcObjects.
valueTable.addDataType(new GPFeatureLayerType());
valueTable.addDataType(new GPStringType());
inputFeatures.setValueByRef((IGPValue)valueTable);
parameters.add(inputFeatures);
//Create additional parameters.
return parameters;
}
}
See Also:
Creating a custom function tool classDefining domain for tool parameters
Updating output parameter using schema for ModelBuilder
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |
Server | Server |
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Standard |
ArcGIS for Desktop Standard | ArcGIS for Desktop Advanced |