Select By Location: Select based on spatial relationship within the layer
The Select Layer By Location tool allows the Input Feature Layer to be the same the layer specified in theSelecting Features parameter. A useful application of this behavior is to select adjacent, connected, or nearby features within a layer. Different Relationship options can be used to generate the desired analysis or result. For details of how the Relationship options differ, see Select By Location: graphical examples.
A loop inside a script or the For or While iterators in ModelBuilder can be used in conjunction with this approach to expand a selection based on a number of iterations or until some criterion is met. One common criterion is expand until no new features are added to the selection. The Get Count tool can be used to establish when the number of selected features stops changing (therefore stops growing).
Below are some examples of analysis performed using this functionality with different types of data and relationship options.
Expand selection to adjacent counties
The following example expands the selection from a single county to select the adjacent counties, then the operation is repeated two times. This effect can be achieved by using either the BOUNDARY_TOUCHES or INTERSECT relationship.
Expand selection to intersecting polygons
The example below uses the INTERSECT relationship to expand a selection from two origin points. WITHIN_A_DISTANCE could also be used to select the features that are within a specified distance of the original selection.
Select connected roads
The approach of expanding a selection is not limited to polygon layers; it can also be used with line data. Below is an example of expanding a selection of streets that are connected to the original selection. The INTERSECT relationship selects any street that touches the selected street, while the BOUNDARY_TOUCHES relationship only includes the streets that have an endpoint (no overlap) on selected roads.