<?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 Subtracting attributes of different records based on common attribute in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/subtracting-attributes-of-different-records-based/m-p/157599#M12115</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not sure if this is the right place to put this question.&amp;nbsp; If not, please let me know. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to find the angle between adjacent lines in a single layer.&amp;nbsp; I plan to accomplish this by subtracting the incidence angle of one line from that of its adjacent line. The lines come from polylines split at vertices, so the start coordinates of one line exactly match the end coordinates of another line. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a field with the incidence angle for each line, a field with the begin xy of the line, and a field with the end xy of the line.&amp;nbsp; I am trying to figure out how to have a script loop through the table, find the line whose beginningxy matches the endxy of the current line, and subtract the angles.&amp;nbsp; I am not very familiar with Python so I would greatly appreciate guidance.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Jun 2014 16:22:29 GMT</pubDate>
    <dc:creator>KatherineHayman1</dc:creator>
    <dc:date>2014-06-25T16:22:29Z</dc:date>
    <item>
      <title>Subtracting attributes of different records based on common attribute</title>
      <link>https://community.esri.com/t5/python-questions/subtracting-attributes-of-different-records-based/m-p/157599#M12115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not sure if this is the right place to put this question.&amp;nbsp; If not, please let me know. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to find the angle between adjacent lines in a single layer.&amp;nbsp; I plan to accomplish this by subtracting the incidence angle of one line from that of its adjacent line. The lines come from polylines split at vertices, so the start coordinates of one line exactly match the end coordinates of another line. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a field with the incidence angle for each line, a field with the begin xy of the line, and a field with the end xy of the line.&amp;nbsp; I am trying to figure out how to have a script loop through the table, find the line whose beginningxy matches the endxy of the current line, and subtract the angles.&amp;nbsp; I am not very familiar with Python so I would greatly appreciate guidance.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2014 16:22:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/subtracting-attributes-of-different-records-based/m-p/157599#M12115</guid>
      <dc:creator>KatherineHayman1</dc:creator>
      <dc:date>2014-06-25T16:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting attributes of different records based on common attribute</title>
      <link>https://community.esri.com/t5/python-questions/subtracting-attributes-of-different-records-based/m-p/157600#M12116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you split the lines using SplitLine (or the toolbox tool Split Line At Vertices)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The new lines will still have any original line ID you may have used&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and be in order in the table from original from onwards.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can identify the individual parts in order and add a segment ID.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, add an integer segID field to your table&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and you already have your origLineID field:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Use an update cursor to run through the table and for each new origLineID, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;you start with a segID of 1, and each time the origLineID stays the same, you increment the segID.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With line and segment ids, you can create a dictionary of a list of &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;incidence angles, in segment order, for each original line&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then it is always differences between adjacent pairs of angles.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is all just off the cuff: no warranties...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2014 18:21:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/subtracting-attributes-of-different-records-based/m-p/157600#M12116</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2014-06-25T18:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Subtracting attributes of different records based on common attribute</title>
      <link>https://community.esri.com/t5/python-questions/subtracting-attributes-of-different-records-based/m-p/157601#M12117</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This solution is assuming you have a multipart feature ... so a new row in your attribute table for each polyline segment. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I'm doing here is cycling through the line geometries, getting the start and end point of each segment, and getting the azimuthal of the starting point.&amp;nbsp; (Note that if you have a longer line, your end azimuthal may be different due to it's great circle)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import math
def getBearing(part):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Returns the initial bearing in degrees from north following the great
&amp;nbsp;&amp;nbsp;&amp;nbsp; # circle path to the destination coordinates.
&amp;nbsp;&amp;nbsp;&amp;nbsp; firstpoint = part.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; lastpoint = part.next()

&amp;nbsp;&amp;nbsp;&amp;nbsp; lat1 = math.radians(float(firstpoint.Y))
&amp;nbsp;&amp;nbsp;&amp;nbsp; lat2 = math.radians(float(lastpoint.Y))

&amp;nbsp;&amp;nbsp;&amp;nbsp; dLon = math.radians(float(lastpoint.X)-float(firstpoint.X))

&amp;nbsp;&amp;nbsp;&amp;nbsp; y = math.sin(dLon) * math.cos(lat2)

&amp;nbsp;&amp;nbsp;&amp;nbsp; x = math.cos(lat1) * math.sin(lat2) - \
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; math.sin(lat1) * math.cos(lat2) * math.cos(dLon)

&amp;nbsp;&amp;nbsp;&amp;nbsp; brng = math.atan2(y, x)

&amp;nbsp;&amp;nbsp;&amp;nbsp; return (math.degrees(brng) + 360) % 360;

arcpy.AddField_management(YourFeatureClass,"angle","FLOAT")

with arcpy.da.UpdateCursor(YourFeatureClass,["SHAPE@","angle"]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geom = row[0]

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; part = geom.getPart(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bearing = getBearing(part)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Updating segment with bearing %f" % bearing

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = bearing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row) &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will update each row with it's azimuthal, then you can take it from there to calculate the differences between angles if needed.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:20:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/subtracting-attributes-of-different-records-based/m-p/157601#M12117</guid>
      <dc:creator>MattEiben</dc:creator>
      <dc:date>2021-12-11T08:20:48Z</dc:date>
    </item>
  </channel>
</rss>

