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?
2 Answers 2
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
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
-
Thanks!! Anything for Javascript?Mo3z– Mo3z2012年10月25日 17:16:25 +00:00Commented 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/…2012年10月25日 18:54:50 +00:00Commented Oct 25, 2012 at 18:54
Explore related questions
See similar questions with these tags.