<?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 Determining main trail on a line network in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/determining-main-trail-on-a-line-network/m-p/1552103#M45437</link>
    <description />
    <pubDate>Wed, 06 Nov 2024 17:54:57 GMT</pubDate>
    <dc:creator>LeoSync727</dc:creator>
    <dc:date>2024-11-06T17:54:57Z</dc:date>
    <item>
      <title>Determining main trail on a line network</title>
      <link>https://community.esri.com/t5/data-management-questions/determining-main-trail-on-a-line-network/m-p/1552103#M45437</link>
      <description />
      <pubDate>Wed, 06 Nov 2024 17:54:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/determining-main-trail-on-a-line-network/m-p/1552103#M45437</guid>
      <dc:creator>LeoSync727</dc:creator>
      <dc:date>2024-11-06T17:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Determining left, right and main trail on a line network</title>
      <link>https://community.esri.com/t5/data-management-questions/determining-main-trail-on-a-line-network/m-p/1552716#M45439</link>
      <description>&lt;P&gt;import arcpy&lt;BR /&gt;import math&lt;/P&gt;&lt;P&gt;# Input layers&lt;BR /&gt;trail_lines = "TrailSegments" # Line feature class&lt;BR /&gt;fork_points = "ForkPoints" # Point feature class&lt;/P&gt;&lt;P&gt;# Add fields to store trail classification&lt;BR /&gt;arcpy.AddField_management(trail_lines, "TrailType", "TEXT")&lt;/P&gt;&lt;P&gt;# Function to calculate angle between two line segments&lt;BR /&gt;def calculate_angle(line1, line2):&lt;BR /&gt;# Get angle in radians between two lines&lt;BR /&gt;angle1 = math.atan2(line1.lastPoint.Y - line1.firstPoint.Y,&lt;BR /&gt;line1.lastPoint.X - line1.firstPoint.X)&lt;BR /&gt;angle2 = math.atan2(line2.lastPoint.Y - line2.firstPoint.Y,&lt;BR /&gt;line2.lastPoint.X - line2.firstPoint.X)&lt;BR /&gt;angle = math.degrees(angle2 - angle1)&lt;BR /&gt;return angle if angle &amp;gt;= 0 else angle + 360&lt;/P&gt;&lt;P&gt;# Loop through each fork&lt;BR /&gt;with arcpy.da.UpdateCursor(trail_lines, ["SHAPE@", "TrailType"]) as line_cursor:&lt;BR /&gt;for line in line_cursor:&lt;BR /&gt;line_geometry = line[0]&lt;BR /&gt;closest_fork = None&lt;BR /&gt;min_distance = float('inf')&lt;BR /&gt;&lt;BR /&gt;# Find closest fork to determine which direction the line takes at the fork&lt;BR /&gt;with arcpy.da.SearchCursor(fork_points, ["SHAPE@"]) as fork_cursor:&lt;BR /&gt;for fork in fork_cursor:&lt;BR /&gt;distance = line_geometry.distanceTo(fork[0])&lt;BR /&gt;if distance &amp;lt; min_distance:&lt;BR /&gt;min_distance = distance&lt;BR /&gt;closest_fork = fork[0]&lt;/P&gt;&lt;P&gt;# For each line segment connected to the fork, calculate angle&lt;BR /&gt;if closest_fork:&lt;BR /&gt;main_angle = calculate_angle(line_geometry, closest_fork)&lt;BR /&gt;&lt;BR /&gt;# Classify based on angle thresholds (you may adjust these as needed)&lt;BR /&gt;if 0 &amp;lt;= main_angle &amp;lt; 30 or main_angle &amp;gt; 330:&lt;BR /&gt;line[1] = "Main"&lt;BR /&gt;elif 30 &amp;lt;= main_angle &amp;lt;= 180:&lt;BR /&gt;line[1] = "Left"&lt;BR /&gt;else:&lt;BR /&gt;line[1] = "Right"&lt;/P&gt;&lt;P&gt;line_cursor.updateRow(line)&lt;/P&gt;&lt;P&gt;print("Trail classification completed.")&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 10:10:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/determining-main-trail-on-a-line-network/m-p/1552716#M45439</guid>
      <dc:creator>Kaone3000</dc:creator>
      <dc:date>2024-10-28T10:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Determining left, right and main trail on a line network</title>
      <link>https://community.esri.com/t5/data-management-questions/determining-main-trail-on-a-line-network/m-p/1552743#M45440</link>
      <description>&lt;P&gt;The above script is pretty good, although there are a few issues you'll need to adjust to suit your data. Consider this crudely drawn example:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertKrisher_0-1730119119063.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118218iBF8DEC837DE457CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RobertKrisher_0-1730119119063.png" alt="RobertKrisher_0-1730119119063.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Instead of using the entire trail line you will likely need to break each line into multiple segments, so you only consider the angles of the line segments that intersect each other.&lt;/LI&gt;
&lt;LI&gt;The orientation of these line segments may not always be consistent, you may need to periodically flip the orientation of a segment when doing your calculation.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;If you found all the locations where trails intersected, buffered those points out slightly, and calculated the angle of each line intersection that would solve most of these issues. You would just need to flip the angle of the line that represents the angle of travel.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RobertKrisher_2-1730119724666.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118220iFD55A90A6110BE33/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RobertKrisher_2-1730119724666.png" alt="RobertKrisher_2-1730119724666.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 12:48:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/determining-main-trail-on-a-line-network/m-p/1552743#M45440</guid>
      <dc:creator>RobertKrisher</dc:creator>
      <dc:date>2024-10-28T12:48:52Z</dc:date>
    </item>
  </channel>
</rss>

