Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

Thanks!!

share|improve this question
add comment

2 Answers

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

share|improve this answer
    
Thanks!! Anything for Javascript? –  Moiz Oct 25 '12 at 17:16
    
You need to use ArcGIS Server Geo-processing and the Javascript API help.arcgis.com/EN/WEBAPI/JAVASCRIPT/ARCGIS/help/… –  Mapperz Oct 25 '12 at 18:54
add comment
up vote 1 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.