Get bearing of selected line feature

499
6
Jump to solution
07-15-2020 10:48 AM
BrianBulla
Regular Contributor

Hi,

Can't seem to find anything in the SDK or the forums here regarding getting the bearing of a selected line segment.  Is there a method somewhere that would do this for me??  I guess I could get the start and end point coordinates and figure it out myself, but I was hoping for something quick and easy.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
BrianBulla
Regular Contributor

OK, well I did find a solution that involves calculating it all out yourself, but I would have to imagine there is something pre-built into the SDK that would allow us to do this without all the math.  If there is, please let me know.  :)

double Rad2Degrees = 180 / Math.PI;
var lineBuilder = new LineBuilder(fromPoint, toPoint);
var lineSeg = lineBuilder.ToSegment();
var degrees = lineSeg.Angle * Rad2Degrees;
degrees = 90 - degrees;
if (degrees < 0)
degrees = degrees + 360;

View solution in original post

0 Kudos
6 Replies
ChristopherBertrand
Occasional Contributor

Hi Brian,

The Measure tool in Pro will show the Net Path Bearing when you use the Measure Distance option.  Would that be sufficient?

0 Kudos
BrianBulla
Regular Contributor

Hi Chris,

I'm actually looking for something in the SDK for determining the bearing of a selected line feature.  For example, as I go iterate through a collection of selected line features features.

I can do things like .LENGTH to get the length, .Points to get the points, but what I am look for is .Bearing which does not seem to exist anywhere that I can find.

0 Kudos
BrianBulla
Regular Contributor

OK, well I did find a solution that involves calculating it all out yourself, but I would have to imagine there is something pre-built into the SDK that would allow us to do this without all the math.  If there is, please let me know.  :)

double Rad2Degrees = 180 / Math.PI;
var lineBuilder = new LineBuilder(fromPoint, toPoint);
var lineSeg = lineBuilder.ToSegment();
var degrees = lineSeg.Angle * Rad2Degrees;
degrees = 90 - degrees;
if (degrees < 0)
degrees = degrees + 360;

0 Kudos
SeanJones
Esri Regular Contributor

Hey Brian,

Your math works because you're assuming you have a two point polyline which is why a bearing/direction property doesn't make sense for polylines in general as they could be made up of any number of segments and parts. The property isn't on segments either because they could be a curve. Pessimistic design

0 Kudos
ThanHtetAung_EsriAu
Esri Regular Contributor

Hi Brian Bulla‌ and Sean Jones‌,

Didn't manage to find that bearing function in sdk before as I have same requirement like what Brian encounter before.

I solved it in old school way of calculation borrowing from cpp code.

Below is the reference I used last time.

Geographic Distance and Azimuth Calculations 

BrianBulla
Regular Contributor

Thanks Than Aung‌.

Sean Jones‌:  Since there does seem to be a need from users to calculate the bearing between two points, is there any way that esri could consider adding this sort of functionality to the SDK?  Given two points, to build in all the math required to do this calculation??

Years ago I became quite familiar with another SDK called the Franson GPS SDK, which had all sort of functionality like that built right into the SDK.

Anyways....just a thought.

Thanks!!

0 Kudos