You are here:
Geoprocessing
>
Automating your work with models
>
Using ModelBuilder
Any model that uses a feature class or feature layer as input can be modified to accept a feature set. A feature set allows the user of your model to interactively enter features.
Any model that uses a table as input can be modified to accept a record set. A record set allows the user of your tool to interactively create a table of records.
Basic steps
The basic steps, as illustrated below, for modifying an existing model that accepts a feature class as input to accept a feature set instead are
- In ModelBuilder, right-click a feature class variable and click Properties.
- In the properties dialog box, click the Data Type tab.
- Select the Feature Set data type.
- Import a schema that defines the attributes, geometry type, and symbology. You can import a schema from an existing dataset, layer file, or layer.
Converting a feature class variable to a feature set
- Click OK.
- Save and close the model, then open the model tool from the ArcToolbox window.
The same steps apply for interactive row input except
- The variable data type is Record Set
- The schema only defines the attributes
Learn more about changing the data type of a variable.
More details about creating models with feature and record sets are found below.
Uses for feature and record sets
Any tool that uses a feature class or table as input also accepts a feature or record set. This means that if you want to interactively enter features or records for any tool, you can build a simple model around the tool and change the data type of the input from feature class to feature set, or from table to record set.
For example, the model below is built around the Geocode Addresses tool. Geocode Addresses takes a table containing an address field and ZIP Code field (depending on the type of used). In this model, the input table variable has been converted to a Record Set data type. The schema of the record set contains the definition of the three fields (Name, Address, and Zip). In addition, the Zip Code field has a coded value attribute domain that enables the drop-down list of valid ZIP Codes. When the model is opened from ArcToolbox, the user adds records and attributes, and the result of running the model tool is a point feature class of the address locations.
The above is just one use of a record set variable. Another way you might use a record set include converting XY coordinates to point features, as illustrated below.
Here is a list of just some of the ways you might make use of a feature set:
- Creating polygons for input to use with the Clip or Erase tool.
- Setting the observer points for the Viewshed tool.
- Setting the point to begin a downstream flow trace using the Cost Path tool.
- Adding points to determine nearby features using the Near or Euclidean Allocation tool.
- Create a point to determine the upstream watershed with the Watershed tool.
- Create candidate locations for a new store, then use Append to add the candidates to a feature class of existing store locations. The appended feature class can then be analyzed to determine the impact the new stores. The model below illustrates one idea for analyzing new locations:
- Use Create Thiessen Polygons to create a polygon feature class of each store's trade area.
- Use Identity to overlay the Thiessen polygons with customer locations.
- Use Frequency to calculate how many customers fall within each store's trade area.
Creating a model tool to allow interactive input
To enable interactive entry of features, you need a model variable with the feature set data type. For interactive entry of records, you need a model variable with the record set data type. There are two ways to create a feature or record set variable:
- Change the data type of an existing variable as described above.
- Create a new variable with a feature or record set data type and connect it to a tool, as illustrated below.
- As illustrated below, right-click in the ModelBuilder diagram and click Create Variable.
- In the Create Variable dialog box, choose Feature Set (or Record Set if you just want a table of records).
- Click OK.
- A new variable is created in ModelBuilder. Connect this variable to a tool.
Learn more about connecting variables to tools in ModelBuilder.
Feature sets are disabled in ModelBuilder
If you open a feature set variable in ModelBuilder, either by double-clicking the variable or by right-clicking and choosing Open, the dialog box that opens will be disabled—you are not able to enter features. (This is not the case for record sets—see below). This means you cannot run a model containing a feature set from ModelBuilder. The model can only be run by opening it from ArcToolbox or the Command Line window. Since the only way to use the feature set is by opening the model tool from ArcToolbox, you need to make the feature set variable a model parameter. In ModelBuilder, right-click the feature set variable and choose Model Parameter. A check mark will appear next to Model Parameter signifying that the variable is a model parameter.
If you need to run a model containing a feature set from within ModelBuilder, you need to replace the feature set variable to a feature class variable, supply a value for the variable, and then run the model. The steps below describe one way to convert the variable and run the model.
- Disconnect the feature set from the tool by selecting and deleting the connector.
-
Add data to the tool.
-
Connect the added data to the tool.
-
Run the model.
- Delete the data variable added in step 2.
- Reconnect the feature set you disconnected in step 1.
Record sets can be used within ModelBuilder
Unlike feature sets, you can open a record set variable in ModelBuilder, add records, and enter attributes. You can then run the model from within ModelBuilder.
Any records you add to a record set in ModelBuilder will appear in the model tool dialog. This means you can populate the record set for the user. For example, the illustration below shows a table that has been populated with four records, each one containing a different soil type and a suitability score. When the model tool is opened, the user doesn't have to enter records—they just change the suitability score.
Populating a record set for your tool is a good technique. Just be aware that the user of your model tool still has the ability to add and delete records and change their attribute values from the tool dialog.
About schemas
A schema defines the attributes and geometry type (point, line, or polygon) of the features to be entered. The schema can also define the symbology to use when displaying new features, as illustrated below where points are symbolized according to the Type attribute. If the schema contains attributes with a coded value attribute domain, the values will appear as a drop-down list, illustrated below.
A record set schema only defines the attributes. If an attribute has a coded value attribute domain, it will appear as a drop-down list as illustrated above.
Where schemas come from
The schema for a feature set can be one of the following:
- A point, polyline, or polygon feature class. Since symbology is not stored with a feature class, the default symbology will be used when drawing interactively entered features.
- A layer file (.lyr) that references a point, polyline, or polygon feature class. The symbology defined in the layer file will be used to draw interactively digitized features.
- A layer in the table of contents.
Learn more about using layers and layer files.
For a record set, the schema defines the attributes and attribute domains of each record. The schema can be one of the following:
- A table or feature class (a feature class is a kind of table that contains shapes)
- The location of a layer file (.lyr) that references a feature class
- A table in the table of contents
Changing a schema
NOTE: When you apply a schema, the schema is read and stored with the model variable. If you subsequently change the schema—for example, changing the symbology or adding a coded value domain—you need to reapply the schema.
- In ModelBuilder, right-click the feature or record set variable and choose Properties.
- Click the Data Type tab.
- Choose the schema (dataset, layer file, or layer) again and click OK.
Because the schema is stored with the feature or record set, you can delete the schema once it has been applied.
Note that layers and layer files can also be used to define the symbology of output datasets, as described in
Setting symbology for output data. When a layer or layer file is used for defining output symbology, the layer or layer file must exist when the tool is run. This is not the case for schemas—the schema is read (from a dataset, layer, or layer file) and stored with the model.
Schemas should contain the minimal number of attributes
The schema should only have the attributes you need for your model to run. Extra unneeded attributes clutter the user interface and cause confusion.
About attribute domains
Attribute domains are rules that describe the legal values of a field. If a field in your template has an attribute domain, the values will be displayed in a drop-down list, as illustrated below.
Learn more about attribute domains.
Schemas are optional
If you don't specify a schema, the feature and record set will only allow importing of features or rows from an existing dataset, but the interactive digitizing of features or adding of rows will be disabled.
Noneditable fields are ignored
Some fields, such as OBJECTID and Shape_Length, are special fields that can only be edited internally by ArcGIS. You can view the contents of these fields, but you cannot edit (update) the contents. These noneditable fields are never shown as attributes of a feature or records set.
Schemas and existing datasets
The feature and record set controls allow you to enter an existing dataset by clicking Use features from
or Use records from
.
When using an existing dataset, the dataset is checked to determine if the schema attributes are found in the dataset. If any of the schema attributes are missing from the dataset, a warning is issued.
NOTE: Since a warning is issued—not an error—the tool can still be executed. If your model tool depends on fields in the schema being present in the dataset, your model may fail.
If you need to ensure that fields in the schema are found on the dataset, you can use the field check script tool described in
Branching: Implementing if-then-else logic. The field check script checks for the existence of a field on a dataset and outputs two Boolean variables, which can be used as preconditions in your model.
The illustration below shows the Geocode Address model
described above with additional logic to check the existence of the Address and Zip fields.
Feature and record set schemas cannot be altered by tools
Feature and record set variables cannot have their schemas altered. The following tools alter schema:
- Add Field
- Delete Field
- Add XY Coordinates
- Near
If you use a feature or record set as input to these tools, an error will be generated.
If you need to use these tools with a feature or record set, use
Copy Features or
Copy Rows to create a new dataset, then use this new dataset as input, as illustrated below.