Select Layer By Location (Data Management)—ArcGIS Pro (2024)

Parameters

LabelExplanationData Type

Input Features

The features that will be evaluated against the Selecting Features parameter values. The selection will be applied to these features.

Feature Layer; Raster Layer; Mosaic Layer

Relationship

(Optional)

Specifies the spatial relationship to be evaluated.

  • IntersectThe features in the input layer will be selected if they intersect a selecting feature. This is the default.
  • Intersect 3DThe features in the input layer will be selected if they intersect a selecting feature in three-dimensional space (x, y, and z).
  • Intersect (DBMS)The features in the input layer will be selected if they intersect a selecting feature. This option applies to enterprise geodatabases only. The selection will be processed in the enterprise geodatabase DBMS rather than on the client when all requirements are met (see more information in the usage notes). This option may provide better performance than performing the selection on the client.
  • Within a distanceThe features in the input layer will be selected if they are within the specified distance (using Euclidean distance) of a selecting feature. Use the Search Distance parameter to specify the distance.
  • Within a distance geodesicThe features in the input layer will be selected if they are within a specified distance of a selecting feature. Distance between features will be calculated using a geodesic formula that takes into account the curvature of the spheroid and correctly handles data near and across the dateline and poles. Use the Search Distance parameter to specify the distance.
  • Within a distance 3DThe features in the input layer will be selected if they are within a specified distance of a selecting feature in three-dimensional space. Use the Search Distance parameter to specify the distance.
  • ContainsThe features in the input layer will be selected if they contain a selecting feature.
  • Completely containsThe features in the input layer will be selected if they completely contain a selecting feature.
  • Contains ClementiniThis spatial relationship yields the same results as Contains with the exception that if the selecting feature is entirely on the boundary of the input feature (no part is properly inside or outside), the feature will not be selected. Clementini defines the boundary polygon as the line separating inside and outside, the boundary of a line is defined as its end points, and the boundary of a point is always empty.
  • WithinThe features in the input layer will be selected if they are within a selecting feature.
  • Completely withinThe features in the input layer will be selected if they are completely within or contained by a selecting feature.
  • Within ClementiniThe result will be identical to Within with the exception that if the entirety of the feature in the input layer is on the boundary of the feature in the selecting layer, the feature will not be selected. Clementini defines the boundary polygon as the line separating inside and outside, the boundary of a line is defined as its end points, and the boundary of a point is always empty.
  • Are identical toThe features in the input layer will be selected if they are identical (in geometry) to a selecting feature.
  • Boundary touchesThe features in the input layer will be selected if they have a boundary that touches a selecting feature. When the input features are lines or polygons, the boundary of the input feature can only touch the boundary of the selecting feature, and no part of the input feature can cross the boundary of the selecting feature.
  • Share a line segment withThe features in the input layer will be selected if they share a line segment with a selecting feature. The input and selecting features must be line or polygon.
  • Crossed by the outline ofThe features in the input layer will be selected if they are crossed by the outline of a selecting feature. The input and selecting features must be lines or polygons. If polygons are used for the input or selecting layer, the polygon's boundary (line) will be used. Lines that cross at a point will be selected; lines that share a line segment will not be selected.
  • Have their center inThe features in the input layer will be selected if their center falls within a selecting 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.
String

Selecting Features

(Optional)

The features in the Input Features parameter will be selected based on their relationship to the features from this layer or feature class.

Feature Layer

Search Distance

(Optional)

The distance that will be searched. This parameter is only valid if the Relationship parameter is set to Within a distance, Within a distance geodesic, Within a distance 3D, Intersect, Intersect 3D, Have their center in, or Contains.

If the Within a distance geodesic option is selected, use a linear unit such as kilometers or miles.

Linear Unit

Selection Type

(Optional)

Specifies how the selection will be applied to the input and how it will be combined with an existing selection. This tool does not include an option to clear an existing selection; use the Clear the current selection option on the Select Layer By Attribute tool to do that.

  • New selectionThe resulting selection will replace any existing selection. This is the default.
  • Add to the current selectionThe resulting selection will be added to an existing selection. If no selection exists, this is the same as the New selection option.
  • Remove from the current selectionThe resulting selection will be removed from an existing selection. If no selection exists, the operation will have no effect.
  • Select subset from the current selectionThe resulting selection will be combined with the existing selection. Only records that are common to both remain selected.
  • Switch the current selectionThe selection will be switched. All records that were selected will be removed from the selection, and all records that were not selected will be added to the selection. The Selecting Features and Relationship parameters are ignored when this option is selected.
String

Invert Spatial Relationship

(Optional)

