Tool parameter domains

Assigning a domain to a parameter allows you to specify a fixed value for the parameter. An assigned domain value is convenient for the user, and it minimizes critical errors during tool execution since the value of the parameter is set by the tool developer. This topic explains how to assign domains and discusses scenarios where you may want to use them.

In this topic

About tool parameter domains

Domains can be defined to specify fixed input values for a custom geoprocessing function tool's parameters or to filter parameter values. For example, you can assign a domain to an input parameter of the integer data type and restrict its value to a range of 1 to 100. Or you can define a tool input parameter to accept only shapefiles. 
The following screen shot shows the Clip tool dialog box. The input parameter for the XY Tolerance can have an assigned domain, and the available domain values are listed in a drop-down menu.
Use the GPParameter.setDomainByRef() method to assign a domain to a tool parameter. Define a parameter domain value using one of the following domain classes that implement the IGPDomain interface:
The most common scenarios for assigning a domain to an input parameter are as follows:

String keywords

Domains can be assigned to an input parameter to allow the user to choose a parameter value from a fixed set of string values. For example, the Add Field tool has set Field Type values of text, long, double, short, float, date, blob, and raster as shown in the following screen shot:
In a case such as this, domain values (keywords) for the parameter are defined using the GPCodedValueDomain class. The following code snippet shows how to create a coded value domain containing specific keywords for a parameter and how to assign it to the Field Type input parameter:[Java]
class AddFieldTool extends BaseGeoprocessingTool{

    public IArray getParameterInfo()throws IOException, AutomationException{
        IArray parameters = new Array();
        GPParameter parameter;


        //Define parameter 3: Field type
        parameter = new GPParameter();
        parameter.setDisplayName("Field Type");
        parameter.setDataTypeByRef(new GPStringType());
        parameter.setValueByRef(new GPString());

        //Define domain values (keywords) for the Field Type parameter.
        IGPCodedValueDomain domain = new GPCodedValueDomain();
        domain.addStringCode("TEXT", "TEXT");
        domain.addStringCode("LONG", "LONG");
        domain.addStringCode("DOUBLE", "DOUBLE");
        domain.addStringCode("SHORT", "SHORT");
        domain.addStringCode("FLOAT", "FLOAT");
        domain.addStringCode("DATE", "DATE");
        domain.addStringCode("BLOB", "BLOB");
        domain.addStringCode("RASTER", "RASTER");

        //Assign the domain to the parameter.

    //Implement other methods.
The keywords for domain values are hard coded in the geoprocessing function tool and are not changed once the tool is built. Do not put keywords in a resource file since they can be inadvertently localized, which could break your code. Additional good practices for creating keywords are as follows: 

Boolean parameters

In a tool dialog box, Boolean parameters are listed as check box options; in the command line and scripting, they are listed as two strings. Always create a coded value domain for a Boolean parameter.
The following code snippet shows how to create a coded value domain with Boolean values and corresponding string codes and how to assign the domain to a parameter:
Always create a coded value domain for a Boolean parameter.
class CustomJavaTool extends BaseGeoprocessingTool{

    public IArray getParameterInfo()throws IOException, AutomationException{


        GPParameter parameter = new GPParameter();
        //Set other properties.
        // Always create a coded value domain for Boolean parameters.
        IGPCodedValueDomain bool_domain = new GPCodedValueDomain();
        IGPValue bool_value = new GPBoolean();
        bool_domain.addCode(bool_value, "CONTINUE_COMPARE");
        bool_value = new GPBoolean();
        bool_domain.addCode(bool_value, "NO_CONTINUE_COMPARE");



    //Override other required methods of BaseGeoprocessingTool.


Feature types

If the input values of a parameter are features—that is, points, lines, or polygons—you can use a domain to build the list of layers or features in the catalog minibrowser. Filtering occurs when the data type validates the value. When using getParameterInfo(), the input feature class parameter is built with a domain to filter the input feature classes so only polygon features are used as shown in the following code:
class CustomJavaTool extends BaseGeoprocessingTool{

    public IArray getParameterInfo()throws IOException, AutomationException{
        IArray parameters = new Array();

        GPParameter inputParameter = new GPParameter();
        //Define other properties for the parameter.

        // Define the domain to filter the input features to polygon features only. 
        IGPFeatureClassDomain fcDomain = new GPFeatureClassDomain();
        //....Define other parameters of the tool.


    //Override other required methods of BaseGeoprocessingTool.


Dynamic domains

Domain values can be assigned or the values can be modified dynamically. You can use dynamic domains when you want keywords in one parameter to be based on the value of another parameter. For example, you want one set of keywords if point features are input, and another set if line features are input. In this case, you can modify the domain values dynamically using the BaseGeoprocessingTool.updateParameters() method. Another example is a coded value domain of SDE configuration keywords. The domain list changes based on the workspace parameter used.
The following code snippet shows how to modify domains using the updateParameters() method. When the value for parameter 1 is input (GPBoolean datatype), parameter 3 (GPString datatype) is enabled, and its domain is assigned dynamically by the updateParameters() method.
class CustomJavaTool extends BaseGeoprocessingTool{

    public void updateParameters(IArray paramvalues, IGPEnvironmentManager envMgr){

        // Get the Boolean parameter value for this tool.
        IGPBoolean val1 = (IGPBoolean)gpUtilities.unpackGPValue

        // Get the coded value parameter.
        IGPParameterEdit3 cvParam = (IGPParameterEdit3)paramvalues.getElement(3);

        // If the Boolean parameter value is true, update the domain with new values.
        if (val1.isValue()){
            //Enable paramater 3.
            //Create the domain.
            IGPCodedValueDomain cvDomain = new GPCodedValueDomain();
            cvDomain.addStringCode("Seconds", "Seconds");
            cvDomain.addStringCode("Feet", "Feet");

See Also:

Geoprocessing tool parameter data types
Customizing a tool dialog

Development licensingDeployment licensing
Engine Developer KitEngine
ArcGIS for Desktop StandardArcGIS for Desktop Basic
ArcGIS for Desktop BasicArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced