<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculate angle of each line in a polyline shapefile in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435251#M14666</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How do I modify the Python code so that it returns the angle in a different projection?&amp;nbsp; I want to use the code in the Field Calculator in ArcMap.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My data is in BC Albers and I want to return the angle in UTM Zone 11N.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Jun 2013 20:09:12 GMT</pubDate>
    <dc:creator>LoreenHodgkinson</dc:creator>
    <dc:date>2013-06-13T20:09:12Z</dc:date>
    <item>
      <title>Calculate angle of each line in a polyline shapefile</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435245#M14660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm looking for a tool that will calculate the angle of each line in a set of polylines individually. Ideally I would like to be able to add an extra field to the attribute table of the polylines and fill this field with the overall angle of the polyline (probably just calculated from the first point to the last point, ignoring the bits in the middle).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a tool that will do this? I can find various tools that will work for polygons, but not for polylines.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Robin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jan 2011 21:03:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435245#M14660</guid>
      <dc:creator>RobinWilson</dc:creator>
      <dc:date>2011-01-20T21:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate angle of each line in a polyline shapefile</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435246#M14661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Robin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To solve your problem, you can first use split lines at vertice tool to explose your polyline to segment. The following step is to use this script on the calculate field:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Parser:
Python

Expression:
GetAzimuthPolyline( !Shape!)

Code Block:
import math
def GetAzimuthPolyline(shape):
 radian = math.atan((shape.lastpoint.x - shape.firstpoint.x)/(shape.lastpoint.y - shape.firstpoint.y))
 degrees = radian * 180 / math.pi
 return degrees

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now you have angle for each line in the new feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that help you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards,&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:30:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435246#M14661</guid>
      <dc:creator>FrédéricPRALLY</dc:creator>
      <dc:date>2021-12-11T19:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate angle of each line in a polyline shapefile</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435247#M14662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Robin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is a tool in your ArcToolbox called &lt;/SPAN&gt;&lt;STRONG&gt;Linear Direction Mean&lt;/STRONG&gt;&lt;SPAN&gt; in the Spatial Statistics toolset. You could try running this tool setting the case field to a unique ID for each polyline (such as the ObjectID). Not tried it so I could be sending you off in the wrong direction (no pun intended).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Jan 2011 13:03:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435247#M14662</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2011-01-24T13:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate angle of each line in a polyline shapefile</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435248#M14663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I edited this code and it works fine in the field calculator, but doesn't work as shown below as a stand-alone script.&amp;nbsp; Any suggestions?&amp;nbsp; Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import math&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set environment settings&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.workspace = "C:/WorkSpace"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set local variables&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;inFeatures = "testfracs.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldName = "Geoangle1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;expression = "GetAzimuthPolyline(!Shape!)"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;codeblock = """def GetAzimuthPolyline(shape):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; radian = math.atan((shape.lastpoint.x - shape.firstpoint.x)/(shape.lastpoint.y - shape.firstpoint.y))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; degrees = radian * 180 / math.pi&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return degrees"""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Execute AddField&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddField_management(inFeatures, fieldName, "SHORT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#print "Field has been added."&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Execute CalculateField &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management(inFeatures, fieldName, expression, "PYTHON", codeblock)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Nov 2011 15:13:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435248#M14663</guid>
      <dc:creator>RyanHuntley</dc:creator>
      <dc:date>2011-11-08T15:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate angle of each line in a polyline shapefile</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435249#M14664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
 radian = math.atan((shape.lastpoint.x - shape.firstpoint.x)/(shape.lastpoint.y - shape.firstpoint.y))
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for posting.&amp;nbsp; Just a quick correction (or maybe not).&amp;nbsp; I'm not sure if this gives the angle in geographic coordinates vs. arithmetic or whatnot, but for my purposes, I need the angle in standard math-style degrees-from-x-axis.&amp;nbsp; So I had to modify the above line switching the x and y values as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; radian = math.atan((shape.lastpoint.y - shape.firstpoint.y)/(shape.lastpoint.x - shape.firstpoint.x))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Both may be correct for different cases, but this one worked for me.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:30:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435249#M14664</guid>
      <dc:creator>SteveShaffer</dc:creator>
      <dc:date>2021-12-11T19:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate angle of each line in a polyline shapefile</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435250#M14665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;May be helpful - similar topic (calculating angular changes and average curvature of lines)...&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/49581-get-vertex-coordinates?p=175418&amp;amp;viewfull=1#post175418"&gt;http://forums.arcgis.com/threads/49581-get-vertex-coordinates?p=175418&amp;amp;viewfull=1#post175418&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Feb 2012 07:57:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435250#M14665</guid>
      <dc:creator>J_B__K_</dc:creator>
      <dc:date>2012-02-24T07:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate angle of each line in a polyline shapefile</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435251#M14666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How do I modify the Python code so that it returns the angle in a different projection?&amp;nbsp; I want to use the code in the Field Calculator in ArcMap.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My data is in BC Albers and I want to return the angle in UTM Zone 11N.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 20:09:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435251#M14666</guid>
      <dc:creator>LoreenHodgkinson</dc:creator>
      <dc:date>2013-06-13T20:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate angle of each line in a polyline shapefile</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435252#M14667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;How do I modify the Python code so that it returns the angle in a different projection?&amp;nbsp; I want to use the code in the Field Calculator in ArcMap.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;My data is in BC Albers and I want to return the angle in UTM Zone 11N.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You hack it.&amp;nbsp; Make sure each line has a unique ID and Project the lines to UTM Zone 11N.&amp;nbsp; Do the calculation above.&amp;nbsp; Join to the original lines and calc the result over.&amp;nbsp; No one has shown a way to use the Field Calculator to do on the fly projections that I have seen.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Easy enough to build a ModelBuilder model to do this with an in memory output of the projection step.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 21:10:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435252#M14667</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-06-13T21:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate angle of each line in a polyline shapefile</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435253#M14668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Checking cutbacks in lines and polygons&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//01020000000n000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//01020000000n000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Features with an angle between segments on a polyline or polygon feature that is below the minimum value are going to be returned as results.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]29961[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Dec 2013 07:12:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-angle-of-each-line-in-a-polyline/m-p/435253#M14668</guid>
      <dc:creator>SreeKumar</dc:creator>
      <dc:date>2013-12-18T07:12:04Z</dc:date>
    </item>
  </channel>
</rss>