Specifies whether the spatial relationship evaluation result or the opposite result will be used. For example, this parameter can be used to get a list of features that do not intersect or are not within a given distance of features in another dataset.

  • Unchecked—The query result will be used. This is the default.
  • Checked—The opposite of the query result will be used. If the Selection Type parameter is used, the reversal of the selection occurs before it is combined with existing selections.
Boolean

Derived Output

LabelExplanationData Type
Layer With Selection

The updated inputs with selections applied.

Feature Layer; Mosaic Layer
Output Layer Names

The names of the updated inputs.

Feature Layer; Mosaic Layer
Count

The number of selected records.

Long
arcpy.management.SelectLayerByLocation(in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type}, {invert_spatial_relationship})
NameExplanationData Type

in_layer

[in_layer,...]

The features that will be evaluated against the select_features parameter values. The selection will be applied to these features.

Feature Layer; Raster Layer; Mosaic Layer

overlap_type

(Optional)

Specifies the spatial relationship to be evaluated.

  • INTERSECTThe features in the input layer will be selected if they intersect a selecting feature. This is the default.
  • INTERSECT_3DThe features in the input layer will be selected if they intersect a selecting feature in three-dimensional space (x, y, and z).
  • INTERSECT_DBMSThe features in the input layer will be selected if they intersect a selecting feature. This option applies to enterprise geodatabases only. The selection will be processed in the enterprise geodatabase DBMS rather than on the client when all requirements are met (see usage notes). This option may provide better performance than performing the selection on the client.
  • WITHIN_A_DISTANCEThe features in the input layer will be selected if they are within the specified distance (using Euclidean distance) of a selecting feature. Use the search_distance parameter to specify the distance.
  • WITHIN_A_DISTANCE_3DThe features in the input layer will be selected if they are within a specified distance of a selecting feature in three-dimensional space. Use the search_distance parameter to specify the distance.
  • WITHIN_A_DISTANCE_GEODESICThe features in the input layer will be selected if they are within a specified distance of a selecting feature. Distance between features will be calculated using a geodesic formula that takes into account the curvature of the spheroid and correctly handles data near and across the dateline and poles. Use the search_distance parameter to specify the distance.
  • CONTAINSThe features in the input layer will be selected if they contain a selecting feature.
  • COMPLETELY_CONTAINSThe features in the input layer will be selected if they completely contain a selecting feature.
  • CONTAINS_CLEMENTINIThis spatial relationship yields the same results as CONTAINS with the exception that if the selecting feature is entirely on the boundary of the input feature (no part is properly inside or outside), the feature will not be selected. Clementini defines the boundary polygon as the line separating inside and outside, the boundary of a line is defined as its end points, and the boundary of a point is always empty.
  • WITHINThe features in the input layer will be selected if they are within a selecting feature.
  • COMPLETELY_WITHINThe features in the input layer will be selected if they are completely within or contained by a selecting feature.
  • WITHIN_CLEMENTINIThe result will be identical to WITHIN with the exception that if the entirety of the feature in the input layer is on the boundary of the feature in the selecting layer, the feature will not be selected. Clementini defines the boundary polygon as the line separating inside and outside, the boundary of a line is defined as its end points, and the boundary of a point is always empty.
  • ARE_IDENTICAL_TOThe features in the input layer will be selected if they are identical (in geometry) to a selecting feature.
  • BOUNDARY_TOUCHESThe features in the input layer will be selected if they have a boundary that touches a selecting feature. When the input features are lines or polygons, the boundary of the input feature can only touch the boundary of the selecting feature, and no part of the input feature can cross the boundary of the selecting feature.
  • SHARE_A_LINE_SEGMENT_WITHThe features in the input layer will be selected if they share a line segment with a selecting feature. The input and selecting features must be line or polygon.
  • CROSSED_BY_THE_OUTLINE_OFThe features in the input layer will be selected if they are crossed by the outline of a selecting feature. The input and selecting features must be lines or polygons. If polygons are used for the input or selecting layer, the polygon's boundary (line) will be used. Lines that cross at a point will be selected; lines that share a line segment will not be selected.
  • HAVE_THEIR_CENTER_INThe features in the input layer will be selected if their center falls within a selecting 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.
String

select_features

(Optional)

The features in the Input Features parameter will be selected based on their relationship to the features from this layer or feature class.

Feature Layer

search_distance

(Optional)

The distance that will be searched. This parameter is only valid if the overlap_type parameter is set to WITHIN_A_DISTANCE, WITHIN_A_DISTANCE_GEODESIC, WITHIN_A_DISTANCE_3D, INTERSECT, INTERSECT_3D, HAVE_THEIR_CENTER_IN, or CONTAINS.

If the WITHIN_A_DISTANCE_GEODESIC option is selected, use a linear unit such as kilometers or miles.

Linear Unit

selection_type

(Optional)

