Using layers and table views

The most common input to a tool is a dataset. You can, of course, always browse to the dataset on disk, but you can also use layers or table views as input.

List By Source

NoteNote:

Any tool that operates on a table will also operate on a feature class or feature layer. This is because feature classes are simply tables with an attribute containing the shape of the feature. In all other respects, they are a table.

When you open a tool dialog box in ArcMap or enter a tool name in the Python window, the following occur:

  1. ArcGIS examines the tool's parameters to see which parameters use an input dataset or table. If one is found, it further examines the type of input dataset. Is it a point feature class? A TIN? A network? A table?
  2. The ArcMap table of contents is then scanned and filtered to see whether any layers match the parameter's dataset type. If so, a list is built of the matching layers and presented as a drop-down list in the parameter's control. You can choose one of these layers or table views as your input.

The following illustration shows the Buffer tool and the drop-down menu of layers it constructed for the Input Features parameter.

Layers in a drop-down list

Some tools only accept layers or layer files as input or output. If this is the case with the tool you are using, the display name for the parameter will contain the word layer (for example, Input Feature Layer rather than Input Features).

Using a layer instead of browsing to the dataset on disk is natural and intuitive. But there's much more to using layers than as a simple shortcut to a dataset on disk.

The "Make Layer" tools—for example, Make Raster Layer—create a layer from the input data. This layer is temporarily stored in memory; it is not saved on disk and only remains available within the current session. If the session is closed, the layer is deleted. Layers created in ArcCatalog cannot be used in ArcMap, and vice versa. ArcCatalog does not display created layers, but they can be used as inputs to other geoprocessing tools in the session in which you are working.

Selections

A layer or table view contains a selection, sometimes called a selection set. A selection is a subset of the features in a feature class or a subset of rows in a table. There are a variety of ways you can select features in ArcMap, such as drawing a shape on the map display to select all features within the shape or using a logical expression. You can also select features and rows using geoprocessing tools found in the Data Management tools Layers and Table Views toolset. In ArcMap, you can see the number of features or rows by clicking the List By Selection button List By Selection found at the top of the table of contents, as illustrated below.

Viewing selections on layers and tables

Almost all geoprocessing tools operate only on the selected set of features or rows. For instance, the Clip tool only uses the currently selected features in both the input features and clip features datasets. The Summary Statistics tool calculates statistics only on the selection. In fact, it is rare that a tool does not operate on selected sets of features. If the tool does not use the selected set, the tool reference page explicitly states that it does not use the selected set.

NoteNote:

Tools that modify the schema of a feature class or table, such as Add Field, do not use the selected set since it is impossible to add fields to one set of records and not another.

Internal layers

You don't need ArcMap in order to create layers. You can use the Make Feature Layer tool found in the Layers and Table Views toolset to create an internal in-memory layer of a feature class in ArcCatalog.

When you create a layer or table view using geoprocessing tools, the new layer or table view is stored in an internal layer list, which is a different list from the ArcMap table of contents. This means that geoprocessing actually keeps two lists of layers and table views:

Regardless of where the layer is kept, the layers will be shown to you in the same drop-down list in the tool dialog box.

If you execute Make Feature Layer in ArcMap, the layer can automatically be added to the ArcMap table of contents by enabling the Add results of geoprocessing operations to the display option.

Using layers in models and scripts

When you exit an ArcGIS Desktop application, all layers are removed from memory. A common problem is creating a model or script that uses a layer as a variable—the model or script works fine in the current session but fails in subsequent sessions because the layer is deleted when the session ends. For example, a script might have the following piece of code:

landuse_layer = "Zoning"

In this example, the variable landuse_layer is "hard coded" to Zoning. Later in the script, the landuse_layer variable is used, and the script returns an error because there is no layer with the name Zoning in the current application. The script works fine if you execute it in ArcMap with the Zoning layer in the table of contents but fails when you execute the script in ArcCatalog, or anytime that layer doesn't exist.

A similar situation occurs in a model. You create a model where the Zoning layer is used, and the model fails because there is no layer by that name in the application.

Model with zoning layer

In both situations, you can do one of the following:

Using layer files

Layers can be saved to disk as a layer file (a file with the .lyr extension), then used as input to any tool that accepts a layer.

A layer file contains the same information as an internal layer (such as a layer in the ArcMap table of contents), including the selection of features.

To create a layer file, you can use the Save To Layer File tool. In ArcMap, you can right-click the layer in the table of contents and click Save As Layer File.

For any tool that accepts a layer, you can browse to a layer file (.lyr) on disk just as you would browse to a dataset on disk. However, when you browse to a layer file, some tools are unable to determine the type of data contained in the layer file and will show you all layer files. If you choose an inappropriate layer file, the tool will display an error or warning.

Duplicate layer names—Using group layers

In ArcMap, you are allowed to have multiple layers of the same name in the table of contents. When geoprocessing scans the table of contents to build the list of layers, it doesn't remove duplicate layer names, so the drop-down list of layers will contain all layers, regardless of whether the names are duplicated.

CautionCaution:

If you pick a layer with a duplicate name, you have no way of telling which layer will be used.

The best way to work around this issue is to use group layers, putting duplicate layers into different group layers. The following illustration shows two group layers in the ArcMap table of contents, each containing a layer of the same name. In the Add Field tool dialog box, the group layers are shown in a tree view, so you can pick the correct layer.

Group layers

Related Topics


12/15/2011