The Select Layer By Location tool allows the Input Feature Layer to be the same the layer specified in the Selecting 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 For and 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 (BOUNDARY_TOUCHES in Python) or Intersect (INTERSECT in Python) relationship.
Expand selection to intersecting polygons
The example below uses the Intersect relationship to expand a selection from two origin points. Within a distance (WITHIN_A_DISTANCE in Python) 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.