Instructions provided are for applying a route layer's definition query to a route event layer in ArcGIS version 8.3 and higher. For instructions doing this in versions 8.1.x and 8.2, please use the article in the Related Information, below.
The results of this procedure will display only the events on visible routes returned by a definition query. There is currently a known issue in the software that causes the definition query to not be read and results in events being displayed for all routes, whether they are visible or not. Background information describing the cause of this problem is available.
When an event layer is added to ArcMap, it uses a route locator, which is a set of properties that describe the route data. The route locator's properties include:
1. The route feature class.
2. The name of the route identifier field.
3. The route 'where clause', used to limit the routes on which the events are displayed.
At ArcGIS version 8.3, ArcMap recognizes whether a newly added layer contains routes and attaches a layer extension to the new layer. When asked, the layer extension knows how to create a 'name object' representation of a route locator. A 'name object' is like a blueprint and provides the necessary details to build an object when asked. The route locator name object can be opened to return a route locator. The route locator will have its feature class property set to the feature class upon which the layer is based, its route identifier field set and its route 'where clause' set to match the layer's definition query.
Part of using the Add Route Events dialog box is to specify the route reference. The Route Reference can either be a layer in the map or you can browse for a feature class on disk. When selecting a route layer already in the map, the Add Route Events dialog box asks the layer extension to create a route locator name object; this will subsequently be opened to create a route locator. When browsing for a feature class on the disk, ArcMap creates a new route locator.
The known issue in the software occurs when the Add Route Events dialog box is creating a new route locator. When a layer in the map has been selected as the route reference, it should be asking the layer extension to do it. This means that the new route locator gets its 'where clause' property set. The event layer that the Add Route Events dialog box creates, will have all the events displayed.
At versions prior to ArcGIS 8.3, no layer extension was attached to route layers. As such, the Add Route Events dialog box always created a new route locator. When the new route locator was created, no attention was paid to whether the Route Reference originated from a layer or a feature class on disk. The new route locator did not get its 'where clause' set and event layers created by way of the Add Route Events dialog box had all events displayed.
There are 4 options provided for addressing this issue.
Option 1 is the simplest because it does not use code, but options 2,3 and 4 require some ArcObjects programming skill.
- Option 1
Apply a definition query to the event table before displaying the route events.
This definition query may be identical to that created for the route layer if the route and event key items are the same. If the event key is named something different, a slight modification of the expression is necessary.
To apply a definition query to the event table:
A. Right-click on the event table in the table of contents and select Properties.
B. Click the Definition Query tab.
C. Type the definition query expression.
D. Click OK.
E. Use the Add Route Events dialog to create the event layer.
- Option 2
Add the event layer by way of an ArcObjects code.
In the code, the services of the route layer extension is used to create a route locator name object. This method ensures that the new event layer respects the route layer's definition query.
Click here to open the code for Option 2. Paste the code into ArcMap's Visual Basic Editor. Minor changes to the code are required, so that it references the correct route feature class, event table, and item names.
- Option 3
If the events have already been added to the map as a layer, copy the route layer's definition query to the event layer's route locator.
This option requires additional coding to pass the routine: the route layer whose definition query you want to copy and the event layer whose route locator you want to apply a route 'where clause' to.
Changing a route layer's definition query after the event layer has been added to the map will not change the number of events displayed in the event layer. If the route layer's definition query is changed, copy the route layer's new definition query to the event layer's locator.
Click here to open the code for Option 3.
- Option 4
Create a 'virtual' feature class that is based on a query and use this layer as the route reference.
Basing a layer on a query feature class is different than setting a definition query on a layer. A query feature class reduces that amount of data that is transferred over the 'wire'. In addition to limiting the number of features that are brought over, the attribute fields that are brought over can also be limited. Lastly, query feature classes can be used to perform 'joins' to other tabular data in the database.
A query feature class can only be based on a feature class that is stored in a personal or enterprise geodatabase; therefore, coverage and shapefile feature classes are not candidates for this procedure. Also, a query feature class cannot be edited.
Once the layer is created based on the query feature class, its definition query does not need to be set up, because those features simply do not exist in the new feature class. Now, the Add Route Events dialog can be used to create the event layers. This saves from having to use Options 2 or 3 for each event layer being added to the map.
Click here to open the code for Option 4 and copy it into ArcMap's Visual Basic Editor.