You are here:
Geoprocessing tool reference
>
Data Management toolbox
>
Layers and Table Views toolset
>
Tools
Creates, updates, or removes a selection on the input layer based on spatial relationships to select features.
Usage tips
-
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 layer or table view, 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.
Command line syntax
Introducing geoprocessing methods—Using dialog boxes and the command line
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.
|
| {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.
- 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.
- COMPLETELY_CONTAINS—The features in the input layer will be selected if they completely contain a select feature. The select features must be polygons.
- COMPLETELY_WITHIN—The features in the input layer will be selected if they are completely within or contained by a select feature.
- HAVE_THEIR_CENTER_IN—The features in the input layer will be selected if their center falls within a select feature.
- 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.
- 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.
- ARE_IDENTICAL_TO—The features in the input layer will be selected if they are identical (in geometry) to a select feature.
- 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.
- 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.
- CONTAINED_BY—The features in the input layer will be selected if they are contained by a select feature. This is only valid when the select features are polygons.
|
| {select_features} |
The features in the input layer will be selected based on their spatial relationship to the features from this layer or feature class.
|
| {search_distance} |
If the Overlap Type is set to WITHIN_A_DISTANCE, set this parameter to the desired distance. If you choose a different Overlap Type, the Search Distance option lets you apply a buffer to the features in the input layer.
|
| {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.
- CLEAR_SELECTION—Clears or removes any selection. The Select Features and Overlap type will be ignored when this option is specified.
|
Command line example
SelectLayerByLocation wells_lyr have_their_center_in c:\gdb.mdb\kamsack_city_lim
Scripting syntax
Introducing geoprocessing methods—Running a script
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.
|
| overlap_type (Optional) |
The spatial relationship between the features in the input layer and the Select Layer on which the selection will be based.
- 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.
- COMPLETELY_CONTAINS—The features in the input layer will be selected if they completely contain a select feature. The select features must be polygons.
- COMPLETELY_WITHIN—The features in the input layer will be selected if they are completely within or contained by a select feature.
- HAVE_THEIR_CENTER_IN—The features in the input layer will be selected if their center falls within a select feature.
- 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.
- 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.
- ARE_IDENTICAL_TO—The features in the input layer will be selected if they are identical (in geometry) to a select feature.
- 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.
- 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.
- CONTAINED_BY—The features in the input layer will be selected if they are contained by a select feature. This is only valid when the select features are polygons.
|
| select_features (Optional) |
The features in the input layer will be selected based on their spatial relationship to the features from this layer or feature class.
|
| search_distance (Optional) |
If the Overlap Type is set to WITHIN_A_DISTANCE, set this parameter to the desired distance. If you choose a different Overlap Type, the Search Distance option lets you apply a buffer to the features in the input layer.
|
| 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.
- CLEAR_SELECTION—Clears or removes any selection. The Select Features and Overlap type will be ignored when this option is specified.
|
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 featureclass
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.