<?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: Arcade calculate angle between 2 points in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684028#M12315</link>
    <description>&lt;P&gt;My faint memories of high school trig tell me something's wrong with how you're calculating the angle. Thankfully, nobody writing arcade has to remember how to do this right thanks to the &lt;A href="https://developers.arcgis.com/arcade/function-reference/geometry_functions/#angle" target="_self"&gt;Angle&lt;/A&gt; function. Replace the last few lines of calculations with &lt;FONT face="courier new,courier"&gt;Angle(referencePoint, nearestPoint) - 90&lt;/FONT&gt;&amp;nbsp;and you should be golden.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Feb 2026 16:38:37 GMT</pubDate>
    <dc:creator>DavidSolari</dc:creator>
    <dc:date>2026-02-12T16:38:37Z</dc:date>
    <item>
      <title>Arcade calculate angle between 2 points</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684018#M12313</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm looking to calculate the angle between 2 points. Both are in different services. The first one it's a pole location and the second one it's an anchor location.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The anchor location must have a particular symbol and should point to the pole. That's what i'm looking for. It's not just a "looking good" nice to have, we need that angle to use it on AutoCad drawing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm using this code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;// Define the reference point (could be a specific feature)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var referencePoint = Geometry($feature); &amp;nbsp;// Reference feature geometry&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;// Define the feature set containing other points to compare&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var otherPoints = FeatureSetByName($map, "POLE"); // Replace with your layer name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;// Variables to store nearest point and minimum distance&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var nearestPoint = -1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var minDist = 1000; &amp;nbsp;// Start with a high number for comparison&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;// return Count(otherPoints)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;// Loop through each point to find the closest one&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for (var pointv in otherPoints) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; var dist = Distance(referencePoint, Geometry(pointv)); &amp;nbsp;// Calculate distance&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;//return dist&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; if (dist &amp;lt; minDist) { &amp;nbsp;// If this point is closer&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; minDist = dist; &amp;nbsp; &amp;nbsp; // Update minimum distance,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nearestPoint = Geometry(pointv); &amp;nbsp;// Update the nearest point&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;// Now calculate the angle using Atan2 based on nearestPoint's coordinates&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if (nearestPoint!= -1) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; var deltaY = nearestPoint.y - referencePoint.y; &amp;nbsp;// Change in Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; var deltaX = nearestPoint.x - referencePoint.x; &amp;nbsp;// Change in X&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; var anglev = Atan2(deltaY, deltaX); &amp;nbsp;// Calculate angle in radians&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; return anglev * abs((180 / PI)); &amp;nbsp;// Convert radians to degrees&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;} else {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; return 0; &amp;nbsp;// Handle case where no point is found&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;------------------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The results are not what I would have wished. First, the "North" at 0 degrees it's pointing West. Then at 0, 90, 180 degrees are looking good but not at 270 degrees. Between those numbers, none of the angles are correct. Here an example:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="CristianGraf_1-1770912615693.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/148347i5558997B32872B9F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="CristianGraf_1-1770912615693.png" alt="CristianGraf_1-1770912615693.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any idea what is wrong or what I need to change...&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Thank you all!!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2026 16:14:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684018#M12313</guid>
      <dc:creator>CristianGraf</dc:creator>
      <dc:date>2026-02-12T16:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade calculate angle between 2 points</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684021#M12314</link>
      <description>&lt;P&gt;A couple issues:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Angle reference &amp;amp; direction&lt;UL&gt;&lt;LI&gt;Atan2(deltaY, deltaX) gives the mathematical angle from the +X axis (East), measured counterclockwise. But you probably want a bearing measured clockwise from North.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Absolute value is breaking the quadrants&lt;UL&gt;&lt;LI&gt;abs(180/PI) will always be positive and that’s fine for the constant—but if the expression ever included abs around your angle, it would erase the sign and collapse quadrants. Even for the constant, abs is unnecessary.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;To convert the mathematical angle (from East, CCW) to a bearing (from North, CW), use:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;bearing = (450 - degreesFromEastCCW) % 360&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't test this on my end, but you want something like:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;// Reference: Anchor feature geometry
var referencePoint = Geometry($feature);

// Feature set containing poles (replace "POLE" with your layer name if different)
var otherPoints = FeatureSetByName($map, "POLE");

// Guard: if there are no poles, bail out
if (Count(otherPoints) == 0) {
    return null;
}

// Find nearest pole to this anchor
var nearestPoint = null;
var minDist = Infinity;

for (var pointv in otherPoints) {
    var g = Geometry(pointv);
    var dist = Distance(referencePoint, g);
    if (dist &amp;lt; minDist) {
        minDist = dist;
        nearestPoint = g;
    }
}

// If we found one, compute bearing (clockwise from North)
if (!IsEmpty(nearestPoint)) {
    var deltaY = nearestPoint.y - referencePoint.y;  // change in Northing
    var deltaX = nearestPoint.x - referencePoint.x;  // change in Easting

    // Mathematical angle from +X (East), CCW
    var angDegFromEastCCW = (Atan2(deltaY, deltaX) * 180 / PI + 360) % 360;

    // Convert to bearing: clockwise from North
    var bearing = (450 - angDegFromEastCCW) % 360;

    return bearing;  // degrees in [0, 360), North=0°, East=90°, South=180°, West=270°
} else {
    return null;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2026 16:29:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684021#M12314</guid>
      <dc:creator>ErikRose</dc:creator>
      <dc:date>2026-02-12T16:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade calculate angle between 2 points</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684028#M12315</link>
      <description>&lt;P&gt;My faint memories of high school trig tell me something's wrong with how you're calculating the angle. Thankfully, nobody writing arcade has to remember how to do this right thanks to the &lt;A href="https://developers.arcgis.com/arcade/function-reference/geometry_functions/#angle" target="_self"&gt;Angle&lt;/A&gt; function. Replace the last few lines of calculations with &lt;FONT face="courier new,courier"&gt;Angle(referencePoint, nearestPoint) - 90&lt;/FONT&gt;&amp;nbsp;and you should be golden.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2026 16:38:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684028#M12315</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2026-02-12T16:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade calculate angle between 2 points</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684030#M12316</link>
      <description>&lt;P&gt;An addendum: as your dataset grows you'll run geometry checks against the entire Pole dataset (at least, the entire set that the map has access to) and your edit performance will slowly grind to a halt. The usual fix is to run a &lt;A href="https://developers.arcgis.com/arcade/function-reference/geometry_functions/#buffer" target="_self"&gt;Buffer&lt;/A&gt; on your anchor point, then use &lt;A href="https://developers.arcgis.com/arcade/function-reference/geometry_functions/#intersects" target="_self"&gt;Intersects&lt;/A&gt; to reduce the available poles. You can also use &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#count" target="_self"&gt;Count&lt;/A&gt; to see if that intersection is empty and return an error to prevent adding anchors in the middle of the Atlantic.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Feb 2026 16:44:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684030#M12316</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2026-02-12T16:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade calculate angle between 2 points</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684400#M12322</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/697140"&gt;@ErikRose&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/4413"&gt;@DavidSolari&lt;/a&gt;&amp;nbsp;this works wonderfully!!! Thank you so mutch!&lt;/P&gt;&lt;P&gt;Mutch appreciated! I will make those last setting on the code!&lt;/P&gt;&lt;P&gt;As usual, this community ROCKS!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers!!!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Feb 2026 18:51:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-calculate-angle-between-2-points/m-p/1684400#M12322</guid>
      <dc:creator>CristianGraf</dc:creator>
      <dc:date>2026-02-13T18:51:01Z</dc:date>
    </item>
  </channel>
</rss>

