Spatial Join to a polyon with multiple lines

1789
4
Jump to solution
11-26-2020 04:34 AM
NoahLeimgruber
New Contributor III

Hi all!

I have polygons that contain multiple lines (Screenshot). How can I make a spatial join to the polygons so that it takes the attributes from the line that is longest in the polygon.

When I select the match option Intersect, it randomly choses a Line. I have also tried other options but so far I haven't found one that gives me the desired result.

 

Thank you in advance for your help!

 

Screenshot 2020-11-26 132437.jpg

0 Kudos
2 Solutions

Accepted Solutions
DavidPike
MVP Frequent Contributor

You can add the attributes of all intersecting lines to your polygon in the field mapping options of the spatial join.

psb excellent article on it.

Spatial Join’s hidden trick or how to transfer attribute values in a One to Many relationship | Esri...

 

you could of course script it, but I'd just to the spatial join, appending all the SHAPE_LENGTH s to a delimited field which would look like - 123.45, 45.56, 789.9...

you could then create a new field then do a field calculation, something selecting the largest value from yourfield.split(",")

 

edit - just read that you want the longest line WITHIN the polygon, I'd guess you'd have to clip all the lines to all the polygons, then split the lines again by the boundaries of the polygons (run a polygon to line I think for the split) and then do the join.

View solution in original post

0 Kudos
DavidPike
MVP Frequent Contributor

Sure, when you find the longest segment of a line within the polygon, it would have coincident geometry with the original line to match it back.

View solution in original post

0 Kudos
4 Replies
DavidPike
MVP Frequent Contributor

You can add the attributes of all intersecting lines to your polygon in the field mapping options of the spatial join.

psb excellent article on it.

Spatial Join’s hidden trick or how to transfer attribute values in a One to Many relationship | Esri...

 

you could of course script it, but I'd just to the spatial join, appending all the SHAPE_LENGTH s to a delimited field which would look like - 123.45, 45.56, 789.9...

you could then create a new field then do a field calculation, something selecting the largest value from yourfield.split(",")

 

edit - just read that you want the longest line WITHIN the polygon, I'd guess you'd have to clip all the lines to all the polygons, then split the lines again by the boundaries of the polygons (run a polygon to line I think for the split) and then do the join.

0 Kudos
NoahLeimgruber
New Contributor III

Thank you for your response!

I guess I expressed myself a bit wrong. The line does not necessarily have to be within the polygon as a whole. The join should simply select the line that interacts the longest with the polygon

0 Kudos
DavidPike
MVP Frequent Contributor

Sure, when you find the longest segment of a line within the polygon, it would have coincident geometry with the original line to match it back.

0 Kudos
NoahLeimgruber
New Contributor III

You're right. Then I'll try it the way you explained. Thank you very much!