You are here:
Geoprocessing tool reference
>
Data Management toolbox
>
Layers and Table Views toolset
>
Tools
NOTE: This topic was updated for 9.3.1.
Adds, updates, or removes a selection on the input layer based on spatial relationships to features in another layer. The features in the Input Feature Layer are evaluated against each individual feature in the Selected Features layer; if the Relationship is met, the feature will be selected.
Usage tips
-
For examples of spatial relationships that will be selected by the overlap types, see Select by Location: Graphical examples.
-
The input must be a or a . It cannot be a or .
-
This tool is not limited to working in ArcMap; it works on layers and table views in ArcCatalog and in scripts. The Make Feature Layer tool makes a layer for a feature class, and the Make Table View tool does the equivalent for a table.
-
Learn more about working with layers and table views.
-
If an extent or a definition query is present on the Input Feature Layer, only those features or rows that match the extent and/or definition query will be available to be selected.
-
The Get Count tool returns the number of features selected by the tool.
-
This tool can be used to select features based on spatial relationships to other features within the layer. For further details and graphical examples of this, click here.
-
The following environment settings affect this tool: workspace, scratch workspace.
Command line syntax
An overview of the Command Line window
SelectLayerByLocation_management <in_layer> {INTERSECT | WITHIN_A_DISTANCE | COMPLETELY_CONTAINS | COMPLETELY_WITHIN | HAVE_THEIR_CENTER_IN | SHARE_A_LINE_SEGMENT_WITH | BOUNDARY_TOUCHES | ARE_IDENTICAL_TO | CROSSED_BY_THE_OUTLINE_OF | CONTAINS | CONTAINED_BY} {select_features} {search_distance} {NEW_SELECTION | ADD_TO_SELECTION | REMOVE_FROM_SELECTION | SUBSET_SELECTION | SWITCH_SELECTION}
<in_layer> |
The input feature layer name. This can be a layer in ArcMap or a layer created by Make Layer in ArcCatalog or in a script.
|
Feature Layer |
{INTERSECT | WITHIN_A_DISTANCE | COMPLETELY_CONTAINS | COMPLETELY_WITHIN | HAVE_THEIR_CENTER_IN | SHARE_A_LINE_SEGMENT_WITH | BOUNDARY_TOUCHES | ARE_IDENTICAL_TO | CROSSED_BY_THE_OUTLINE_OF | CONTAINS | CONTAINED_BY} |
The spatial relationship between the features in the input layer and the Select Layer on which the selection will be based. If the textual description is unclear, refer to the Graphical examples.
- INTERSECT —
The features in the input layer will be selected if they intersect a select feature. This is the default.
- WITHIN_A_DISTANCE —
The features in the input layer will be selected if they are within a specified distance of a select feature. Specify a distance in the search distance parameter.
- CONTAINS —
The features in the input layer will be selected if they contain a select feature. This is only valid when the input features are polygons.
- COMPLETELY_CONTAINS —
The features in the input layer will be selected if they completely contain a select feature. The input features layer must be polygons.
- CONTAINS_CLEMENTINI —
This spatial relationship will provide the same results as COMPLETELY_CONTAINS if the feature in the select layer is entirely on the boundary of the input feature. When no part of the contained feature is properly inside the feature in the input layer, the input feature will not be selected. CLEMENTINI states that the boundary of a point is always empty and the boundary of a line is the endpoints.
- WITHIN —
The features in the input layer will be selected if they are within one of the select features. This is only valid when the select features are polygons.
- COMPLETELY_WITHIN —
The features in the input layer will be selected if they are completely within or contained by a select feature.
- WITHIN_CLEMENTINI —
The result will be identical to CONTAINED_BY except if the entirety of the feature in the input layer is on the boundary of the feature in the select layer. CLEMENTINI states that the boundary of a point is always empty and the boundary of a line is the endpoints.
- ARE_IDENTICAL_TO —
The features in the input layer will be selected if they are identical (in geometry) to a select feature.
- BOUNDARY_TOUCHES —
The features in the input layer will be selected if they have a boundary that touches a select feature. The input and select features must be lines or polygons. Additionally, the feature in the input layer must be either completely inside or outside the polygon from the select layer.
- SHARE_A_LINE_SEGMENT_WITH —
The features in the input layer will be selected if they share a line segment with a select feature. The input and select features must be lines or polygons.
- CROSSED_BY_THE_OUTLINE_OF —
The features in the input layer will be selected if they are crossed by the outline of a select feature. The input and select features must be lines or polygons. If polygons are used for the input or select layer, the polygon's boundary (line) will be used. Lines that cross at a point will be selected, not lines that share a line segment.
- HAVE_THEIR_CENTER_IN —
The features in the input layer will be selected if their center falls within a select feature. The center of the feature is calculated as follows: for polygon and multipoint, the geometry's centroid is used; for line input, the geometry's midpoint is used.
- CONTAINED_BY —
This returns the same result as WITHIN. This is here for backward compatibility with 9.2 models and scripts.
|
String |
{select_features} |
The features in the input layer will be selected based on their topological relationship to the features from this layer or feature class.
|
Feature Layer |
{search_distance} |
If the Overlap Type is set to WITHIN_A_DISTANCE, set this parameter to the desired distance. Any Input Feature which intersects the buffered Select Features will be selected.
This search distance functionality is not only for use with the WITHIN_A_DISTANCE Overlap type. If a search distance is specified, a buffer of that distance is applied to each Select features geometry. When the Overlap type (topological relationship) is evaluated, the buffered geometry is used instead of the original geometry.
The following Overlap type options do not support the search distance buffering: SHARE_A_LINE_SEGMENT_WITH and ARE_IDENTICAL_TO.
|
Linear unit |
{NEW_SELECTION | ADD_TO_SELECTION | REMOVE_FROM_SELECTION | SUBSET_SELECTION | SWITCH_SELECTION} |
Determines how the selection will be applied and what to do if a selection already exists.
- NEW_SELECTION —
The resulting selection replaces any existing selection. This is the default.
- ADD_TO_SELECTION —
The resulting selection is added to an existing selection if one exists. If no selection exists, this is the same as the NEW_SELECTION option.
- REMOVE_FROM_SELECTION —
The resulting selection is removed from an existing selection. If no selection exists, this option has no effect.
- SUBSET_SELECTION —
The resulting selection is combined with the existing selection. Only records that are common to both remain selected.
- SWITCH_SELECTION —
Switches the selection. All records that were selected are removed from the selection, and all records that were not selected are added to the selection. The Select Features and Overlap type will be ignored when this option is specified.
|
String |
Data types for geoprocessing tool parameters
Command line example
SelectLayerByLocation wells_lyr have_their_center_in c:\gdb.mdb\kamsack_city_lim
Scripting syntax
About getting started with writing geoprocessing scripts
SelectLayerByLocation_management (in_layer, overlap_type, select_features, search_distance, selection_type)
in_layer (Required) |
The input feature layer name. This can be a layer in ArcMap or a layer created by Make Layer in ArcCatalog or in a script.
|
Feature Layer |
overlap_type (Optional) |
The spatial relationship between the features in the input layer and the Select Layer on which the selection will be based. If the textual description is unclear, refer to the Graphical examples.
- INTERSECT —
The features in the input layer will be selected if they intersect a select feature. This is the default.
- WITHIN_A_DISTANCE —
The features in the input layer will be selected if they are within a specified distance of a select feature. Specify a distance in the search distance parameter.
- CONTAINS —
The features in the input layer will be selected if they contain a select feature. This is only valid when the input features are polygons.
- COMPLETELY_CONTAINS —
The features in the input layer will be selected if they completely contain a select feature. The input features layer must be polygons.
- CONTAINS_CLEMENTINI —
This spatial relationship will provide the same results as COMPLETELY_CONTAINS if the feature in the select layer is entirely on the boundary of the input feature. When no part of the contained feature is properly inside the feature in the input layer, the input feature will not be selected. CLEMENTINI states that the boundary of a point is always empty and the boundary of a line is the endpoints.
- WITHIN —
The features in the input layer will be selected if they are within one of the select features. This is only valid when the select features are polygons.
- COMPLETELY_WITHIN —
The features in the input layer will be selected if they are completely within or contained by a select feature.
- WITHIN_CLEMENTINI —
The result will be identical to CONTAINED_BY except if the entirety of the feature in the input layer is on the boundary of the feature in the select layer. CLEMENTINI states that the boundary of a point is always empty and the boundary of a line is the endpoints.
- ARE_IDENTICAL_TO —
The features in the input layer will be selected if they are identical (in geometry) to a select feature.
- BOUNDARY_TOUCHES —
The features in the input layer will be selected if they have a boundary that touches a select feature. The input and select features must be lines or polygons. Additionally, the feature in the input layer must be either completely inside or outside the polygon from the select layer.
- SHARE_A_LINE_SEGMENT_WITH —
The features in the input layer will be selected if they share a line segment with a select feature. The input and select features must be lines or polygons.
- CROSSED_BY_THE_OUTLINE_OF —
The features in the input layer will be selected if they are crossed by the outline of a select feature. The input and select features must be lines or polygons. If polygons are used for the input or select layer, the polygon's boundary (line) will be used. Lines that cross at a point will be selected, not lines that share a line segment.
- HAVE_THEIR_CENTER_IN —
The features in the input layer will be selected if their center falls within a select feature. The center of the feature is calculated as follows: for polygon and multipoint, the geometry's centroid is used; for line input, the geometry's midpoint is used.
- CONTAINED_BY —
This returns the same result as WITHIN. This is here for backward compatibility with 9.2 models and scripts.
|
String |
select_features (Optional) |
The features in the input layer will be selected based on their topological relationship to the features from this layer or feature class.
|
Feature Layer |
search_distance (Optional) |
If the Overlap Type is set to WITHIN_A_DISTANCE, set this parameter to the desired distance. Any Input Feature which intersects the buffered Select Features will be selected.
This search distance functionality is not only for use with the WITHIN_A_DISTANCE Overlap type. If a search distance is specified, a buffer of that distance is applied to each Select features geometry. When the Overlap type (topological relationship) is evaluated, the buffered geometry is used instead of the original geometry.
The following Overlap type options do not support the search distance buffering: SHARE_A_LINE_SEGMENT_WITH and ARE_IDENTICAL_TO.
|
Linear unit |
selection_type (Optional) |
Determines how the selection will be applied and what to do if a selection already exists.
- NEW_SELECTION —
The resulting selection replaces any existing selection. This is the default.
- ADD_TO_SELECTION —
The resulting selection is added to an existing selection if one exists. If no selection exists, this is the same as the NEW_SELECTION option.
- REMOVE_FROM_SELECTION —
The resulting selection is removed from an existing selection. If no selection exists, this option has no effect.
- SUBSET_SELECTION —
The resulting selection is combined with the existing selection. Only records that are common to both remain selected.
- SWITCH_SELECTION —
Switches the selection. All records that were selected are removed from the selection, and all records that were not selected are added to the selection. The Select Features and Overlap type will be ignored when this option is specified.
|
String |
Data types for geoprocessing tool parameters
Script example
# ExtactFeaturesByLocationAndAttribute.py
# Description: Extract features to a new feature class based on a Location and an attribute query
# Requirements: Python and the Python win32all extension
# Author: ESRI
# Data 1/1/2004
# Create the Geoprocessor
import arcgisscripting
gp = arcgisscripting.create()
# Put in error trapping in case an error occurs when running tool
try:
# Make a layer from the feature class
gp.MakeFeatureLayer("c:/mexico.mdb/cities", "cities_lyr")
gp.MakeFeatureLayer("c:/mexico.mdb/chihuahua", "chihuahua_lyr")
# Select all cities that overlap the chihuahua polygon
gp.SelectLayerByLocation("cities_lyr", "intersect", "chihuahua_lyr")
# Within the selection (done above) further select only those cities which have a population > 10,000
gp.SelectLayerByAttribute("cities_lyr", " [population] > 10000 ", "SUBSET_SELECTION")
# Write the selected features to a new feature class
gp.CopyFeatures("cities_lyr", "c:/mexico.mdb/chihuahua_10000plus")
except:
# If an error occurred, print the message to the screen
print gp.GetMessages()
Please visit the
Feedback page to comment or give suggestions on ArcGIS Desktop Help.
Copyright © Environmental Systems Research Institute, Inc.