Hi,
May i know how can i get a azimuth value between 2 points?
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 <SPAN class="token function">Azimuth</SPAN><SPAN class="punctuation token">(</SPAN>lat1 As Single<SPAN class="punctuation token">,</SPAN> lat2 As Single<SPAN class="punctuation token">,</SPAN> lon1 As Single<SPAN class="punctuation token">,</SPAN> lon2 As Single<SPAN class="punctuation token">)</SPAN> As Single Dim X1 As Single<SPAN class="punctuation token">,</SPAN> X2 As Single<SPAN class="punctuation token">,</SPAN> Y As Single<SPAN class="punctuation token">,</SPAN> dX As Single<SPAN class="punctuation token">,</SPAN> dY As Single With Application<SPAN class="punctuation token">.</SPAN>WorksheetFunction X1 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="token function">Radians</SPAN><SPAN class="punctuation token">(</SPAN>lat1<SPAN class="punctuation token">)</SPAN> X2 <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="token function">Radians</SPAN><SPAN class="punctuation token">(</SPAN>lat2<SPAN class="punctuation token">)</SPAN> Y <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="token function">Radians</SPAN><SPAN class="punctuation token">(</SPAN>lon2 <SPAN class="operator token">-</SPAN> lon1<SPAN class="punctuation token">)</SPAN> End With dX <SPAN class="operator token">=</SPAN> Math<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Cos</SPAN><SPAN class="punctuation token">(</SPAN>X1<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> Math<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Sin</SPAN><SPAN class="punctuation token">(</SPAN>X2<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN> Math<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Sin</SPAN><SPAN class="punctuation token">(</SPAN>X1<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> Math<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Cos</SPAN><SPAN class="punctuation token">(</SPAN>X2<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> Math<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Cos</SPAN><SPAN class="punctuation token">(</SPAN>Y<SPAN class="punctuation token">)</SPAN> dY <SPAN class="operator token">=</SPAN> Math<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Cos</SPAN><SPAN class="punctuation token">(</SPAN>X2<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> Math<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Sin</SPAN><SPAN class="punctuation token">(</SPAN>Y<SPAN class="punctuation token">)</SPAN> With Application<SPAN class="punctuation token">.</SPAN>WorksheetFunction Azimuth <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="token function">Degrees</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Atan2</SPAN><SPAN class="punctuation token">(</SPAN>dX<SPAN class="punctuation token">,</SPAN> dY<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> End With End Function<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Use the GeometryEngine.DistanceGeodetic method. The result, a GeodeticDistanceResult, includes the azimuths between the two points.
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);}
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);
}
Hi Mohamad Fathin,
You could set them up something like this:
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">readonly</SPAN> LinearUnit _metersUnit <SPAN class="operator token">=</SPAN> LinearUnits<SPAN class="punctuation token">.</SPAN>Meters<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">readonly</SPAN> AngularUnit _degreesUnit <SPAN class="operator token">=</SPAN> AngularUnits<SPAN class="punctuation token">.</SPAN>Degrees<SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
or just call DistanceGeodetic like this:
GeodeticDistanceResult distance <SPAN class="operator token">=</SPAN> GeometryEngine<SPAN class="punctuation token">.</SPAN><SPAN class="token function">DistanceGeodetic</SPAN><SPAN class="punctuation token">(</SPAN>mapPoint1<SPAN class="punctuation token">,</SPAN> mapPoint2<SPAN class="punctuation token">,</SPAN> LinearUnits<SPAN class="punctuation token">.</SPAN>Meters<SPAN class="punctuation token">,</SPAN> AngularUnits<SPAN class="punctuation token">.</SPAN>Degrees<SPAN class="punctuation token">,</SPAN> GeodeticCurveType<SPAN class="punctuation token">.</SPAN>Geodesic<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
See LinearUnits and AngularUnits.
Hope that helps!
Nick.
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 32Inner Exception 1:DllNotFoundException: Unable to load DLL 'RuntimeCoreNet.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
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());
private readonly LinearUnit _metersUnit = LinearUnits.Meters; private readonly AngularUnit _degreesUnit = AngularUnits.Degrees;
// 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();
textBox.Text = string.Format("Distance:{0} | Azimuth:{1}", _metersUnit.UnitType.ToString(), _degreesUnit.UnitType.ToString());
I tried the code locally and found the following worked for the basic use case of finding the azimuth values:
MapPoint mapPoint1 <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">MapPoint</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">2.72</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">56.065</SPAN><SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> MapPoint mapPoint2 <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">MapPoint</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">2.69</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">56.065</SPAN><SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>Wgs84<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> GeodeticDistanceResult distance <SPAN class="operator token">=</SPAN> GeometryEngine<SPAN class="punctuation token">.</SPAN><SPAN class="token function">DistanceGeodetic</SPAN><SPAN class="punctuation token">(</SPAN>mapPoint1<SPAN class="punctuation token">,</SPAN> mapPoint2<SPAN class="punctuation token">,</SPAN> LinearUnits<SPAN class="punctuation token">.</SPAN>Meters<SPAN class="punctuation token">,</SPAN> AngularUnits<SPAN class="punctuation token">.</SPAN>Degrees<SPAN class="punctuation token">,</SPAN> GeodeticCurveType<SPAN class="punctuation token">.</SPAN>Geodesic<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>$<SPAN class="string token">"Distance:{distance.Distance} | Azimuth1:{distance.Azimuth1} | Azimuth2:{distance.Azimuth2}"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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?
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 ?
If the value is < 0, add 360. -179 becomes 181. -10 becomes 350, etc.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.