Specifies how the selection will be applied to the input and how it will be combined with an existing selection. This tool does not include an option to clear an existing selection; use the CLEAR_SELECTION option on the Select Layer By Attribute tool to do that.

  • NEW_SELECTIONThe resulting selection will replace any existing selection. This is the default.
  • ADD_TO_SELECTIONThe resulting selection will be added to an existing selection. If no selection exists, this is the same as the NEW_SELECTION option.
  • REMOVE_FROM_SELECTIONThe resulting selection will be removed from an existing selection. If no selection exists, the operation will have no effect.
  • SUBSET_SELECTIONThe resulting selection will be combined with the existing selection. Only records that are common to both remain selected.
  • SWITCH_SELECTIONThe selection will be switched. All records that were selected will be removed from the selection, and all records that were not selected will be added to the selection. The select_features and overlap_type parameters are ignored when this option is selected.
String

invert_spatial_relationship

(Optional)

Specifies whether the spatial relationship evaluation result or the opposite result will be used. For example, this parameter can be used to get a list of features that do not intersect or are not within a given distance of features in another dataset.

  • NOT_INVERTThe query result will be used. This is the default.
  • INVERTThe opposite of the query result will be used. If the selection_type parameter is used, the reversal of the selection occurs before it is combined with existing selections.
Boolean

Derived Output

NameExplanationData Type
out_layer_or_view

The updated inputs with selections applied.

Feature Layer; Mosaic Layer
out_layers_or_views

The names of the updated inputs.

Feature Layer; Mosaic Layer
count

The number of selected records.

Long

Code sample

SelectLayerByLocation example 1 (Python window)

The following Python window script demonstrates how to use the SelectLayerByLocation function in immediate mode.

import arcpyarcpy.SelectLayerByLocation_management("parcel_lyr", "have_their_center_in", "c:/kamsack.gdb/city_limits")
SelectLayerByLocation example 2 (stand-alone script)

The following stand-alone script shows how to use the SelectLayerByLocation function in a workflow to extract features to a new feature class based on location and an attribute query.

# Description: Extract features to a new feature class based on a # location and an attribute query# Import arcpy and set path to dataimport arcpyarcpy.env.workspace = "c:/data/mexico.gdb"# Make a layer and select cities that overlap the chihuahua polygonchihuahua_cities = arcpy.SelectLayerByLocation_management('cities', 'INTERSECT', 'chihuahua')# From the previous selection, select a subset of cities that have # population > 10,000arcpy.SelectLayerByAttribute_management(chihuahua_cities, 'SUBSET_SELECTION', '"population" > 10000')# If features matched criteria, write them to a new feature classmatchcount = int(arcpy.GetCount_management(chihuahua_cities)[0]) if matchcount == 0: print('no features matched spatial and attribute criteria')else: arcpy.CopyFeatures_management(chihuahua_cities, 'chihuahua_10000plus') print('{0} cities that matched criteria written to {0}'.format( matchcount, chihuahua_10000plus))
SelectLayerByLocation example 3 (stand-alone script)

The following stand-alone script shows a variety of uses of the overlap_type parameter's WITHIN_A_DISTANCE and WITHIN_A_DISTANCE_GEODESIC options with the search_distance parameter.

# Description: Select features within a distance# Import arcpy and set path to dataimport arcpyarcpy.env.workspace = r"c:\data\mexico.gdb"arcpy.SelectLayerByLocation_management('cities', 'WITHIN_A_DISTANCE', 'chihuahua', '1.5 Miles')arcpy.SelectLayerByLocation_management('cities', 'WITHIN_A_DISTANCE_GEODESIC', 'chihuahua', '200 Kilometers')# When using WITHIN_A_DISTANCE, if distance units are not specified, the # distance value is assumed to be in the units of the input dataset's coordinate # systemarcpy.SelectLayerByLocation_management('cities', 'WITHIN_A_DISTANCE', 'chihuahua', '200')# When using WITHIN_A_DISTANCE_GEODESIC, if distance units are not specified, # the distance value is assumed to be in metersarcpy.SelectLayerByLocation_management('cities', 'WITHIN_A_DISTANCE_GEODESIC', 'chihuahua', '200')
Select Layer By Location (Data Management)—ArcGIS Pro (2024)
Top Articles
Latest Posts
Article information

Author: Amb. Frankie Simonis

Last Updated:

Views: 5917

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Amb. Frankie Simonis

Birthday: 1998-02-19

Address: 64841 Delmar Isle, North Wiley, OR 74073

Phone: +17844167847676

Job: Forward IT Agent

Hobby: LARPing, Kitesurfing, Sewing, Digital arts, Sand art, Gardening, Dance

Introduction: My name is Amb. Frankie Simonis, I am a hilarious, enchanting, energetic, cooperative, innocent, cute, joyous person who loves writing and wants to share my knowledge and understanding with you.