Shrink Lines — GP Tool

2139
23
03-20-2023 10:24 AM
Status: Open
Labels (1)
Bud
by
Honored Contributor

It would be helpful if there were an OOTB geoprocessing tool for shrinking lines at each end. By a measure or a percentage.

Bud_0-1679333021202.png

It would also be good if the tool could stretch out lines too -- using the angle of the last segment at each end. Or make that separate GP tool.

Thanks.

Related: Batch shrink lines at each end

23 Comments
DanLee
by Esri Regular Contributor
Bud
by

@DanLee Thanks.

As far as I can tell, the Trim Line tool can't be used to shrink lines -- when dangles aren't involved.

 

DanLee
by Esri Regular Contributor

Not directly, you are right.  You might have to find a way to generate a crossing line at where you need to trim to. Then select both the line you need to trim and the crossing line to use Trim Line tool.

DanLee
by Esri Regular Contributor

I am a bit curious about why you need to shorten the line in both ends. Do you mind describing what you need to do?

Just a thought for a potential workflow: if you have the line(s) selected, you can do the following:

- Use Feature Vertices To Points tool with Both_ends option to obtain the endpoints of the line(s).

- Use Butter tool to buffer the points with the distance that you want to shorten the line at both ends.

- Use Erase tool to erase the lines by the buffer polygons; your lines are shortened.  

Would that work? 🙂

Bud
by

@DanLee 

Here's my current use case, although there are others:

For each road line, I want to count the number of right-of-way polygons that the line intersects (using the Spatial Join geoprocessing tool). The relationship should always be 1 line to 1 polygon. So if the spatial join count isn't 1, then that area needs to be investigated.

Bud_0-1679399710283.png

The problem is, the roads often slightly overlap other polygons at road intersections, since the polygons aren't snapped to the road endpoints. And automatic snapping isn't an option in scenarios like these: screenshot. So the spatial join will count polygons that I don't care about.

So I figure, if I shorten the lines at each end in a copy FC, either by a measure or by a percentage, then that will avoid counting polygons that just barely overlap the roads.

What do you think?

 

For my notes, in general, I can think of a few scenarios I need to check for:

  1. 1 polygon intersects many lines
  2. 1 line intersects many polygons
  3. Lines that don't intersect any polygons
  4. Polygons that don't intersect any lines
  5. The line ROAD_ID matches the polygon ROAD_ID, but the line and polygon features don't intersect -- indicating a possible problem with the ROAD_ID.

 

Regarding the potential workflow you provided. I will check it out. Thanks!

DanLee
by Esri Regular Contributor

Note: this comment has been edited to clarify some details and to switch red box #1 and #2 to match Bud's notation change. - Dan

Perhaps you can use Feature Vertices To Points with Midpoint option to obtain midpoint of each line. Then use Spatial Join to join polygons with the midpoints using "Contains" option. For your scenarios:

  1. 1 polygon intersects many lines: Look for polygons with Joint_Count >1 (your red box #1)
  2. 1 line intersects many polygons:  Look for polygons with Joint_Count = 0, (two of the three polygons in your red box #2 would not contain the midpoints)
  3. Lines that don't intersect any polygons: this needs Spatial Join of the midpoints of lines with polygons, then look for Joint_Count = 0.  Could there be any line with midpoint is not inside any polygon but the line still intersects a polygon?
  4. Polygons that don't intersect any lines:  This may need Spatial Join of the polygons with line using the "Crossed by the outline of" option (I didn't test this, so not 100% sure).

With these processes, you may not need to shorten your lines?

DanLee
by Esri Regular Contributor

No problem. See my "Note" at top of my comment above.

SeanLim

Hi @Bud,

I've created a script tool for you that shrinks lines at both ends by a percentage or length.

You can add it to your project from Pro by navigating to the ArcGIS Online tab under Catalog > Portal and searching for "Shrink Line". Note that you have to be logged into ArcGIS Online for this.

SeanLim_0-1679499876727.png

Alternatively, you can access it here: https://arcg.is/9H8S8

 

Please let me know if you have any questions or feedback. Thanks!

DanLee
by Esri Regular Contributor

Hey @Bud,

Sean Lim who posted the script tool, Shrink Line, above is my teammate. He had some account conflict issue to resolve; that's why there is no Esri badge next to his name.  If you are still interested in this tool, please give it a try and let Sean know if it is helpful to solving your problem. Thanks.  - Dan

Bud
by

Thanks @SeanLim!

Just a heads up:
I had a rare case where one of the features in my FC had a null geometry. And that caused an error in the tool.

Bud_0-1679553287541.png
(mobile GDB; ArcGIS Pro 3.1)

But that's an uncommon scenario. It might not be worth worrying about.

Still testing.