Select to view content in your preferred language

Get Azimuth value from point A to point B

4790
8
05-24-2019 01:19 AM
MohamadFathin
Emerging Contributor

Hi,

May i know how can i get a azimuth value between 2 points?

0 Kudos
8 Replies
TedKowal
Honored Contributor

Calculating a bearing distance—Help | ArcGIS Desktop 

How to Calculate Azimuth in Excel | It Still Works 

Now if you can script in Excel this is a custom function I use for determining Azimuths..

I use it in excel like this... =Azimuth(cell with Latitude1, cell with Longitude1, cell with Latitude1, cell with Longitude2)

                                         eg.  =Azimuth(A1,B1,A2,B2)

Function Azimuth(lat1 As Single, lat2 As Single, lon1 As Single, lon2 As Single) As Single

Dim X1 As Single, X2 As Single, Y As Single, dX As Single, dY As Single

With Application.WorksheetFunction
    X1 = .Radians(lat1)
    X2 = .Radians(lat2)
    Y = .Radians(lon2 - lon1)
End With

    dX = Math.Cos(X1) * Math.Sin(X2) - Math.Sin(X1) * Math.Cos(X2) * Math.Cos(Y)
    dY = Math.Cos(X2) * Math.Sin(Y)


With Application.WorksheetFunction
    Azimuth = .Degrees(.Atan2(dX, dY))
End With

End Function
0 Kudos
Nicholas-Furness
Esri Regular Contributor

Use the GeometryEngine.DistanceGeodetic method. The result, a GeodeticDistanceResult, includes the azimuths between the two points.

0 Kudos
MohamadFathin
Emerging Contributor

Hi 

I try using the method for calculate to get the azimuth between 2 point, but i am not understand these two functions:

private readonly LinearUnit _metersUnit;
private readonly AngularUnit _degreesUnit;

below is the code i try to implement, sorry i am new to c#

private void CreatePoints()
{
// Create a red circle simple marker symbol
SimpleMarkerSymbol redCircleSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.FromArgb(0xFF, 0xFF, 0x00, 0x00), 10);

MapPoint mapPoint1 = new MapPoint(-2.72, 56.065, SpatialReferences.Wgs84);

MapPoint mapPoint2 = new MapPoint(-2.69, 56.065, SpatialReferences.Wgs84);

// Create graphics and add them to graphics overlay
Graphic graphic = new Graphic(mapPoint1, redCircleSymbol);
_overlay.Graphics.Add(graphic);

graphic = new Graphic(mapPoint2, redCircleSymbol);
_overlay.Graphics.Add(graphic);

GeodeticDistanceResult distance = GeometryEngine.DistanceGeodetic(mapPoint1, mapPoint2, _metersUnit, _degreesUnit, GeodeticCurveType.Geodesic);

}

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Hi Mohamad Fathin,

You could set them up something like this:

private readonly LinearUnit _metersUnit = LinearUnits.Meters;
private readonly AngularUnit _degreesUnit = AngularUnits.Degrees;

or just call DistanceGeodetic like this:

GeodeticDistanceResult distance = GeometryEngine.DistanceGeodetic(mapPoint1, mapPoint2, LinearUnits.Meters, AngularUnits.Degrees, GeodeticCurveType.Geodesic);

See LinearUnits and AngularUnits.

Hope that helps!

Nick.

0 Kudos
MohamadFathin
Emerging Contributor

HI Nicholas Furness

I get below error, did you know how to settle this issues?

System.InvalidOperationException
HResult=0x80131509
Message=Invalid id for creating a unit
Source=Esri.ArcGISRuntime
StackTrace:
at Esri.ArcGISRuntime.Geometry.Unit.FromUnitId(Int32 unitId)
at Esri.ArcGISRuntime.Geometry.LinearUnits.get_Meters()
at ArcGISControl.MainWindow..ctor() in C:\Users\mfathin.CSYSINT\Documents\Visual Studio 2017\Projects\ArcGISControl\ArcGISControl\MainWindow.xaml.cs:line 32

Inner Exception 1:
DllNotFoundException: Unable to load DLL 'RuntimeCoreNet.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

This my code:

private readonly LinearUnit _metersUnit = LinearUnits.Meters;
private readonly AngularUnit _degreesUnit = AngularUnits.Degrees;

private void CreatePoints()
{
// Create a red circle simple marker symbol
SimpleMarkerSymbol redCircleSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.FromArgb(0xFF, 0xFF, 0x00, 0x00), 10);

MapPoint mapPoint1 = new MapPoint(-2.72, 56.065, SpatialReferences.Wgs84);

MapPoint mapPoint2 = new MapPoint(-2.69, 56.065, SpatialReferences.Wgs84);

// Create graphics and add them to graphics overlay
graphic1 = new Graphic(mapPoint1, redCircleSymbol);
_overlay.Graphics.Add(graphic1);

graphic2 = new Graphic(mapPoint2, redCircleSymbol);
_overlay.Graphics.Add(graphic2);

//CreateLinePoint();


GeodeticDistanceResult distance = GeometryEngine.DistanceGeodetic(mapPoint1, mapPoint2, _metersUnit, _degreesUnit, GeodeticCurveType.Geodesic);

textBox.Text = string.Format("Distance:{0} | Azimuth:{1}", _metersUnit.UnitType.ToString(), _degreesUnit.UnitType.ToString());

0 Kudos
NathanCastle1
Esri Contributor

Hi,

I tried the code locally and found the following worked for the basic use case of finding the azimuth values:

MapPoint mapPoint1 = new MapPoint(-2.72, 56.065, SpatialReferences.Wgs84);

MapPoint mapPoint2 = new MapPoint(-2.69, 56.065, SpatialReferences.Wgs84);

GeodeticDistanceResult distance = GeometryEngine.DistanceGeodetic(mapPoint1, mapPoint2, LinearUnits.Meters, AngularUnits.Degrees, GeodeticCurveType.Geodesic);

MessageBox.Show($"Distance:{distance.Distance} | Azimuth1:{distance.Azimuth1} | Azimuth2:{distance.Azimuth2}");

That is essentially what you had, and based on the error message you shared (Unable to load DLL 'RuntimeCoreNet.dll': The specified module could not be found), this looks like a deployment issue. 

Did you use Nuget to reference the ArcGIS Runtime SDK? Have you tried cleaning, clearing the bin/ and obj/ folders, and then rebuilding?

MohamadFathin
Emerging Contributor

Hi ,

Thank you for your answer. I manage to get the azimuth from point 1 to point 2 and vice versa. One thing that i want to know. The azimuth start from 0 to 180 for clock wise and -0 to -180 for anti-clockwise. After the 180 on clockwise the degree become negative that start with -180 until -0. How can i make azimuth from 0 to 360 ?

0 Kudos
Nicholas-Furness
Esri Regular Contributor

If the value is < 0, add 360. -179 becomes 181. -10 becomes 350, etc.

0 Kudos