I have a polygon feature class which contains many (9952) polygons, some of which overlap each other. I have another point feature class with many points (15998) and one of the fields is called route_number.
What I need to do is for every polygon in the polygon feature class, I need to select the points which intersect it. Then with these selected points I need to find the number of unique values for route_number. For example I can do this in ArcGIS Pro by selecting one polygon feature in the attribute table and then running the "Select Layer By Location" tool. It successfully selects just the points which intersect the polygon.
How do I do this in Python using ArcPy?
I have the following code to do a Select by location however it selects every point in the points feature class. I think this is because the select_features is the whole polygon feature class (polygons). I want this to be just one feature within the polygons feature class.
selection = arcpy.SelectLayerByLocation_management(in_layer='point_fc',overlap_type='INTERSECT',select_features='polygon_fc')
print(selection)
num_points = int(arcpy.GetCount_management(selection)[0])
print(num_points)