I have 2 separate feature classes, line and point. I want to select line feature class based on the location of points on a point feature class. If the points are on the line itself then I don't want to select the line. But, if they are at its end/start, the line should be selected.
I suggest these steps to Select Lines that Intersect another Point FC only at Line End Points.
Export the Line endpoints to a Point featureclass (named Line_endpoints) - "Feature Vertices to Points", select Point type = "END".
Select By Location, Line_endpoints with Point_FC, Intersect. You can add a small Search Tolerance if needed (if Points don't match exactly)
Select By Location, Line FC with Line_endpoints, Intersect, click Use Select features
If I understand your question correctly, you can solve this by using
arcpy.da.SearchCursor on your point feature class and load the point geometry into a list. In a
arcpy.da.SearchCursor the geometry object can be accessed via the
SHAPE@ token. Something like this:
point_feature_class = r'C:\path_to_data\points.shp' points =  with arcpy.da.SearchCursor(point_feature_class, "SHAPE@") as s_cur: for row in s_cur: points.append(row)
Then you can again use an
arcpy.da.SearchCursor to loop over the line features and compare the first and last points of the lines to the points within the list you created above. Something like this:
line_feature_class = r'C:\path_to_data\lines.shp' lines_to_select =  with arcpy.da.SearchCursor(line_feature_class, ['OID@', 'SHAPE@"]) as s_cur: for row in s_cur: first_point = row.firstPoint last_point = row.lastPoint for pt in points: if pt == first_point or pt == last_point: lines_to_select.append(row)
This will give you a list of OID of lines that have points from the point feature class that are either the first or last point. You can then use the OID values within your list in many or one complex
This is off the top of my head and is a fairly roundabout way to get this done, but it should get the job done and/or get you going in the right direction. One note about this method is because you are comparing geometries, you need to make sure that that both feature classes have or don't have
M values. If one does and the other does not then this process should be modified to just compare the
XY values either through straight comparisons or creating new more simple point geometries of just
XY. There is certainly room for improvements and simplifications of this process.
This is what @klewis suggesting:
arcpy.FeatureVerticesToPoints_management("LINES", "D:/Scratch/ends.shp", " BOTH_ENDS ") arcpy.SelectLayerByLocation_management("ends", "INTERSECT", "POINTS") arcpy.SelectLayerByAttribute_management("ends", "SWITCH_SELECTION") arcpy.DeleteFeatures_management(in_features="ends") arcpy.AddJoin_management("LINES", "FID", "ends", "ORIG_FID", "KEEP_ALL") arcpy.SelectLayerByAttribute_management("LINES", "NEW_SELECTION", """"ends.ORIG_FID" IS NOT NULL""")