I have 250 polylines. I have a value i calculated (all different) that needs to be added to the length of the. The values are in the attribute table. How can I increase the length of the lines using the values in the table as the distance to add to the lines?
Not sure if there is a tool that directly addresses this. I know this question has been asked in one form or another on GeoNet and StackExchange, so I encourage a bit more searching.
If you up for some basic scripting, the following code snippet should work or get you most of the way there:
<SPAN class="keyword token">import</SPAN> math fc <SPAN class="operator token">=</SPAN> <SPAN class="comment token"># Path to feature class containing lines to be extended</SPAN> dist_fld <SPAN class="operator token">=</SPAN> <SPAN class="comment token"># Name of field containing distance to extend line</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"SHAPE@"</SPAN><SPAN class="punctuation token">,</SPAN> dist_fld<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cur<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> line<SPAN class="punctuation token">,</SPAN> dist <SPAN class="keyword token">in</SPAN> cur<SPAN class="punctuation token">:</SPAN> SR <SPAN class="operator token">=</SPAN> line<SPAN class="punctuation token">.</SPAN>spatialReference parts <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> part <SPAN class="keyword token">in</SPAN> line<SPAN class="punctuation token">.</SPAN>getPart<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> pn1<SPAN class="punctuation token">,</SPAN> pn <SPAN class="operator token">=</SPAN> part<SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN> angle <SPAN class="operator token">=</SPAN> math<SPAN class="punctuation token">.</SPAN>atan2<SPAN class="punctuation token">(</SPAN>pn<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">-</SPAN> pn1<SPAN class="punctuation token">.</SPAN>Y<SPAN class="punctuation token">,</SPAN> pn<SPAN class="punctuation token">.</SPAN>X <SPAN class="operator token">-</SPAN> pn1<SPAN class="punctuation token">.</SPAN>X<SPAN class="punctuation token">)</SPAN> p <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>pn<SPAN class="punctuation token">.</SPAN>X <SPAN class="operator token">+</SPAN> dist <SPAN class="operator token">*</SPAN> math<SPAN class="punctuation token">.</SPAN>cos<SPAN class="punctuation token">(</SPAN>angle<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> pn<SPAN class="punctuation token">.</SPAN>Y <SPAN class="operator token">+</SPAN> dist <SPAN class="operator token">*</SPAN> math<SPAN class="punctuation token">.</SPAN>sin<SPAN class="punctuation token">(</SPAN>angle<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> part<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>p<SPAN class="punctuation token">)</SPAN> parts<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>part<SPAN class="punctuation token">)</SPAN> line <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Polyline<SPAN class="punctuation token">(</SPAN>parts<SPAN class="punctuation token">,</SPAN> SR<SPAN class="punctuation token">)</SPAN> cur<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>line<SPAN class="punctuation token">,</SPAN>dist<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
The above code simply linearly extrapolates the line that connects the last two vertices of the line. If you want different line fitting/extending, you can implement a different formula.
NOTE: The ArcPy Array slicing on line 11 requires ArcGIS 10.4.1. If you are using an earlier version the line can be modified.
pn1<SPAN class="punctuation token">,</SPAN> pn <SPAN class="operator token">=</SPAN> arr<SPAN class="punctuation token">[</SPAN>len<SPAN class="punctuation token">(</SPAN>arr<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> arr<SPAN class="punctuation token">[</SPAN>len<SPAN class="punctuation token">(</SPAN>arr<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
That worked fantastically!
Could you mark the answer posted by Joshua as the correct answer?
Thank you!
Yes it will be extended at the end of the line.
I thought the same thing, about beginning, end, or both, but after reading the question a couple times, I assumed (I know about assuming) we are talking about the end. If the OP states otherwise, I can modify the code snippet.
The helpful example provided by bixb0012 assumes that the line will be extended at the end of the line. A possible scenario could be to extend both ends with half the value from the attribute table.
Would be interesting to learn a little more about why you want this.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.