For the longest part in a multipart polyline, use the line/part's midpoint to get the ID of the closest polygon

05-24-2022 02:29 PM
Regular Contributor II

I have a multi-part road polyline FC. For the longest part of a given polyline, I want to use the line/part's midpoint to get the WARD_ID of the closest polygon (single-part polygon FC).

  • The WARD polygons aren't topologically clean. There are slight overlaps and gaps. So that's why I want to get the closest polygon -- within a 30m tolerance.

Is there a way to do that operation with geoprocessing tools? 

License level = Advanced.


0 Kudos
4 Replies
MVP Regular Contributor
  • Explode the multipart features
  • Calculate a new field that tells you whether a singlepart line is the longest part of a multipart feature
var id = $feature.ORIG_FID
var fs = $featureset
var all_line_parts = Filter(fs, "ORIG_FID = @ID")
if($feature.Shape_Length == Max(all_line_parts, "Shape_Length")) {
    return 1
return 0


  • select and delete all exploded lines where "LongestLine = 0"


  • Calculate the central point coordinates
    • This is not actually the midpoint.  This is what the tool help says:
    • "This point is the same as the centroid if the centroid is inside the feature, otherwise it is an inner label point."
    • But it's probably the best you're going to get without pretty large code blocks...JohannesLindner_3-1653460466851.png


  • Convert to points
  • export to actual point feature class
  • Find nearby polygon features

  •  Join MidPoints to the original Line FC using "OBJECTID = ORIG_FID"


  • Add the polygons to that join, using "MidPoints.NEAR_FID = OBJECTID"
  • Calculate the PolygonID field
  • Remove all joins




Have a great day!
by Esri Regular Contributor
Esri Regular Contributor

Just want to mention some alternative tools to use:

1.  To get the longest part among the singleparts with the same ORIG_FID, you can use Summary Statistics with MAXIMUM option on Shape_Length, using ORIG_FID as the Case FIeld. Then Add Join back to the singlepart features via ORIG_FID.

2. Once the longest parts have been identified, you can use Feature Vertices To Point with "Midpoint" option to get the midpoints.

As you mentioned the overlaps and gaps, when a midpoint falls inside multiple (overlapping) polygons, Near may return the FID for one of them.  Are you concerned about that?

I am curious about why the roads are in multipart to begin with and why you need to know the closest Ward polygons to each midpoint of the longest part.  Would you mind giving a brief explanation on the real story with some screenshots if possible?  Thanks.  - Dan

0 Kudos
Regular Contributor II

Thanks Dan. Regarding your question, "Why are the roads multipart to begin with?"


Some of the roads are multi-part due to situations like this:

The road's "Exclusive Right Turn" lane was deemed to be too short to be it's own asset. So it was merged into it's parent asset as a multipart feature: 


(Here's an example photo, although not the same one from the screenshot above:

That decision was made years ago by people other than me and is beyond my control. (It's not possible to change things at this point...there are too many existing dependencies. Splitting the multipart into two single parts would compromise any records that are related. Including an already-integrated work order management system.)


The other scenario is:
Multipart features were created by accident. The person who digitized the roads merged two lines together, but didn't realize that a multipart feature was created. 


In that case, it might be possible to go back and convert the multiparts to single parts. But it would take a lot of work to review/fix any linear referencing events that are tied to the geometry/M-values of those roads.


I've submitted an idea about multiparts here: Prevent multi-part features.


Does that answer your first question?

I'll answer your second question about "Why you need to know the closest Ward polygons to each midpoint of the longest part?" in a separate comment. Cheers.



0 Kudos
by Esri Regular Contributor
Esri Regular Contributor

Thank you Bud for explaining the two scenarios for multipart features to be created.

For the mistakenly created multipart features, if you can select them by some attributes without selecting those "sliparound lanes", then you can run Multipart To Singlepart to make them singlepart, each carries ORIG_FID, followed by Unsplit Line using the ORIG_FID as the Dissolve Field to merge them without being multipart. Hopefully you can use the ORIG_FID to join with original features to transfer any lost attributes.  It may be a hassle but necessary.

0 Kudos