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:
- You might want to display only cities with a population above a certain threshold.
- Many datasets, such as roads and street datasets, have subsets of features (classes), and you might want to define map layers for each class of roads independent of the other features.
- In another case, you might have large enterprise databases with datasets that contain millions of features across wide extents—say for a whole nation or state. Yet, in your maps, you might want to work with only a subset of that data.
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.
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.
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
- Right-click the layer in the table of contents and click Properties.
- Click the Definition Query tab on the Layer Properties dialog box.
- Enter a query expression. See Building a query expression for more information on how to build valid queries.
- 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.