1

This question already has an answer here:

I have two layers. One with small Polygons and one with a line. I want to select all Polygons which intersect with the line. Additionally the selected Polygons should be sorted by the order of the line, as a line has always a start and a end. The first polygon that intersects at the start of the line should be on top of the attribute table. The second one on second place and so on.

marked as duplicate by PolyGeo Oct 26 '18 at 8:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

This solution is for line.

First of all I made 2 polygon feature classes and one line. enter image description here

Then I used Near and made inputs as shown below.

enter image description here

When you have distance from green polygon (poly2) to all others you can make Select by Location to select only polygons intersecting the line. Then just export selection and you will have only those which are on the line plus you will be able to sort them by distance from polygon which is near the beginning of the line.

Below you got sample code for this remember to change: gdb location, in_features, near_features, line_fc and output_name to your preferences.

import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"**GDB LOCATION**"
in_features = 'poly'
near_features = 'poly2'
line_fc = 'line'
output_name =  "poly_Intersect"

arcpy.Near_analysis(in_features, near_features)
arcpy.MakeFeatureLayer_management(in_features, 'poly_lyr')
arcpy.SelectLayerByLocation_management('poly_lyr', 'intersect', line_fc)
arcpy.CopyFeatures_management('poly_lyr', output_name )

Not the answer you're looking for? Browse other questions tagged or ask your own question.