Displaying a subset of features in a layer

When you specify a dataset that you want to draw as a map layer, you often only want to draw some of the features in the dataset. In these situations, you can define a query expression to select a subset of features for the layer display. This is referred to as a definition query.

For example:

If you only want to display and work with a subset of features in a layer, you can apply a definition query to a layer. You can type your own expression, or you can use the Query Builder dialog box to help you set up your query expression.

When performing a query on an enterprise geodatabase feature class with both spatial and attribute components, the dialog launched by the Search order button lets you choose whether to perform the spatial search first (the default) or the attribute search first. This enables you to fine-tune how the query will be executed. This button is only present if the data source for the layer is an enterprise geodatabase feature class.

NoteNote:

If the Perform the spatial search first option is selected the definition query will limit the features to those available in the extent. If the Perform the attribute search first option is selected, all attributes that match your query from the entire dataset will be selected and then the spatial search will find all those values that are visible in your extent.

If your map has Data Driven Pages enabled, you can use Page Definition Queries to specify which features of a layer are drawn based on an SQL query. Though similar to other definition queries, page definition queries differ in that they only work with Data Driven Pages and are dynamic. Features are filtered based on the current page. As you iterate through the pages, the query changes and a new set of features appropriate to the new page are drawn. If you have features that overlap page extents and want these features to be displayed in multiple pages, you should consider using Clip to customize your map. This button is only present if Data Driven Pages has been defined for your map document. When Data Driven Pages is defined, it is not present in the layer properties for the layer currently being used as the index layer for Data Driven Pages.

CautionCaution:

Definition queries are unavailable if you are working with a table or event layer (x,y or route) data source that does not have an ObjectID (OID) field. This will be the case with text files (.txt files); Excel data (.xls files); and OLE DB data, such as unregistered Oracle files accessed through OLE DB.

With event data, the workaround is to create a feature class from the tabular data source instead of an event layer. If you are adding a table with no ObjectID field containing x,y data, don't use the File > Add Data > Add XY Data command in ArcMap to create an event layer based on the table. Instead start ArcCatalog, right-click the table, choose Create Feature Class from XY to create a new feature class from it, then add that new feature class into your map. Alternatively, after using File > Add Data > Add XY Data or File > Add Data > Add Route Events functions to create an event layer from a table without an ObjectID, you can export the data to make a new layer. This saves the data to a feature class and therefore writes an ObjectID field. Another option is to use the Make Query Table geoprocessing tool, which allows you to make the table using an OLE DB connection and to specify a column to use for the ObjectID or dynamically add the ObjectID.

Creating a definition query

  1. Right-click the layer in the table of contents and click Properties.
  2. Click the Definition Query tab on the Layer Properties dialog box.
  3. Enter a query expression.
    Entering a definition query to display a subset of features
    Query Builder lets you create an expression to identify the particular features in the layer you want to display.
    See Building a query expression for more information on how to build valid queries.
  4. Click OK.

Once you set the definition query, the map is redrawn and displays the subset of features that are selected using your query. The layer continues to be drawn with this feature subset each time the map is refreshed.

To add all the features back to the layer, simply delete the definition query.

Related Topics

3/5/2014