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).
Is there a way to do that operation with geoprocessing tools?
License level = Advanced.
Thanks.
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
Find nearby polygon features
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
Thanks Dan. Regarding your question, "Why are the roads multipart to begin with?"
Answer:
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: https://i.stack.imgur.com/aiL7W.png)
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.
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.
Just FYI, as a post-editing option, you can use Calculate Geometry Attributes to calculate "Part Count" to a field. Any feature getting a value greater than 1 would be a multipart feature.
I look forward to your description on "Why you need to know the closest Ward polygons to each midpoint of the longest part?", Bud. 🙂
Question:
"Why you need to know the closest Ward polygons to each midpoint of the longest part?"
Answer:
I want to be able to control what part of a given multi-part line was used to get the Ward number.
In some cases, simply using the midpoint of the entire line might work. Maybe the midpoint would have still fallen on the main part of the road, and within the correct ward. But I didn't want to assume that it would always work like that. And with GP tools like Feature Vertices To Points, it actually creates a midpoint for each part, not a single midpoint for the entire line. That's not what I want. So when I saw that behavior, I got a bit nervous and wanted to find a way to completely control how things behaved.
Does that answer your question?
(Side note: I don't have control over the Ward layer/topological correctness.)
Thanks! I understand now.
Feature Vertices To Points generates MID point per part for a reason. Parts may not be connected in one feature. So it doesn't make sense to find midpoint among disconnected parts.
You can try Feature To Point with the "Inside" option. It generates one point per feature on one of the parts.
As you suggested, Feature To Point with the "Inside" option worked well thanks.
It seems to have placed the midpoint along the entire length of the line (all parts considered), which is what I wanted. It didn't just use the midpoint of a single part...such as the the first part it found (good).
(The line in the screenshot is composed of multiple parts. That's incorrect/unnecessary, but beyond my control.)
Thanks for the tip about that GP tool.
Actually, on closer inspection, I don't think it placed the point halfway along the line. Maybe it did something else, like place the point in the middle of the envelope. Then snap the point to the line, to satisfy the "Inside" criteria.