4

I am trying to compute angle between two lines (line segment) using ESRI (ArcGIS, JS) in conventional bearing (Eg: N29'E)

I am using Add Toolbar to draw a line segment where point A is a fixed point (already drawn) and when the user is hovering over the map looking for point B, it should display projected angle.

Has anybody tried anything like this before or any idea?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Oct 25, 2012 at 17:03

2 Answers 2

5

For anyone needing this:

function computeAngle(pointA, pointB){
 var dLon = (pointB.x - pointA.x) * Math.PI / 180;
 var lat1 = pointA.y * Math.PI / 180;
 var lat2 = pointB.y * Math.PI / 180;
 var y = Math.sin(dLon) * Math.cos(lat2);
 var x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
 var bearing = Math.atan2(y, x) * 180 / Math.PI;
 bearing = ((bearing + 360) % 360).toFixed(1); //Converting -ve to +ve (0-360)
 if(bearing >= 0 && bearing < 90){
 return 'N' + (bearing != 0 ? bearing + 'E' : '');
 }
 if(bearing >= 90 && bearing < 180){
 return (bearing != 90 ? 'S' + (180 - bearing).toFixed(1) : '') + 'E';
 }
 if(bearing >= 180 && bearing < 270){
 return 'S' + (bearing != 180 ? (bearing - 180).toFixed(1) + 'W' : '');
 }
 if(bearing >= 270){
 return (bearing != 270 ? 'N' + (360 - bearing).toFixed(1) : '') + 'W';
 }
 return 'N';
}

References:

http://www.movable-type.co.uk/scripts/latlong.html

http://www.mathsteacher.com.au/year7/ch08_angles/07_bear/bearing.htm

answered Oct 25, 2012 at 21:02
4

Bearing Distance To Line (Data Management)

Creates a new feature class containing geodetic line features constructed based on the values in an x-coordinate field, y-coordinate field, bearing field, and distance field of a table.

enter image description here

bearing_units (Optional)

The units of the values in the Bearing Field.

DEGREES —Values in decimal degrees; this is the default.
MILS —Values in mils.
RADS —Values in radians.
GRADS —Values in gradians.

source: http://resources.arcgis.com/en/help/main/10.1/index.html#//0017000000ts000000

answered Oct 25, 2012 at 17:14
2
  • Thanks!! Anything for Javascript? Commented Oct 25, 2012 at 17:16
  • You need to use ArcGIS Server Geo-processing and the Javascript API help.arcgis.com/EN/WEBAPI/JAVASCRIPT/ARCGIS/help/… Commented Oct 25, 2012 at 18:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.