Select to view content in your preferred language

Points - Calculate Bearing/Direction from Point to Point in Attribute Table

696
3
Jump to solution
04-22-2024 06:52 AM
ArmstKP
Frequent Contributor

Has anybody done this in Python or Arcade?

0 Kudos
1 Solution

Accepted Solutions
Dale_Honeycutt
Frequent Contributor

found on this stackoverflow thread:

import numpy
import math

def get_bearing(lat1, long1, lat2, long2):
    dLon = (long2 - long1)
    x = math.cos(math.radians(lat2)) * math.sin(math.radians(dLon))
    y = math.cos(math.radians(lat1)) * math.sin(math.radians(lat2)) - math.sin(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.cos(math.radians(dLon))
    brng = numpy.arctan2(x,y)
    brng = numpy.degrees(brng)

    return brng

 

View solution in original post

0 Kudos
3 Replies
Dale_Honeycutt
Frequent Contributor

found on this stackoverflow thread:

import numpy
import math

def get_bearing(lat1, long1, lat2, long2):
    dLon = (long2 - long1)
    x = math.cos(math.radians(lat2)) * math.sin(math.radians(dLon))
    y = math.cos(math.radians(lat1)) * math.sin(math.radians(lat2)) - math.sin(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.cos(math.radians(dLon))
    brng = numpy.arctan2(x,y)
    brng = numpy.degrees(brng)

    return brng

 

0 Kudos
ArmstKP
Frequent Contributor

@Dale_Honeycutt Thank you.  This worked like a charm!

0 Kudos
Dale_Honeycutt
Frequent Contributor

That's good to hear b/c that was some scary math.