Table of Contents
The Video
Introduction
This problem was posed on Reddit.
“Right now I have map of store locations with a 1 mile buffer around them. Is there a way for me to only select the stores that intersect with 2 or more buffers?”
Let’s take a look at a solution using ArcPy.
Leverage ArcPy for geospatial data management workflows within ArcGIS Pro. Learn the fundamentals of utilising ArcGIS Pro geoprocessing tools with ArcPy for data management, conversions, and analysis. This course is packed with amazing content that will help you discover the power of automating tasks within the ArcGIS Pro environment. Take your ArcPy skills from beginner to snake charmer. A little code goes a long way, a little ArcPy provides you with an in-demand skill. Sign up now for our highly rated course.
Custom Tool Syntax
The syntax for the Select Points that Intersect Multiple Polygons tool is as follows…
selectPointsMultipleIntersects(
point_fc,
polygon_fc,
num_or_more
)
All parameters are required. The point_fc is a Feature Layer input, the polygon_fc is also a Feature Layer input, and the num_or_more is the minimum number of intersections for a point to be selected.
Import the neccessary module
ArcPy is a Python site package that enables automation, analysis, and management of geographic data within the ArcGIS software environment. We also import the Counter class from the collections module which is a part of the standard Python library, this will help us count the intersections.
import arcpy
from collections import Counter
Define the parameters
## the input points feature class
point_fc = arcpy.GetParameterAsText(0)
## the input polygon feature class
polygon_fc = arcpy.GetParameterAsText(1)
## the points must intersect this amount of polygons
num_or_more = arcpy.GetParameterAsText(2)
Required Python object for the tool
Just the one, we want the OID field name for the Point Feature Layer. This will be used to perform the selection.
## oid field for the point feature class
oid_field = [fld.name for fld in arcpy.ListFields(point_fc) if fld.type == "OID"][0]
Pairwise Intersect
Now we call the big dawg! The Pairwise Intersect tool and we place the output feature class into the memory workspace. The output will give use a field called FID_{the_name_of_the_point_layer}, from which we will grab the interscting OIDs – of which there will be multiples if multiple intersects.
## use the Analysis toolbox Pairwise Interset geoprocessing tool.
## use the memorey workspace.
intersect_fc = arcpy.analysis.PairwiseIntersect(
in_features = [point_fc, polygon_fc],
out_feature_class = "memory/intersect_fc",
join_attributes="ONLY_FID",
cluster_tolerance=None,
output_type="POINT"
)
Get the OIDs for Selection
The FID_{the_name_of_the_point_layer} field should sit at index 2, but you could finesse here to get the exact field name. For now, I’ll stick with indexing from all the fields.
Counter creates a dictionary with the OID number and the number of intersections.
We can then get a set of OIDs with X number or more intersections.
## all OIDs that intersected polygons
oid_list = [row[2] for row in arcpy.da.SearchCursor(intersect_fc, "*")]
## count multiple
counts = Counter(oid_list)
## if the count of the individual OID is equal to or greater than required
selection_oids = {oid for oid in oid_list if counts[oid] >= int(num_or_more)}
Perform the Selection in the Map
If there were OIDs found that met the number threshold then they will be selected in the map, otherwise a warning will state that “No point met the criteria”.
if selection_oids:
## craete a where clause
sql_exp = "{0} IN ({1})".format(oid_field, ",".join([str(oid) for oid in selection_oids]))
## select by attribute using where clause
arcpy.management.SelectLayerByAttribute(
in_layer_or_view=point_fc,
selection_type="NEW_SELECTION",
where_clause=sql_exp
)
else:
arcpy.AddWarning("No point met the criteria")
Cleanup the memory workspace.
The script ending should be enough to clear the memory but it can be good practice to clear it yourself.
arcpy.management.Delete(intersect_fc)
Mastering ArcGIS Pro ArcPy Search, Insert, & Update Cursors
Unlock the full potential of ArcPy Cursors with our intensive and in-depth course. Designed for GIS professionals, analysts, and enthusiasts, this course delves into the intricacies of Search, Insert, and Update Cursors in the ArcPy library, empowering you to manipulate and manage spatial data with precision and efficiency.
ArcPy Cursors enable you to streamline your GIS workflows, automate repetitive tasks, and witness the full potential of spatial data manipulation in ArcGIS Pro.
Create the tool in ArcGIS Pro
That didn’t take much code now did it? A lot of code is made up with comments. Save your script and let’s head over to ArcGIS Pro to create our custom tool for use.
Right-click on your toolbox/toolset of choice and select New > Script. The New Script window will appear. In the General tab set Name to selectPointsMultipleIntersects, Label to Select Points that Intersect Multiple Polygons, and the Description to This tool selects features from a point layer that intersects a user-defined number of polygons from another layer.

In the Parameters tab set as per below. Set the Input Point Layer with a Data Type of Feature Layer, use the Filter to restrict Feature Type to Point. Set the Input Polygon Layer with a Data Type of Feature Layer, use the Filter to restrict Feature Type to Polygon. Set the Point Intersects This Number of Polygons or More with a Data Type of Long.

In the Execution tab, click the folder icon in the top-right corner and ad your saved Python script.
Click OK and go test out the tool!
All the code in one place
You can find the entire code workflow below with links to important components in the documentation that were used.
import arcpy
from collections import Counter
################################################################################
## Esri Documentation
## https://pro.arcgis.com/en/pro-app/latest/tool-reference/analysis/pairwise-intersect.htm
## https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/getparameterastext.htm
## https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfields.htm
## https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm
## https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/select-layer-by-attribute.htm
## https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/delete.htm
## https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/basics/the-in-memory-workspace.htm
################################################################################
################################################################################
## USER INPUT ##################################################################
## the input points feature class
point_fc = arcpy.GetParameterAsText(0)
## the input polygon feature class
polygon_fc = arcpy.GetParameterAsText(1)
## the points must intersect this amount of polygons
num_or_more = arcpy.GetParameterAsText(2)
################################################################################
## REQUIRED OBJECTS ############################################################
## oid field for the point feature class
oid_field = [fld.name for fld in arcpy.ListFields(point_fc) if fld.type == "OID"][0]
################################################################################
## PERFORM THE INTERSECTION ####################################################
## use the Analysis toolbox Pairwise Interset geoprocessing tool.
## use the memorey workspace.
intersect_fc = arcpy.analysis.PairwiseIntersect(
in_features = [point_fc, polygon_fc],
out_feature_class = "memory/intersect_fc",
join_attributes="ONLY_FID",
cluster_tolerance=None,
output_type="POINT"
)
################################################################################
## GET OIDS FOR SELECTION ######################################################
## all OIDs that intersected polygons
oid_list = [row[2] for row in arcpy.da.SearchCursor(intersect_fc, "*")]
## count multiple
counts = Counter(oid_list)
## if the count of the individual OID is equal to or greater than required
selection_oids = {oid for oid in oid_list if counts[oid] >= int(num_or_more)}
################################################################################
## SELECT FEATURES IN THE MAP ##################################################
if selection_oids:
## craete a where clause
sql_exp = "{0} IN ({1})".format(oid_field, ",".join([str(oid) for oid in selection_oids]))
## select by attribute using where clause
arcpy.management.SelectLayerByAttribute(
in_layer_or_view=point_fc,
selection_type="NEW_SELECTION",
where_clause=sql_exp
)
else:
arcpy.AddWarning("No point met the criteria")
################################################################################
## MEMORY CLEANUP ##############################################################
arcpy.management.Delete(intersect_fc)
################################################################################