Select Layer By Location (Data Management)—ArcMap (2024)

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

Selects features in a layer based on a spatial relationship to features in another layer.

Each feature in the Input Feature Layer is evaluated against the features in the Selecting Features layer or feature class; if the specified Relationship is met, the input feature is selected.

Graphic examples of relationships

Usage

  • The input must be a feature layer; it cannot be a feature class.

  • This tool works on layers in ArcMap, ArcGlobe, or ArcScene and also on layers created in models and scripts using the Make Feature Layer tool.

  • The coordinate system in which the spatial relationship is evaluated may affect the result. Features that intersect in one coordinate system may or may not intersect in another.

    • This tool evaluates a spatial relationship in the coordinate system of the Input Feature Layer data source (the feature class on disk). Set the output coordinate system environment to evaluate the spatial relationship in a different coordinate system.
  • This tool can be used to select features based on their spatial relationships to other features within the same layer. For some examples, see Select by location within a layer.

  • The Get Count tool can be used to find the number of features selected by the Select Layer By Location tool. This can be useful for determining if any features matched the desired spatial relationship before proceeding to further analysis as part of an automated workflow (that is, script or model).

  • For more information about using the three-dimensional spatial relationships INTERSECT_3D and WITHIN_A_DISTANCE_3D, see Select by location 3D relationships.

Syntax

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

in_layer

The layer containing the features that will be evaluated against the select_features. The selection will be applied to this layer. The input cannot be the path to a feature class on disk.

Feature Layer; Mosaic Layer; Raster Catalog Layer

overlap_type

(Optional)

The spatial relationship to be evaluated.

  • INTERSECT —The features in the input layer will be selected if they intersect a selecting feature. This is the default.
  • INTERSECT_3D —The features in the input layer will be selected if they intersect a selecting feature in three-dimensional space (x, y, and z).
  • WITHIN_A_DISTANCE —The features in the input layer will be selected if they are within a specified distance of a selecting feature. Specify a distance in the Search Distance parameter.
  • WITHIN_A_DISTANCE_3D —The features in the input layer will be selected if they are within a specified distance of a selecting feature in three-dimensional space. Specify a distance in the Search Distance parameter.
  • WITHIN_A_DISTANCE_GEODESIC —The 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 method which takes into account the curvature of the earth and correctly deals with data near and across the dateline and poles.
  • CONTAINS —The features in the input layer will be selected if they contain a selecting feature.
  • COMPLETELY_CONTAINS —The features in the input layer will be selected if they completely contain a selecting feature.
  • CONTAINS_CLEMENTINI —This spatial relationship yields the same results as COMPLETELY_CONTAINS with the following exception: 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.
  • WITHIN —The features in the input layer will be selected if they are within a selecting feature.
  • COMPLETELY_WITHIN —The features in the input layer will be selected if they are completely within or contained by a selecting feature.
  • WITHIN_CLEMENTINI —The 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_TO —The features in the input layer will be selected if they are identical (in geometry) to a selecting feature.
  • BOUNDARY_TOUCHES —The features in the input layer will be selected if they have a boundary that touches a selecting feature. When the inputs 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_WITH —The 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_OF —The 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, 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 selecting feature. The center of the feature is calculated as follows: for polygon and multipoint, the geometry's centroid is used, and for line input, the geometry's midpoint is used.
String

select_features

(Optional)

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

Feature Layer

search_distance

(Optional)

This parameter is only valid if the overlap_type parameter is set to one of the following: WITHIN_A_DISTANCE_GEODESIC, WITHIN_A_DISTANCE, WITHIN_A_DISTANCE_3D, INTERSECT, INTERSECT_3D, HAVE_THEIR_CENTER_IN, CONTAINS, or WITHIN.

If the WITHIN_A_DISTANCE_GEODESIC option is used, a linear unit such as Kilometers or Miles should be used.

Linear unit

selection_type

(Optional)

Determines how the selection will be applied to the input and how to combine with an existing selection. Note that there is no option here to clear an existing selection. To clear a selection, use the CLEAR_SELECTION option on the Select Layer By Attribute tool.

  • 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, the operation will have 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 parameters are ignored when this option is selected.
String

invert_spatial_relationship

(Optional)

After the spatial relationship is evaluated, this option determines if the result should be used as is, or inverted. For example, this option can be used to quickly get a list of features that do not intersect or are not within a distance of features in another dataset.

  • NOT_INVERT —The result of the query will not be inverted. This is the default.
  • INVERT —The result of the query will be inverted. If a selection_type option is used, the inversion occurs before the selection is combined with existing selections.
Boolean

Derived Output

NameExplanationData Type
out_layer_or_view

The updated input with selection applied.

Feature Layer; Raster Catalog Layer; Mosaic Layer

Code sample

SelectLayerByLocation example 1 (Python window)

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

import arcpy# First, make a layer from the feature classarcpy.MakeFeatureLayer_management("c:/kamsack.gdb/parcel", "parcel_lyr")# Then add a selection to the layer based on location to features in another feature class arcpy.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.

# Name: ExtactFeaturesByLocationAndAttribute.py# 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 which overlap the chihuahua polygonarcpy.MakeFeatureLayer_management('cities', 'cities_lyr') arcpy.SelectLayerByLocation_management('cities_lyr', 'intersect', 'chihuahua') # Within the previous selection sub-select cities which have population > 10,000arcpy.SelectLayerByAttribute_management('cities_lyr', 'SUBSET_SELECTION', '"population" > 10000')# If features matched criteria write them to a new feature classmatchcount = int(arcpy.GetCount_management('cities_lyr')[0]) if matchcount == 0: print('no features matched spatial and attribute criteria')else: arcpy.CopyFeatures_management('cities_lyr', 'chihuahua_10000plus') print('{0} cities that matched criteria written to {0}'.format( matchcount, chihuahua_10000plus))

Environments

  • Current Workspace
  • Output Coordinate System

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics

  • An overview of the Layers and Table Views toolset
  • Using layers and table views
  • Working with layers and table views
  • Creating and using layer selections
  • Using Select by Location (ArcMap dialog)
Select Layer By Location (Data Management)—ArcMap (2024)
Top Articles
Latest Posts
Article information

Author: Nathanael Baumbach

Last Updated:

Views: 5915

Rating: 4.4 / 5 (55 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Nathanael Baumbach

Birthday: 1998-12-02

Address: Apt. 829 751 Glover View, West Orlando, IN 22436

Phone: +901025288581

Job: Internal IT Coordinator

Hobby: Gunsmithing, Motor sports, Flying, Skiing, Hooping, Lego building, Ice skating

Introduction: My name is Nathanael Baumbach, I am a fantastic, nice, victorious, brave, healthy, cute, glorious person who loves writing and wants to share my knowledge and understanding with you.