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.
This solution is for line.
First of all I made 2 polygon feature classes and one line.
Then I used Near and made inputs as shown below.
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 )
-
Thank you very much! This is a very good idea, but unfortunately my line is not straight. That means, that the distance to the intial polygon is increasing but also decreasing in the course of the line! – Hannes Oct 25 '18 at 8:38
-
gis.stackexchange.com/questions/6476/… check this link, You have polyline not line. – JuniorPythonNewbie Oct 25 '18 at 8:50
-
Thanks, I found the solution here: gis.stackexchange.com/questions/124639/… Thanks for your help! – Hannes Oct 25 '18 at 8:54