ArcGIS Toolbox – Shorten Polylines by Percentage or Distance with ArcPy

Share Button

Updated – 4/10/2015
Can now shorten the polylines from both sides, this keeps the middle part of the polyline

Previous Updates
Fixed compatibility with Python 3 for ArcGIS Pro
Output polylines now retain original vertices, whereas before the features were simplified into straight lines

(If you’re using Firefox, then right click and Save Link As)
Download the Shorten Polylines Toolbox – works with ArcGIS 10.2+
View the Source Code

(any donations go towards hosting costs)

Only use the following download if you have ArcGIS 10.1 or earlier. This version will not retain the original line shape.
Download the Shorten Polylines Toolbox
View the Source Code

The Shorten Polylines tool takes an input Polyline feature class and shortens each polyline feature based on a specified distance or percentage value. The value can either be fixed or field based.

You can now shorten the lines based on either the beginning, end, or both sides as shown in the screenshot below. If BOTH is chosen, then the middle portion of the polyline is kept. Also, if BOTH is chosen the distance or percentage value is divided by two.

The output Polyline feature class containing the shortened polylines will have a field called LineOID which states the OID of the original polyline it was created from. This allows any attribute information to be joined back to the new polylines. It will also contain a field called Value, which states the value that was used to create the line.

If a field is being used to assign the value, any features with null values will be skipped. If the polylines are being shortened using a PERCENTAGE, the value must be in decimal format and between 0 and 1.0. All features with values outside this range will be skipped. If the polylines are being shortened using a DISTANCE, the value must be positive. All features with negative numbers will be skipped.

Be sure to view the Tool Help within the tool dialog box for detailed instructions. Also, check the Geoprocessing Results for any error messages.

Here’s a screenshot of the parameters:

Shorten Polylines parameters

I hope someone finds this tool useful. Please leave a comment if you have any questions or problems, and be sure to check out the other tools I’ve created!

11 thoughts on “ArcGIS Toolbox – Shorten Polylines by Percentage or Distance with ArcPy

    1. Hi Shaohu, what exactly are you having problems with? Adding it to ArcMap? If so, you need to right click in the whitespace of ArcToolbox and go to Add Toolbox and then add the toolbox you downloaded from this page. Here is a video for a different set of tools, but it will show you how to add them:

      https://www.youtube.com/watch?v=5BUSVxmu8Qw

      Let me know if this didn’t answer your question.

  1. Great toolbox.
    I have polylines, each with several vertexes and twists and turns. I need to shorten those lines by a percentage while leaving the rest of the complexity of the line. This tool currently simplifies the line into a straight line.

    1. Hi Steve, thanks! I can understand why you’d want to keep the original complexity of the line instead of just simplifying the feature into a straight line. I made a few modifications to the script, and it now does what you’re asking. However, the toolbox now requires 10.2+ because of ArcPy capabilities not present in lesser versions. I’ve changed the script and download links above. Thanks for the suggestion!

    1. Hi Theresa, I’ve added the ArcGIS 10.1 or earlier download to the top of this page. This version is really only good for perfectly straight lines, as it does not retain the shape of any vertices besides the first and last.

  2. Hi Ian,

    This tool is great, exactly what I was after. Would I be possible for the new polyline to be shortened from both ends?

    Currently I am using a percentage, but the reduction only happens on one end of the line. Ideally I want the reduction to happen across both ends.

    Cheers!

    1. Hi Sam, thanks for the comment! I’ve now added this functionality. You can now shorten the polylines from the beginning, end, or both. If you choose both, it shortens both ends and keeps the middle part of the polyline. Hope this works for you.

  3. Hey Sam,

    I was wondering how you could use this tool in an Arcpy script. I am receiving the error:
    AttributeError: ‘module’ object has no attribute ‘ShortenPolylines_ShortenPolylines’

    Thanks

Leave a Reply